Skip to content
Snippets Groups Projects
Commit faaa76bb authored by dmitriy.gerasimov's avatar dmitriy.gerasimov
Browse files

Merge branch 'support-4382-4' into 'testing'

Revert "[*] fixed /'Too big size/' error in packet write"

See merge request cellframe/cellframe-sdk!180
parents 07068437 9a730ff1
No related branches found
No related tags found
1 merge request!12hotfix-7350
......@@ -164,18 +164,16 @@ size_t dap_stream_ch_pkt_write_unsafe(dap_stream_ch_t * a_ch, uint8_t a_type, c
(char) l_hdr.id, l_hdr.size, l_hdr.type, l_hdr.seq_id , l_hdr.enc_type );
}
if(a_data_size > 250000){
printf("bazinga");
}
uint8_t * l_ch_buf = DAP_NEW_SIZE(uint8_t, a_data_size+sizeof(l_hdr));
assert(l_ch_buf);
memcpy(l_ch_buf,&l_hdr,sizeof(l_hdr) );
if(a_data_size+sizeof(l_hdr)> sizeof(a_ch->buf) ){
log_it(L_ERROR,"Too big data size %lu, bigger than encryption buffer size %lu", a_data_size, sizeof(a_ch->buf));
a_data_size=sizeof(a_ch->buf)-sizeof(l_hdr);
}
memcpy(a_ch->buf,&l_hdr,sizeof(l_hdr) );
if( a_data_size )
memcpy(l_ch_buf+sizeof(l_hdr),a_data,a_data_size );
memcpy(a_ch->buf+sizeof(l_hdr),a_data,a_data_size );
size_t l_ret=dap_stream_pkt_write_unsafe(a_ch->stream,l_ch_buf,a_data_size+sizeof(l_hdr));
DAP_DELETE(l_ch_buf);
size_t l_ret=dap_stream_pkt_write_unsafe(a_ch->stream,a_ch->buf,a_data_size+sizeof(l_hdr));
a_ch->stat.bytes_write+=a_data_size;
a_ch->ready_to_write=true;
return l_ret;
......
......@@ -46,6 +46,8 @@ typedef struct dap_stream_ch{
uint64_t bytes_read;
} stat;
uint8_t buf[500000];
dap_stream_ch_proc_t * proc;
void * internal;
struct dap_stream_ch *me;
......
......@@ -121,7 +121,6 @@ size_t dap_stream_pkt_read_unsafe( dap_stream_t * a_stream, dap_stream_pkt_t * a
}
#define DAP_STREAM_PKT_ENCRYPTION_OVERHEAD 200 //intended overkill, it's about ~2*16+15 for oaes
/**
* @brief stream_ch_pkt_write
......@@ -136,23 +135,22 @@ size_t dap_stream_pkt_write_unsafe(dap_stream_t * a_stream, const void * a_data,
size_t ret=0;
stream_pkt_hdr_t pkt_hdr;
size_t l_stream_buf_size = a_data_size + DAP_STREAM_PKT_ENCRYPTION_OVERHEAD;
uint8_t * l_stream_buf = DAP_NEW_SIZE(uint8_t, l_stream_buf_size);
assert(l_stream_buf);
if(a_data_size > STREAM_BUF_SIZE_MAX ){
log_it(L_ERROR,"Too big data size %lu, bigger than encryption buffer size %lu",a_data_size,sizeof(a_stream->buf));
a_data_size=sizeof(a_stream->buf);
}
memset(&pkt_hdr,0,sizeof(pkt_hdr));
memcpy(pkt_hdr.sig,c_dap_stream_sig,sizeof(pkt_hdr.sig));
pkt_hdr.size =(uint32_t) a_stream->session->key->enc_na(a_stream->session->key, a_data,a_data_size,l_stream_buf,l_stream_buf_size);
assert(pkt_hdr.size > 0 && pkt_hdr.size <= l_stream_buf_size);
pkt_hdr.size =(uint32_t) a_stream->session->key->enc_na(a_stream->session->key, a_data,a_data_size,a_stream->buf, STREAM_BUF_SIZE_MAX);
// printf("*[dap_stream_pkt_write] size=%d key=0x%x _inheritor_size=%d\n", pkt_hdr.size, sid->session->key,
// sid->session->key->_inheritor_size);
ret+=dap_events_socket_write_unsafe(a_stream->esocket,&pkt_hdr,sizeof(pkt_hdr));
ret+=dap_events_socket_write_unsafe(a_stream->esocket,l_stream_buf,pkt_hdr.size);
ret+=dap_events_socket_write_unsafe(a_stream->esocket,a_stream->buf,pkt_hdr.size);
dap_events_socket_set_writable_unsafe(a_stream->esocket, true);
DAP_DELETE(l_stream_buf);
return ret;
}
......
......@@ -73,6 +73,7 @@ typedef struct dap_stream {
uint8_t buf_defrag[STREAM_BUF_SIZE_MAX];
uint64_t buf_defrag_size;
uint8_t buf[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
......
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