diff --git a/tunnels/server/openssl/openssl_server.c b/tunnels/server/openssl/openssl_server.c index f31a60b4..c2ca0d9b 100644 --- a/tunnels/server/openssl/openssl_server.c +++ b/tunnels/server/openssl/openssl_server.c @@ -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; @@ -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) @@ -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) @@ -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); @@ -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)) { @@ -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) { @@ -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 diff --git a/ww/buffer_pool.c b/ww/buffer_pool.c index ba9d8f93..622506f9 100644 --- a/ww/buffer_pool.c +++ b/ww/buffer_pool.c @@ -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) diff --git a/ww/buffer_stream.c b/ww/buffer_stream.c index 94736644..ec62f010 100644 --- a/ww/buffer_stream.c +++ b/ww/buffer_stream.c @@ -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); } diff --git a/ww/buffer_stream.h b/ww/buffer_stream.h index b029eaf5..15b0b293 100644 --- a/ww/buffer_stream.h +++ b/ww/buffer_stream.h @@ -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);