Skip to content

Commit

Permalink
small work on fallback to use and hold less ram
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Apr 24, 2024
1 parent 9f183f5 commit c31f34d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
21 changes: 11 additions & 10 deletions tunnels/server/openssl/openssl_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ typedef struct oss_server_state_s
typedef struct oss_server_con_state_s
{

bool handshake_completed;

bool fallback;
bool handshake_completed;
bool fallback_mode;
bool fallback_init_sent;
bool fallback_first_sent;
buffer_stream_t *fallback_buf;
Expand Down Expand Up @@ -168,6 +167,7 @@ static void fallbackWrite(tunnel_t *self, context_t *c)
size_t record_len = bufferStreamLen(cstate->fallback_buf);
if (record_len == 0)
{
destroyContext(c);
return;
}
if (! cstate->fallback_first_sent)
Expand Down Expand Up @@ -195,11 +195,11 @@ static inline void upStream(tunnel_t *self, context_t *c)
if (c->payload != NULL)
{

if (! cstate->handshake_completed)
if (state->fallback != NULL && ! cstate->handshake_completed)
{
bufferStreamPush(cstate->fallback_buf, newShallowShiftBuffer(c->payload));
}
if (cstate->fallback)
if (cstate->fallback_mode)
{
reuseContextBuffer(c);
if (state->fallback_delay <= 0)
Expand Down Expand Up @@ -278,7 +278,7 @@ static inline void upStream(tunnel_t *self, context_t *c)
printSSLError();
if (state->fallback != NULL)
{
cstate->fallback = true;
cstate->fallback_mode = true;
if (state->fallback_delay <= 0)
{
fallbackWrite(self, c);
Expand All @@ -304,8 +304,9 @@ static inline void upStream(tunnel_t *self, context_t *c)

LOGD("OpensslServer: Tls handshake complete");
cstate->handshake_completed = true;
context_t *up_init_ctx = newInitContext(c->line);
up_init_ctx->src_io = c->src_io;
empytBufferStream(cstate->fallback_buf);
context_t *up_init_ctx = newInitContext(c->line);
up_init_ctx->src_io = c->src_io;
self->up->upStream(self->up, up_init_ctx);
if (! isAlive(c->line))
{
Expand Down Expand Up @@ -431,7 +432,7 @@ static inline void upStream(tunnel_t *self, context_t *c)
else if (c->fin)
{

if (cstate->fallback)
if (cstate->fallback_mode)
{
if (cstate->fallback_init_sent)
{
Expand Down Expand Up @@ -491,7 +492,7 @@ static inline void downStream(tunnel_t *self, context_t *c)

if (! cstate->handshake_completed)
{
if (cstate->fallback)
if (cstate->fallback_mode)
{
self->dw->downStream(self->dw, c);
return; // not gona encrypt fall back data
Expand Down
8 changes: 4 additions & 4 deletions ww/buffer_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#endif

#define LOW_MEMORY 0 // no preallocation (very small)
#define MED1_MEMORY 1 // APPROX 10MB per thread
#define MED2_MEMORY 2 // APPROX 20MB per thread
#define HIG1_MEMORY 3 // APPROX 28MB per thread
#define HIG2_MEMORY 4 // APPROX 36MB per thread
#define MED1_MEMORY 1 // APPROX 20MB per thread
#define MED2_MEMORY 2 // APPROX 40MB per thread
#define HIG1_MEMORY 3 // APPROX 56MB per thread
#define HIG2_MEMORY 4 // APPROX 72MB per thread

#define MEMORY_PROFILE HIG2_MEMORY // todo (cmake)

Expand Down
7 changes: 6 additions & 1 deletion ww/buffer_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ buffer_stream_t *newBufferStream(struct buffer_pool_s *pool)
return bs;
}

void destroyBufferStream(buffer_stream_t *self)
void empytBufferStream(buffer_stream_t *self)
{
c_foreach(i, queue, self->q) { reuseBuffer(self->pool, *i.ref); }
}

void destroyBufferStream(buffer_stream_t *self)
{
empytBufferStream(self);
queue_drop(&self->q);
free(self);
}
Expand Down
1 change: 1 addition & 0 deletions ww/buffer_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct buffer_stream_s
typedef struct buffer_stream_s buffer_stream_t;

buffer_stream_t *newBufferStream(buffer_pool_t *pool);
void empytBufferStream(buffer_stream_t *self);
void destroyBufferStream(buffer_stream_t *self);
void bufferStreamPush(buffer_stream_t *self, shift_buffer_t *buf);
shift_buffer_t * bufferStreamRead(buffer_stream_t *self, size_t bytes);
Expand Down

0 comments on commit c31f34d

Please sign in to comment.