Skip to content
Snippets Groups Projects
Commit 44e34e08 authored by dmitriy.gerasimov's avatar dmitriy.gerasimov
Browse files
parents 318665f1 1fbe7407
No related branches found
No related tags found
No related merge requests found
......@@ -11,10 +11,12 @@ set(DAP_CHAIN_NET_SRV_HEADERS
dap_chain_net_srv_common.h
)
add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_NET_SRV_SRCS} ${DAP_CHAIN_NET_SRV_HEADERS})
target_link_libraries(dap_chain_net_srv dap_core dap_crypto dap_chain dap_chain_crypto dap_chain_net )
target_link_libraries(dap_chain_net_srv dap_core dap_crypto dap_chain dap_chain_crypto dap_chain_net)
#target_link_libraries(dap_chain_net_srv dap_core dap_crypto dap_chain dap_chain_crypto dap_chain_net dap_server_http_db_auth)
target_include_directories(dap_chain_net_srv INTERFACE .)
set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE)
......
/*
* Authors:
* Dmitriy A. Gearasimov <kahovski@gmail.com>
* DeM Labs Inc. https://demlabs.net
* DeM Labs Open source community https://github.com/demlabsinc
* Copyright (c) 2017-2018
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include "utlist.h"
#include "dap_chain_net_srv.h"
#define LOG_TAG "chain_net_srv"
static size_t m_uid_count;
static dap_chain_net_srv_uid_t * m_uid;
/**
* @brief dap_chain_net_srv_init
* @return
*/
int dap_chain_net_srv_init(void)
{
m_uid = NULL;
m_uid_count = 0;
return 0;
}
/**
* @brief dap_chain_net_srv_deinit
*/
void dap_chain_net_srv_deinit(void)
{
}
/**
* @brief dap_chain_net_srv_add
* @param a_srv
*/
void dap_chain_net_srv_add(dap_chain_net_srv_t * a_srv)
{
}
/**
* @brief dap_chain_net_srv_get
* @param a_uid
* @return
*/
dap_chain_net_srv_t * dap_chain_net_srv_get( dap_chain_net_srv_uid_t a_uid)
{
}
/**
* @brief dap_chain_net_srv_count
* @return
*/
size_t dap_chain_net_srv_count()
{
}
/**
* @brief dap_chain_net_srv_list
* @return
*/
const dap_chain_net_srv_uid_t * dap_chain_net_srv_list()
{
}
/*
* Authors:
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain
* Copyright (c) 2017-2018
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "dap_chain_net_srv_common.h"
typedef struct dap_chain_net_srv
{
dap_chain_net_srv_uid_t uid; // Unique ID for service.
void * _internal;
void * _inhertor;
} dap_chain_net_srv_t;
int dap_chain_net_srv_init(void);
void dap_chain_net_srv_deinit(void);
void dap_chain_net_srv_add(dap_chain_net_srv_t * a_srv);
dap_chain_net_srv_t * dap_chain_net_srv_get( dap_chain_net_srv_uid_t a_uid);
size_t dap_chain_net_srv_count();
const dap_chain_net_srv_uid_t * dap_chain_net_srv_list();
#include <stdint.h>
#include "rand/dap_rand.h"
#include "dap_chain_net_srv_common.h"
#include "dap_chain_datum_tx_items.h"
#include "dap_chain_utxo.h"
/**
* Generate unique id for service
*/
bool dap_chain_net_srv_gen_uid(dap_chain_net_srv_uid_t *a_srv)
{
if(!a_srv)
return false;
randombytes(a_srv, sizeof(dap_chain_net_srv_uid_t));
return true;
}
/**
*
*/
uint64_t dap_chain_net_srv_client_auth(char *a_addr_base58, uint8_t *a_sign, size_t a_sign_size,
const dap_chain_net_srv_abstract_t **a_cond_out)
{
dap_chain_addr_t *l_addr = (a_addr_base58) ? dap_chain_str_to_addr(a_addr_base58) : NULL;
dap_chain_tx_out_cond_t *l_tx_out_cond = NULL;
// Search all value in transactions with l_addr in 'out_cond' item
uint64_t l_value = 0;//!!!dap_chain_node_datum_tx_cache_get_out_cond_value(l_addr, &l_tx_out_cond);
DAP_DELETE(l_addr);
// not found transaction with l_addr in 'out_cond' item
if(!l_value)
return 0;
size_t l_pkey_size = 0;
size_t l_cond_size = 0;
uint8_t *l_cond = dap_chain_datum_tx_out_cond_item_get_pkey(l_tx_out_cond, &l_cond_size);
uint8_t *l_pkey = dap_chain_datum_tx_out_cond_item_get_cond(l_tx_out_cond, &l_pkey_size);
// create l_chain_sign for check a_sign
dap_chain_sign_t *l_chain_sign = DAP_NEW_Z_SIZE(dap_chain_sign_t,
sizeof(dap_chain_sign_t) + a_sign_size + l_pkey_size);
l_chain_sign->header.type = l_addr->sig_type;
l_chain_sign->header.sign_size = l_pkey_size;
l_chain_sign->header.sign_pkey_size = l_pkey_size;
// write serialized public key to dap_chain_sign_t
memcpy(l_chain_sign->pkey_n_sign, l_pkey, l_pkey_size);
// write serialized signature to dap_chain_sign_t
memcpy(l_chain_sign->pkey_n_sign + l_pkey_size, a_sign, a_sign_size);
// check signature
if(dap_chain_sign_verify(l_chain_sign, a_sign, a_sign_size) != 1) {
// invalid signature
return 0;
}
if(l_cond_size != sizeof(dap_chain_net_srv_abstract_t)) {
return 0;
}
if(a_cond_out)
*a_cond_out = (const dap_chain_net_srv_abstract_t*) l_cond;
return l_value;
}
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "dap_common.h"
#include "dap_math_ops.h"
......@@ -13,3 +14,46 @@ typedef union{
dap_uint128_t raw_ui128[1];
#endif
} dap_chain_net_srv_uid_t;
//Classes of services
enum {
SERV_CLASS_ONCE = 1, // one-time service
SERV_CLASS_PERMANENT = 2
};
//Types of services
enum {
SERV_ID_VPN = 1,
};
typedef struct dap_chain_net_srv_abstract
{
uint64_t proposal_id; // id trade proposal. Must be unique to the node.
uint8_t class; //Class of service
uint8_t type_id; //Type of service
union {
struct {
int bandwith;
int abuse_resistant;
int limit_bytes;
} vpn;
/*struct {
int value;
} another_srv;*/
} proposal_params;
//size_t pub_key_data_size;
//void * pub_key_data;
uint64_t price; // service price, for SERV_CLASS_ONCE ONCE for the whole service, for SERV_CLASS_PERMANENT for one unit.
uint8_t price_units; // Unit of service (seconds, megabytes, etc.) Only for SERV_CLASS_PERMANENT
char decription[128];
} DAP_ALIGN_PACKED dap_chain_net_srv_abstract_t;
// generate new dap_chain_net_srv_uid_t
bool dap_chain_net_srv_gen_uid(dap_chain_net_srv_uid_t *a_srv);
uint64_t dap_chain_net_srv_client_auth(char *a_addr_base58, uint8_t *a_sign, size_t a_sign_size,
const dap_chain_net_srv_abstract_t **a_cond_out);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment