diff --git a/cmake/OS_Detection.cmake b/cmake/OS_Detection.cmake
index f4253d7094d05e40c5d525d4b9f5aaffad62d6b7..285ef67930e9403e85e2d019851436725f2f204d 100644
--- a/cmake/OS_Detection.cmake
+++ b/cmake/OS_Detection.cmake
@@ -48,11 +48,11 @@ if(UNIX)
     add_definitions ("-DDAP_OS_LINUX -DDAP_OS_UNIX")
     # add_definitions ("-DDAP_LOG_MT")
     if(DAP_DEBUG)
-      set(_CCOPT "-DDAP_DEBUG -Wall -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols")
+      set(_CCOPT "-DDAP_DEBUG -Wall -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols")
       set(_LOPT "-pg")
       SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
     else()
-	set(_CCOPT "-Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fPIC -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all -std=gnu11")
+        set(_CCOPT "-Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fPIC -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all -std=gnu11")
     endif()
 
     if (ANDROID)
@@ -93,10 +93,10 @@ if(WIN32)
     add_definitions ("-DDAP_OS_WINDOWS")
 
      if(DAP_DEBUG)
-      set(_CCOPT "-mconsole -static -Wall -std=gnu11 -Wextra -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -g3 -ggdb -fno-eliminate-unused-debug-symbols -pg")
+      set(_CCOPT "-mconsole -static -Wall -std=gnu11 -Wextra -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -g3 -ggdb -fno-eliminate-unused-debug-symbols -pg")
       set(_LOPT "-mconsole -static -pg")
     else()
-      set(_CCOPT "-static -std=gnu11 -Wall -Wextra -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
+      set(_CCOPT "-static -std=gnu11 -Wall -Wextra -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
     endif()
 
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT} ")
diff --git a/dap-sdk/core/include/dap_common.h b/dap-sdk/core/include/dap_common.h
index 6da42d7977cbadce1a8a8c143303632423e01644..4d48891061d004bdb4f3195df3c44e56efdcc0fd 100755
--- a/dap-sdk/core/include/dap_common.h
+++ b/dap-sdk/core/include/dap_common.h
@@ -252,7 +252,6 @@ extern "C" {
 #define MAX_PATH 120
 #endif
 
-#ifndef _WIN32
 #ifndef MAX
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 #endif
@@ -260,7 +259,6 @@ extern "C" {
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #endif
 
-#endif
 
 extern uint16_t htoa_lut256[ 256 ];
 
diff --git a/dap-sdk/crypto/src/dap_enc_GOST.c b/dap-sdk/crypto/src/dap_enc_GOST.c
index a3bb436dbcefc6846253b069e920d59361e206a7..22c7fb98b2925802db533cfa7615179ce3fa96c8 100644
--- a/dap-sdk/crypto/src/dap_enc_GOST.c
+++ b/dap-sdk/crypto/src/dap_enc_GOST.c
@@ -11,8 +11,6 @@
 
 #define LOG_TAG "dap_enc_gost"
 
-#define DAP_DEL_Z DAP_DELETE
-
 void dap_enc_gost_key_generate(struct dap_enc_key * a_key, const void *kex_buf,
         size_t kex_size, const void * seed, size_t seed_size, size_t key_size)
 {
diff --git a/dap-sdk/crypto/src/dap_enc_salsa2012.c b/dap-sdk/crypto/src/dap_enc_salsa2012.c
index 68c4b577f96372a5d1d65f90f84930bf02555f76..767f9fb9e02447ba1517e19f11eb53909690085d 100644
--- a/dap-sdk/crypto/src/dap_enc_salsa2012.c
+++ b/dap-sdk/crypto/src/dap_enc_salsa2012.c
@@ -13,8 +13,6 @@
 #define SALSA20_KEY_SIZE 32
 #define SALSA20_NONCE_SIZE 8
 
-#define DAP_DEL_Z DAP_DELETE
-
 void dap_enc_salsa2012_key_generate(struct dap_enc_key * a_key, const void *kex_buf,
         size_t kex_size, const void * seed, size_t seed_size, size_t key_size)
 {
diff --git a/dap-sdk/crypto/src/rand/dap_rand.c b/dap-sdk/crypto/src/rand/dap_rand.c
index 145f1466e998af2caf3472fb1a6ccc3119e7f920..c804f53899cc1d25e1b0962ea9176ab1db5f93c2 100755
--- a/dap-sdk/crypto/src/rand/dap_rand.c
+++ b/dap-sdk/crypto/src/rand/dap_rand.c
@@ -45,6 +45,7 @@ int randombase64(void*random_array, unsigned int size)
             ((uint8_t*)random_array)[size - odd_signs + i] = tmpv[i];
         }
     }
+    return (int) size;
 }
 
 
diff --git a/dap-sdk/crypto/src/sig_picnic/picnic_impl.c b/dap-sdk/crypto/src/sig_picnic/picnic_impl.c
index 2ff96df6388bfb44bd2b91000e3a59a2afca6c7e..2736ff31e7cc049e40f976dec7367036dc04aed1 100755
--- a/dap-sdk/crypto/src/sig_picnic/picnic_impl.c
+++ b/dap-sdk/crypto/src/sig_picnic/picnic_impl.c
@@ -33,7 +33,7 @@
 #include "hash.h"
 #include "picnic_types.h"
 
-#define MAX(a, b) ((a) > (b)) ? (a) : (b)
+//#define MAX(a, b) ((a) > (b)) ? (a) : (b)
 
 #define VIEW_OUTPUTS(i, j) viewOutputs[(i) * 3 + (j)]
 
diff --git a/dap-sdk/net/stream/ch/dap_stream_ch.c b/dap-sdk/net/stream/ch/dap_stream_ch.c
index 4cd6c5f0428edf58e0fe206e23fdd86cd803d743..6402394bf3fb0db0276b505c77212692d9cac02b 100644
--- a/dap-sdk/net/stream/ch/dap_stream_ch.c
+++ b/dap-sdk/net/stream/ch/dap_stream_ch.c
@@ -75,19 +75,23 @@ void dap_stream_ch_deinit()
  * @param direction Direction of channel (input to the server, output to the client)
  * @return
  */
-dap_stream_ch_t* dap_stream_ch_new(dap_stream_t* stream,uint8_t id)
+dap_stream_ch_t* dap_stream_ch_new(dap_stream_t* a_stream, uint8_t id)
 {
     stream_ch_proc_t * proc=stream_ch_proc_find(id);
     if(proc){
-        dap_stream_ch_t * ret= DAP_NEW_Z(dap_stream_ch_t);
-        ret->stream=stream;
-        ret->proc=proc;
+        dap_stream_ch_t* ret = DAP_NEW_Z(dap_stream_ch_t);
+        ret->stream = a_stream;
+        ret->proc = proc;
         ret->ready_to_read=true;
-        ret->stream->channel[ret->stream->channel_count]=ret;
-        ret->stream->channel_count++;
         pthread_mutex_init(&(ret->mutex),NULL);
         if(ret->proc->new_callback)
             ret->proc->new_callback(ret,NULL);
+
+        pthread_rwlock_wrlock(&a_stream->rwlock);
+        a_stream->channel[ret->stream->channel_count] = ret;
+        a_stream->channel_count++;
+        pthread_rwlock_unlock(&a_stream->rwlock);
+
         return ret;
     }else{
         log_it(L_WARNING, "Unknown stream processor with id %uc",id);
diff --git a/dap-sdk/net/stream/ch/dap_stream_ch_pkt.c b/dap-sdk/net/stream/ch/dap_stream_ch_pkt.c
index 5e2329841f9fedb49ee0f7bc9b20630bc51f5944..cb575948c43b1c9604965ca8ec56f881f7cc5bbc 100644
--- a/dap-sdk/net/stream/ch/dap_stream_ch_pkt.c
+++ b/dap-sdk/net/stream/ch/dap_stream_ch_pkt.c
@@ -90,8 +90,11 @@ size_t dap_stream_ch_pkt_write(struct dap_stream_ch * a_ch,  uint8_t a_type, con
     l_hdr.size=(uint32_t) a_data_size;
     l_hdr.type=a_type;
     l_hdr.enc_type = a_ch->proc->enc_type;
+
+    pthread_rwlock_wrlock(&a_ch->stream->rwlock);
     l_hdr.seq_id=a_ch->stream->seq_id;
     a_ch->stream->seq_id++;
+    pthread_rwlock_unlock(&a_ch->stream->rwlock);
 
     if ( dap_stream_get_dump_packet_headers() ){
         log_it(L_INFO,"Outgoing channel packet: id='%c' size=%u type=0x%02Xu seq_id=0x%016X enc_type=0x%02hhX",
diff --git a/dap-sdk/net/stream/stream/dap_stream.c b/dap-sdk/net/stream/stream/dap_stream.c
index cda062260efe7e20e6537726ed188ef58ea3df92..d6769440874667f6a4182fd522cdc95a66426d41 100644
--- a/dap-sdk/net/stream/stream/dap_stream.c
+++ b/dap-sdk/net/stream/stream/dap_stream.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <unistd.h>
 
 #ifdef _WIN32
 #include <winsock2.h>
@@ -81,7 +82,7 @@ static pthread_mutex_t s_mutex_keepalive_list;
 static void start_keepalive( dap_stream_t *sid );
 static void keepalive_cb( void );
 
-static bool bKeepaliveLoopQuitSignal = false;
+static bool s_keep_alive_loop_quit_signal = false;
 static bool s_dump_packet_headers = false;
 
 bool dap_stream_get_dump_packet_headers(){ return  s_dump_packet_headers; }
@@ -91,6 +92,7 @@ static struct timespec keepalive_loop_sleep = { 0, STREAM_KEEPALIVE_TIMEOUT * 10
 // Start keepalive stream
 static void *stream_loop( void *arg )
 {
+    UNUSED(arg);
 //    keepalive_loop = ev_loop_new(0);
 //    ev_loop(keepalive_loop, 0);
   do {
@@ -104,7 +106,7 @@ static void *stream_loop( void *arg )
 
     keepalive_cb( );
 
-  } while ( !bKeepaliveLoopQuitSignal );
+  } while ( !s_keep_alive_loop_quit_signal );
 
   return NULL;
 }
@@ -115,21 +117,20 @@ static void *stream_loop( void *arg )
  */
 int dap_stream_init( bool a_dump_packet_headers)
 {
-  if( dap_stream_ch_init() != 0 ){
-
-    log_it(L_CRITICAL, "Can't init channel types submodule");
-    return -1;
-  }
-  s_dump_packet_headers = a_dump_packet_headers;
+    if( dap_stream_ch_init() != 0 ){
+        log_it(L_CRITICAL, "Can't init channel types submodule");
+        return -1;
+    }
+    s_dump_packet_headers = a_dump_packet_headers;
 
-  bKeepaliveLoopQuitSignal = false;
+    s_keep_alive_loop_quit_signal = false;
 
-  pthread_mutex_init( &s_mutex_keepalive_list, NULL );
-  //pthread_create( &keepalive_thread, NULL, stream_loop, NULL );
+    pthread_mutex_init( &s_mutex_keepalive_list, NULL );
+    //pthread_create( &keepalive_thread, NULL, stream_loop, NULL );
 
-  log_it(L_NOTICE,"Init streaming module");
+    log_it(L_NOTICE,"Init streaming module");
 
-  return 0;
+    return 0;
 }
 
 /**
@@ -137,12 +138,12 @@ int dap_stream_init( bool a_dump_packet_headers)
  */
 void dap_stream_deinit()
 {
-  bKeepaliveLoopQuitSignal = true;
-  pthread_join( keepalive_thread, NULL );
+    s_keep_alive_loop_quit_signal = true;
+    pthread_join( keepalive_thread, NULL );
 
-  pthread_mutex_destroy( &s_mutex_keepalive_list );
+    pthread_mutex_destroy( &s_mutex_keepalive_list );
 
-  dap_stream_ch_deinit( );
+    dap_stream_ch_deinit( );
 }
 
 /**
@@ -201,7 +202,7 @@ void stream_headers_read(dap_http_client_t * cl_ht, void * arg)
    // int raw_size;
     unsigned int id=0;
 
-    log_it(L_DEBUG,"Prepare data stream");
+//    log_it(L_DEBUG,"Prepare data stream");
     if(cl_ht->in_query_string[0]){
         log_it(L_INFO,"Query string [%s]",cl_ht->in_query_string);
 //        if(sscanf(cl_ht->in_query_string,"fj913htmdgaq-d9hf=%u",&id)==1){
@@ -324,6 +325,7 @@ dap_stream_t * stream_new(dap_http_client_t * a_sh)
 {
     dap_stream_t * ret=(dap_stream_t*) calloc(1,sizeof(dap_stream_t));
 
+    pthread_rwlock_init( &ret->rwlock, NULL);
     ret->conn = a_sh->client;
     ret->conn_http=a_sh;
     ret->buf_defrag_size = 0;
@@ -343,8 +345,10 @@ void dap_stream_delete( dap_stream_t *a_stream )
         log_it(L_ERROR,"stream delete NULL instance");
         return;
     }
+    pthread_rwlock_destroy(&a_stream->rwlock);
     stream_dap_delete(a_stream->conn, NULL);
-    free(a_stream);
+
+    DAP_DELETE(a_stream);
 }
 
 /**
@@ -355,7 +359,7 @@ void dap_stream_delete( dap_stream_t *a_stream )
 dap_stream_t* dap_stream_new_es(dap_events_socket_t * a_es)
 {
     dap_stream_t * ret= DAP_NEW_Z(dap_stream_t);
-
+    pthread_rwlock_init( &ret->rwlock, NULL);
     ret->events_socket = a_es;
     ret->buf_defrag_size=0;
     ret->is_client_to_uplink = true;
@@ -682,26 +686,29 @@ void stream_dap_data_write(dap_client_remote_t* a_client , void * arg){
 void stream_dap_delete(dap_client_remote_t* sh, void * arg){
     if(!sh)
         return;
-    dap_stream_t * sid = DAP_STREAM(sh);
-    if(sid == NULL)
+    dap_stream_t * l_stream = DAP_STREAM(sh);
+    if(l_stream == NULL)
         return;
     (void) arg;
 
     pthread_mutex_lock(&s_mutex_keepalive_list);
     if(s_stream_keepalive_list){
-        DL_DELETE(s_stream_keepalive_list, sid);
+        DL_DELETE(s_stream_keepalive_list, l_stream);
     }
     pthread_mutex_unlock(&s_mutex_keepalive_list);
 
+    pthread_rwlock_wrlock(&l_stream->rwlock);
     size_t i;
-    for(i=0;i<sid->channel_count; i++)
-        dap_stream_ch_delete(sid->channel[i]);
-    sid->channel_count = 0;
-    if(sid->session)
-        dap_stream_session_close(sid->session->id);
-    sid->session = NULL;
+    for(i=0;i<l_stream->channel_count; i++)
+        dap_stream_ch_delete(l_stream->channel[i]);
+    l_stream->channel_count = 0;
+
+    if(l_stream->session)
+        dap_stream_session_close(l_stream->session->id);
+    l_stream->session = NULL;
+    pthread_rwlock_unlock(&l_stream->rwlock);
     //free(sid);
-    log_it(L_NOTICE,"[core] Stream connection is finished");
+    log_it(L_NOTICE,"Stream connection is over");
 }
 
 /**
@@ -715,26 +722,29 @@ void stream_dap_new(dap_client_remote_t* sh, void * arg){
 }
 
 
-static bool _detect_loose_packet(dap_stream_t * sid)
+static bool _detect_loose_packet(dap_stream_t * a_stream)
 {
-    dap_stream_ch_pkt_t * ch_pkt = (dap_stream_ch_pkt_t *) sid->buf_pkt_in;
+    dap_stream_ch_pkt_t * ch_pkt = (dap_stream_ch_pkt_t *) a_stream->pkt_cache;
+
+    pthread_rwlock_wrlock (&a_stream->rwlock);
 
-    int count_loosed_packets = ch_pkt->hdr.seq_id - (sid->client_last_seq_id_packet + 1);
+    int count_loosed_packets = ch_pkt->hdr.seq_id - (a_stream->client_last_seq_id_packet + 1);
     if(count_loosed_packets > 0)
     {
         log_it(L_WARNING, "Detected loosed %d packets. "
                           "Last read seq_id packet: %d Current: %d", count_loosed_packets,
-               sid->client_last_seq_id_packet, ch_pkt->hdr.seq_id);
+               a_stream->client_last_seq_id_packet, ch_pkt->hdr.seq_id);
     } else if(count_loosed_packets < 0) {
-        if(sid->client_last_seq_id_packet != 0 && ch_pkt->hdr.seq_id != 0) {
+        if(a_stream->client_last_seq_id_packet != 0 && ch_pkt->hdr.seq_id != 0) {
         log_it(L_WARNING, "Something wrong. count_loosed packets %d can't less than zero. "
                           "Last read seq_id packet: %d Current: %d", count_loosed_packets,
-               sid->client_last_seq_id_packet, ch_pkt->hdr.seq_id);
+               a_stream->client_last_seq_id_packet, ch_pkt->hdr.seq_id);
         } // else client don't support seqid functionality
     }
 //    log_it(L_DEBUG, "Packet seq id: %d", ch_pkt->hdr.seq_id);
 //    log_it(L_DEBUG, "Last seq id: %d", sid->last_seq_id_packet);
-    sid->client_last_seq_id_packet = ch_pkt->hdr.seq_id;
+    a_stream->client_last_seq_id_packet = ch_pkt->hdr.seq_id;
+    pthread_rwlock_unlock (&a_stream->rwlock);
 
     return false;
 }
@@ -746,24 +756,36 @@ static bool _detect_loose_packet(dap_stream_t * sid)
  */
 void stream_proc_pkt_in(dap_stream_t * a_stream)
 {
-    if(a_stream->pkt_buf_in->hdr.type == STREAM_PKT_TYPE_DATA_PACKET)
+    pthread_rwlock_wrlock( &a_stream->rwlock );
+    dap_stream_pkt_t * l_pkt = a_stream->pkt_buf_in;
+    size_t l_pkt_size = a_stream->pkt_buf_in_data_size;
+    a_stream->pkt_buf_in=NULL;
+    a_stream->pkt_buf_in_data_size=0;
+    a_stream->keepalive_passed = 0;
+    pthread_rwlock_unlock (&a_stream->rwlock);
+
+    if(l_pkt->hdr.type == STREAM_PKT_TYPE_DATA_PACKET)
     {
-        dap_stream_ch_pkt_t * l_ch_pkt = (dap_stream_ch_pkt_t *) a_stream->buf_pkt_in;
+        dap_stream_ch_pkt_t * l_ch_pkt = (dap_stream_ch_pkt_t *) a_stream->pkt_cache;
 
-        if(dap_stream_pkt_read(a_stream,a_stream->pkt_buf_in, l_ch_pkt, STREAM_BUF_SIZE_MAX)==0){
-            log_it(L_WARNING, "Input: can't decode packet size=%d",a_stream->pkt_buf_in_data_size);
+        if(dap_stream_pkt_read(a_stream,l_pkt, l_ch_pkt, STREAM_BUF_SIZE_MAX)==0){
+            log_it(L_WARNING, "Input: can't decode packet size=%d",l_pkt_size);
         }
 
         _detect_loose_packet(a_stream);
 
+        // Find channel
         dap_stream_ch_t * ch = NULL;
-        size_t i;
-        for(i=0;i<a_stream->channel_count;i++)
+        pthread_rwlock_rdlock (&a_stream->rwlock);
+        for(size_t i=0;i<a_stream->channel_count;i++){
             if(a_stream->channel[i]->proc){
                 if(a_stream->channel[i]->proc->id == l_ch_pkt->hdr.id ){
                     ch=a_stream->channel[i];
                 }
             }
+        }
+        pthread_rwlock_unlock (&a_stream->rwlock);
+
         if(ch){
             ch->stat.bytes_read+=l_ch_pkt->hdr.size;
             if(ch->proc)
@@ -780,24 +802,20 @@ void stream_proc_pkt_in(dap_stream_t * a_stream)
         } else{
             log_it(L_WARNING, "Input: unprocessed channel packet id '%c'",(char) l_ch_pkt->hdr.id );
         }
-    } else if(a_stream->pkt_buf_in->hdr.type == STREAM_PKT_TYPE_SERVICE_PACKET) {
-        stream_srv_pkt_t * srv_pkt = (stream_srv_pkt_t *)malloc(sizeof(stream_srv_pkt_t));
-        memcpy(srv_pkt,a_stream->pkt_buf_in->data,sizeof(stream_srv_pkt_t));
+    } else if(l_pkt->hdr.type == STREAM_PKT_TYPE_SERVICE_PACKET) {
+        stream_srv_pkt_t * srv_pkt = DAP_NEW(stream_srv_pkt_t);
+        memcpy(srv_pkt, l_pkt->data,sizeof(stream_srv_pkt_t));
         uint32_t session_id = srv_pkt->session_id;
         check_session(session_id,a_stream->conn);
-        free(srv_pkt);
+        DAP_DELETE(srv_pkt);
     } else {
         log_it(L_WARNING, "Unknown header type");
     }
 
-    a_stream->keepalive_passed = 0;
 
 //    ev_timer_again (keepalive_loop, &a_stream->keepalive_watcher);
     start_keepalive( a_stream );
-
-    free(a_stream->pkt_buf_in);
-    a_stream->pkt_buf_in=NULL;
-    a_stream->pkt_buf_in_data_size=0;
+    DAP_DELETE(l_pkt);
 }
 
 /**
diff --git a/dap-sdk/net/stream/stream/include/dap_stream.h b/dap-sdk/net/stream/stream/include/dap_stream.h
index aa929ecb28d209784066b0aa2975cf18084953df..2e3aa9c2853cebbf29d7573f369ed3530b0d9d31 100644
--- a/dap-sdk/net/stream/stream/include/dap_stream.h
+++ b/dap-sdk/net/stream/stream/include/dap_stream.h
@@ -25,7 +25,7 @@
 #include <stddef.h>
 #include <pthread.h>
 #include <stdbool.h>
-
+#include <pthread.h>
 #include "dap_stream_session.h"
 #include "dap_stream_ch.h"
 
@@ -51,8 +51,8 @@ typedef struct dap_events_socket dap_events_socket_t;
 typedef void (*dap_stream_callback)( dap_stream_t *,void*);
 
 typedef struct dap_stream {
-
     int id;
+    pthread_rwlock_t rwlock;
     dap_stream_session_t * session;
     struct dap_client_remote * conn; // Connection
 
@@ -78,7 +78,7 @@ typedef struct dap_stream {
     uint64_t buf_defrag_size;
 
     uint8_t buf[STREAM_BUF_SIZE_MAX];
-    uint8_t buf_pkt_in[STREAM_BUF_SIZE_MAX];
+    uint8_t pkt_cache[STREAM_BUF_SIZE_MAX];
 
     dap_stream_ch_t *channel[255]; // TODO reduce channels to 16 to economy memory
     size_t channel_count;
diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c
index 8a7357967f7e2ebef800c60e37327ba51a75b179..b8384cf4b4fb40010581ae45b2b32d42cb3f52f0 100644
--- a/modules/net/dap_chain_net.c
+++ b/modules/net/dap_chain_net.c
@@ -80,7 +80,7 @@
 #include <sys/types.h>
 #include <dirent.h>
 
-#define _XOPEN_SOURCE       /* See feature_test_macros(7) */
+//#define _XOPEN_SOURCE       /* See feature_test_macros(7) */
 #define __USE_XOPEN
 #define _GNU_SOURCE
 #include <time.h>
diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c
index 1f15bd943d939d884a44935711ef1ac8ff4c48b0..4504d1c791ea9b64f0b583307a4917eb027f6c44 100644
--- a/modules/net/dap_chain_node_cli_cmd.c
+++ b/modules/net/dap_chain_node_cli_cmd.c
@@ -73,6 +73,7 @@
 #include "dap_chain_node_cli_cmd_tx.h"
 #include "dap_chain_node_ping.h"
 #include "dap_chain_net_srv.h"
+#include "dap_chain_net_vpn_client.h"
 #include "dap_chain_cell.h"
 
 #include "dap_chain_common.h"