Skip to content
Snippets Groups Projects
Commit b244a430 authored by Alexandr Mruchok's avatar Alexandr Mruchok
Browse files

Merge branch 'master' of...

Merge branch 'master' of https://gitlab.demlabs.net/cellframe/libdap-stream-ch-chain-net-srv into feature-2648

# Conflicts:
#	CMakeLists.txt
#	dap_stream_ch_chain_net_srv.c
#	dap_stream_ch_chain_net_srv.h
#	dap_stream_ch_chain_net_srv_pkt.c
#	dap_stream_ch_chain_net_srv_pkt.h
parents 413aa25d e136afe7
No related branches found
No related tags found
1 merge request!2Feature 2648
.gitignore 100644 → 100755
File mode changed from 100644 to 100755
CMakeLists.txt 100644 → 100755
cmake_minimum_required(VERSION 3.0)
project (dap_stream_ch_chain_net_srv)
set(DAP_STREAM_CH_CHAIN_NET_SRV_SRCS dap_stream_ch_chain_net_srv.c dap_stream_ch_chain_net_srv_pkt.c)
set(DAP_STREAM_CH_CHAIN_NET_SRV_SRCS dap_stream_ch_chain_net_srv.c dap_stream_ch_chain_net_srv_session.c dap_stream_ch_chain_net_srv_pkt.c)
if(WIN32)
include_directories(../libdap/src/win32/)
include_directories(../3rdparty/wepoll/include/)
include_directories(../3rdparty/uthash/src/)
include_directories(../3rdparty/libjson-c/)
include_directories(../3rdparty/libmagic/src/)
include_directories(../3rdparty/curl/include/)
include_directories(../3rdparty/libsqlite3/)
endif()
......
/*
* 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/>.
* Authors:
* Dmitriy Gerasimov <naeper@demlabs.net>
* Cellframe https://cellframe.net
* DeM Labs Inc. https://demlabs.net
* Copyright (c) 2017-2019
* All rights reserved.
This file is part of CellFrame SDK the open source project
CellFrame SDK 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.
CellFrame SDK 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 CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#ifdef WIN32
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#include <winsock2.h>
#include <windows.h>
#include <mswsock.h>
#include <ws2tcpip.h>
#include <io.h>
//#include "wrappers.h"
#include <wepoll.h>
#include <pthread.h>
#endif
#include "dap_common.h"
#include "dap_stream.h"
#include "dap_stream_ch.h"
#include "dap_stream_ch_pkt.h"
#include "dap_stream_ch_chain_net_srv.h"
#include "dap_stream_ch_chain_net_srv_pkt.h"
#include "dap_stream_ch_chain_net_srv_session.h"
#include "dap_stream_ch_proc.h"
#define LOG_TAG "dap_stream_ch_chain_net_srv"
......@@ -65,10 +47,10 @@ static void s_stream_ch_packet_out(dap_stream_ch_t* ch , void* arg);
* @brief dap_stream_ch_chain_net_init
* @return
*/
int dap_stream_ch_chain_net_srv_init()
int dap_stream_ch_chain_net_srv_init(void)
{
log_it(L_NOTICE,"Chain network services channel initialized");
dap_stream_ch_proc_add('S',s_stream_ch_new,s_stream_ch_delete,s_stream_ch_packet_in,s_stream_ch_packet_out);
dap_stream_ch_proc_add('R',s_stream_ch_new,s_stream_ch_delete,s_stream_ch_packet_in,s_stream_ch_packet_out);
return 0;
}
......@@ -76,7 +58,7 @@ int dap_stream_ch_chain_net_srv_init()
/**
* @brief dap_stream_ch_chain_deinit
*/
void dap_stream_ch_chain_net_srv_deinit()
void dap_stream_ch_chain_net_srv_deinit(void)
{
}
......@@ -91,6 +73,12 @@ void s_stream_ch_new(dap_stream_ch_t* a_ch , void* arg)
a_ch->internal=DAP_NEW_Z(dap_stream_ch_chain_net_srv_t);
dap_stream_ch_chain_net_srv_t * l_ch_chain_net_srv = DAP_STREAM_CH_CHAIN_NET_SRV(a_ch);
pthread_mutex_init( &l_ch_chain_net_srv->mutex,NULL);
if (a_ch->stream->session->_inheritor == NULL && a_ch->stream->session != NULL)
dap_stream_ch_chain_net_srv_session_create( a_ch->stream->session );
else if ( a_ch->stream->session == NULL)
log_it( L_ERROR, "No session at all!");
else
log_it(L_ERROR, "Session inheritor is already present!");
}
......@@ -99,7 +87,7 @@ void s_stream_ch_new(dap_stream_ch_t* a_ch , void* arg)
* @param ch
* @param arg
*/
void s_stream_ch_delete(dap_stream_ch_t* ch , void* arg)
void s_stream_ch_delete(dap_stream_ch_t* a_ch , void* a_arg)
{
}
......@@ -109,17 +97,38 @@ void s_stream_ch_delete(dap_stream_ch_t* ch , void* arg)
* @param ch
* @param arg
*/
void s_stream_ch_packet_in(dap_stream_ch_t* ch , void* arg)
void s_stream_ch_packet_in(dap_stream_ch_t* a_ch , void* a_arg)
{
dap_stream_ch_chain_net_srv_t * l_ch_chain_net = DAP_STREAM_CH_CHAIN_NET_SRV(a_ch);
dap_stream_ch_pkt_t *l_ch_pkt = (dap_stream_ch_pkt_t *) a_arg; // chain packet
if(l_ch_pkt) {
switch (l_ch_pkt->hdr.type) {
case DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_REQUEST:{
} break;
case DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_SIGN_REQUEST:{
} break;
case DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_SIGN_RESPONSE:{
} break;
case DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RECEIPE:{
} break;
case DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_SUCCESS:{
} break;
case DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_ERROR:{
} break;
default: log_it( L_WARNING, "Unknown packet type 0x%02X", l_ch_pkt->hdr.type);
}
}
}
/**
* @brief s_stream_ch_packet_out
* @param ch
* @param arg
* @param a_ch
* @param a_arg
*/
void s_stream_ch_packet_out(dap_stream_ch_t* ch , void* arg)
void s_stream_ch_packet_out(dap_stream_ch_t* a_ch , void* a_arg)
{
(void) a_arg;
log_it(L_WARNING,"We don't need anything special to write but for some reasons write flag was on and now we're in output callback. Why?");
dap_stream_ch_set_ready_to_write(a_ch, false);
}
......@@ -2,8 +2,9 @@
* Authors:
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* DeM Labs Inc. https://demlabs.net
* Kelvin Project https://github.com/kelvinblockchain
* Copyright (c) 2017-2018
* CellFrame https://cellframe.net
* Sources https://gitlab.demlabs.net/cellframe
* Copyright (c) 2017-2019
* All rights reserved.
This file is part of DAP (Deus Applications Prototypes) the open source project
......@@ -20,9 +21,9 @@
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
int dap_stream_ch_chain_net_srv_init();
void dap_stream_ch_chain_net_srv_deinit();
int dap_stream_ch_chain_net_srv_init(void);
void dap_stream_ch_chain_net_srv_deinit(void);
/*
* 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/>.
**/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#ifdef WIN32
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0600
#include <winsock2.h>
#include <windows.h>
#include <mswsock.h>
#include <ws2tcpip.h>
#include <io.h>
//#include "wrappers.h"
#include <wepoll.h>
#include <pthread.h>
#endif
#include "dap_chain_net_srv_common.h"
typedef struct dap_stream_ch_chain_net_srv_pkt_hdr{
dap_chain_net_srv_uid_t srv_uid;
uint32_t type; // Chain data type
union{
struct{
}type_block;
struct{
}type_datum;
struct{
}type_global_db;
};
} __attribute__((packed)) dap_stream_ch_chain_net_srv_pkt_hdr_t;
typedef struct dap_stream_ch_chain_net_srv_pkt{
dap_stream_ch_chain_net_srv_pkt_hdr_t hdr;
uint8_t data[];
} __attribute__((packed)) dap_stream_ch_chain_net_srv_pkt_t;
* Authors:
* Dmitriy Gerasimov <naeper@demlabs.net>
* Cellframe https://cellframe.net
* DeM Labs Inc. https://demlabs.net
* Copyright (c) 2017-2019
* All rights reserved.
This file is part of CellFrame SDK the open source project
CellFrame SDK 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.
CellFrame SDK 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 CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dap_stream_ch_chain_net_srv_pkt.h"
#define LOG_TAG "dap_stream_ch_chain_net_srv_pkt"
/*
* Authors:
* Dmitriy Gerasimov <naeper@demlabs.net>
* Cellframe https://cellframe.net
* DeM Labs Inc. https://demlabs.net
* Copyright (c) 2017-2019
* All rights reserved.
This file is part of CellFrame SDK the open source project
CellFrame SDK 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.
CellFrame SDK 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 CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include "dap_chain_net_srv_common.h"
// Ch pkt types
#define DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_REQUEST 0x01
#define DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_SIGN_REQUEST 0x10
#define DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_SIGN_RESPONSE 0x11
#define DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RECEIPE 0x20
#define DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_SUCCESS 0xf0
#define DAP_STREAM_CH_CHAIN_NET_SRV_PKT_TYPE_RESPONSE_ERROR 0xff
// TYPE_REQUEST
typedef struct dap_stream_ch_chain_net_srv_pkt_request_hdr{
dap_chain_net_id_t net_id;// Network id wheither to request
dap_chain_hash_fast_t tx_cond; // Conditioned transaction with paymemt for
dap_chain_net_srv_uid_t srv_uid;
dap_chain_net_srv_class_t srv_class;
} DAP_ALIGN_PACKED dap_stream_ch_chain_net_srv_pkt_request_hdr_t;
typedef struct dap_stream_ch_chain_net_srv_pkt_request{
dap_stream_ch_chain_net_srv_pkt_request_hdr_t hdr;
uint8_t data[];
} DAP_ALIGN_PACKED dap_stream_ch_chain_net_srv_pkt_request;
// TYPE_RESPONSE_ERROR
typedef struct dap_stream_ch_chain_net_srv_pkt_error{
uint32_t code; // error code
} DAP_ALIGN_PACKED dap_stream_ch_chain_net_srv_pkt_error_t;
/*
* Authors:
* Dmitriy Gerasimov <naeper@demlabs.net>
* Cellframe https://cellframe.net
* DeM Labs Inc. https://demlabs.net
* Copyright (c) 2017-2019
* All rights reserved.
This file is part of CellFrame SDK the open source project
CellFrame SDK 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.
CellFrame SDK 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 CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dap_common.h"
#include "rand/dap_rand.h"
#include "dap_stream_ch_chain_net_srv_session.h"
#define LOG_TAG "dap_stream_ch_chain_net_srv_session"
/**
* @brief dap_stream_ch_chain_net_srv_session_create
* @param a_session
* @return
*/
dap_stream_ch_chain_net_srv_session_t * dap_stream_ch_chain_net_srv_session_create( dap_stream_session_t * a_session)
{
if (!a_session){
log_it (L_ERROR, "Session is NULL!");
return NULL;
}
dap_stream_ch_chain_net_srv_session_t * l_session_srv= DAP_NEW_Z(dap_stream_ch_chain_net_srv_session_t);
a_session->_inheritor = l_session_srv;
return l_session_srv;
}
/**
* @brief dap_stream_ch_chain_net_srv_usage_add
* @param a_srv_session
* @param a_net
* @param a_srv
* @return
*/
dap_stream_ch_chain_net_srv_usage_t* dap_stream_ch_chain_net_srv_usage_add (dap_stream_ch_chain_net_srv_session_t * a_srv_session,
dap_chain_net_t * a_net, dap_chain_net_srv_t * a_srv)
{
dap_stream_ch_chain_net_srv_usage_t * l_ret = DAP_NEW_Z(dap_stream_ch_chain_net_srv_usage_t);
randombytes(&l_ret->id, sizeof(l_ret->id));
l_ret->net = a_net;
l_ret->service = a_srv;
HASH_ADD_INT( a_srv_session->usages, id,l_ret );
return l_ret;
}
/**
* @brief dap_stream_ch_chain_net_srv_usage_delete
* @param a_srv_session
* @param a_usage
* @return
*/
void dap_stream_ch_chain_net_srv_usage_delete (dap_stream_ch_chain_net_srv_session_t * a_srv_session,
dap_stream_ch_chain_net_srv_usage_t* a_usage)
{
if ( a_usage->receipt_active )
DAP_DELETE( a_usage->receipt_active );
HASH_DEL(a_srv_session->usages, a_usage);
DAP_DELETE( a_usage );
}
/**
* @brief dap_stream_ch_chain_net_srv_usage_find
* @param a_srv_session
* @param a_usage_id
* @return
*/
dap_stream_ch_chain_net_srv_usage_t* dap_stream_ch_chain_net_srv_usage_find (dap_stream_ch_chain_net_srv_session_t * a_srv_session,
uint32_t a_usage_id)
{
dap_stream_ch_chain_net_srv_usage_t * l_ret = NULL;
HASH_FIND_INT(a_srv_session->usages, &a_usage_id, l_ret);
return l_ret;
}
/*
* Authors:
* Dmitriy Gerasimov <naeper@demlabs.net>
* Cellframe https://cellframe.net
* DeM Labs Inc. https://demlabs.net
* Copyright (c) 2017-2019
* All rights reserved.
This file is part of CellFrame SDK the open source project
CellFrame SDK 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.
CellFrame SDK 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 CellFrame SDK based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "uthash.h"
#include "dap_stream_session.h"
#include "dap_hash.h"
#include "dap_chain.h"
#include "dap_sign.h"
#include "dap_chain_datum_tx.h"
#include "dap_chain_datum_tx_receipt.h"
#include "dap_chain_net_srv.h"
#include "dap_chain_net_srv_order.h"
typedef struct dap_stream_ch_chain_net_srv_usage{
uint32_t id; // Usage id
dap_chain_net_t * net; // Chain network where everything happens
dap_chain_net_srv_t * service; // Service that used
dap_chain_datum_tx_receipt_t* receipt_active;
UT_hash_handle hh; //
} dap_stream_ch_chain_net_srv_usage_t;
typedef struct dap_stream_ch_chain_net_srv_session {
dap_stream_session_t * parent;
dap_stream_ch_chain_net_srv_usage_t * usages;
dap_sign_t* user_sign; // User's signature for auth if reconnect
} dap_stream_ch_chain_net_srv_session_t;
dap_stream_ch_chain_net_srv_session_t * dap_stream_ch_chain_net_srv_session_create( dap_stream_session_t * a_session);
dap_stream_ch_chain_net_srv_usage_t* dap_stream_ch_chain_net_srv_usage_add (dap_stream_ch_chain_net_srv_session_t * a_srv_session,
dap_chain_net_t * a_net, dap_chain_net_srv_t * a_srv);
void dap_stream_ch_chain_net_srv_usage_delete (dap_stream_ch_chain_net_srv_session_t * a_srv_session,
dap_stream_ch_chain_net_srv_usage_t* a_usage);
dap_stream_ch_chain_net_srv_usage_t* dap_stream_ch_chain_net_srv_usage_find (dap_stream_ch_chain_net_srv_session_t * a_srv_session,
uint32_t a_usage_id);
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