diff --git a/tunnels/client/halfduplex/halfduplex_client.c b/tunnels/client/halfduplex/halfduplex_client.c index c511d47b..ae4e2456 100644 --- a/tunnels/client/halfduplex/halfduplex_client.c +++ b/tunnels/client/halfduplex/halfduplex_client.c @@ -67,11 +67,8 @@ static void upStream(tunnel_t *self, context_t *c) } cid_bytes[0] = cid_bytes[0] & 0x7f; // kHLFDCmdUpload - unsigned int blen = bufLen(c->payload); - setLen(c->payload, blen + sizeof(uint64_t)); - shiftr(c->payload, blen); + shiftl(c->payload,8); writeRaw(c->payload, cid_bytes, sizeof(cids)); - shiftl(c->payload, blen); } self->up->upStream(self->up, switchLine(c, cstate->upload_line)); } diff --git a/tunnels/server/halfduplex/halfduplex_server.c b/tunnels/server/halfduplex/halfduplex_server.c index 7ddb4e59..099a6cbf 100644 --- a/tunnels/server/halfduplex/halfduplex_server.c +++ b/tunnels/server/halfduplex/halfduplex_server.c @@ -146,12 +146,10 @@ static void localUpStream(tunnel_t *self, context_t *c, pipe_line_t *pl) if (c->first) { assert(bufLen(buf) >= sizeof(uint64_t)); - unsigned int blen = bufLen(buf); - shiftr(c->payload, blen - sizeof(uint64_t)); - hash_t hash = 0x0; + hash_t hash = 0x0; readUI64(c->payload, (uint64_t *) &hash); cstate->hash = hash; - shiftl(c->payload, blen - sizeof(uint64_t)); + shiftr(c->payload, sizeof(uint64_t)); hhybridmutex_lock(&(state->download_line_map_mutex)); hmap_cons_t_iter f_iter = hmap_cons_t_find(&(state->download_line_map), hash); @@ -199,7 +197,6 @@ static void localUpStream(tunnel_t *self, context_t *c, pipe_line_t *pl) } unLockLine(main_line); - setLen(buf, blen - sizeof(uint64_t)); // dont need the hash part if (bufLen(buf) > 0) { @@ -394,15 +391,12 @@ static void upStream(tunnel_t *self, context_t *c) destroyContext(c); return; } - unsigned int blen = bufLen(buf); - shiftr(c->payload, blen - sizeof(uint64_t)); const bool is_upload = (((uint8_t *) rawBuf(c->payload))[0] & 0x80) == 0x0; ((uint8_t *) rawBufMut(c->payload))[0] = (((uint8_t *) rawBuf(c->payload))[0] & 0x7F); hash_t hash = 0x0; readUI64(c->payload, (uint64_t *) &hash); cstate->hash = hash; - shiftl(c->payload, blen - sizeof(uint64_t)); if (is_upload) { @@ -454,8 +448,7 @@ static void upStream(tunnel_t *self, context_t *c) } unLockLine(main_line); - - setLen(buf, blen - sizeof(uint64_t)); // dont need the hash part + shiftr(c->payload, sizeof(uint64_t)); if (bufLen(buf) > 0) { if (! cstate->first_sent) @@ -505,15 +498,8 @@ static void upStream(tunnel_t *self, context_t *c) return; } - if (bufLen(buf) > 0) - { - cstate->buffering = buf; - c->payload = NULL; - } - else - { - reuseContextBuffer(c); - } + cstate->buffering = buf; + c->payload = NULL; // upload connection is waiting in the pool } } @@ -565,8 +551,8 @@ static void upStream(tunnel_t *self, context_t *c) assert(upload_line_cstate->buffering); - setLen(upload_line_cstate->buffering, - bufLen(upload_line_cstate->buffering) - sizeof(uint64_t)); // dont need the hash part + + shiftr(upload_line_cstate->buffering, sizeof(uint64_t)); if (bufLen(upload_line_cstate->buffering) > 0) { context_t *buf_ctx = newContext(main_line); @@ -574,6 +560,7 @@ static void upStream(tunnel_t *self, context_t *c) buf_ctx->first = true; upload_line_cstate->buffering = NULL; upload_line_cstate->first_sent = true; + shiftr(buf_ctx->payload, sizeof(uint64_t)); self->up->upStream(self->up, buf_ctx); } else diff --git a/tunnels/server/reality/reality_server.c b/tunnels/server/reality/reality_server.c index b70ba387..ace22a83 100644 --- a/tunnels/server/reality/reality_server.c +++ b/tunnels/server/reality/reality_server.c @@ -43,7 +43,6 @@ typedef struct reality_server_con_state_s uint8_t giveup_counter; enum connection_auth_state auth_state; bool first_sent; - bool init_sent; uint32_t reply_sent_tit; } reality_server_con_state_t; @@ -124,9 +123,10 @@ static void upStream(tunnel_t *self, context_t *c) buf = genericDecrypt(buf, cstate->decryption_context, state->context_password, getContextBufferPool(c)); - + cstate->first_sent = true; context_t *plain_data_ctx = newContextFrom(c); plain_data_ctx->payload = buf; + plain_data_ctx->first = true; self->up->upStream(self->up, plain_data_ctx); if (! isAlive(c->line)) @@ -192,10 +192,10 @@ static void upStream(tunnel_t *self, context_t *c) context_t *plain_data_ctx = newContextFrom(c); plain_data_ctx->payload = buf; - if (WW_UNLIKELY(! cstate->init_sent)) + if (WW_UNLIKELY(! cstate->first_sent)) { plain_data_ctx->first = true; - cstate->init_sent = true; + cstate->first_sent = true; } self->up->upStream(self->up, plain_data_ctx); } diff --git a/tunnels/server/reverse/helpers.h b/tunnels/server/reverse/helpers.h index 1dd7bd1e..8a41dad6 100644 --- a/tunnels/server/reverse/helpers.h +++ b/tunnels/server/reverse/helpers.h @@ -79,7 +79,7 @@ static reverse_server_con_state_t *createCstate(bool isup, line_t *line) else { cstate->wait_stream = newBufferStream(getLineBufferPool(line)); - cstate->d = line; + cstate->d = line; } return cstate; } @@ -90,9 +90,10 @@ static void cleanup(reverse_server_con_state_t *cstate) if (cstate->uqueue) { destroyContextQueue(cstate->uqueue); - }else{ + } + else + { destroyBufferStream(cstate->wait_stream); - } free(cstate); } diff --git a/ww/utils/mathutils.h b/ww/utils/mathutils.h index 4ea22305..107a9f75 100644 --- a/ww/utils/mathutils.h +++ b/ww/utils/mathutils.h @@ -25,4 +25,4 @@ static inline ssize_t max(ssize_t x, ssize_t y) { return (((x) < (y)) ? (y) : (x #define SMAXOF(t) (((0x1ULL << ((sizeof(t) * 8ULL) - 1ULL)) - 1ULL) | \ (0x7ULL << ((sizeof(t) * 8ULL) - 4ULL))) -#define MAXOF(t) ((unsigned long long) (ISSIGNED(t) ? SMAXOF(t) : UMAXOF(t))) \ No newline at end of file +#define MAXOF(t) ((unsigned long long) (ISSIGNED(t) ? SMAXOF(t) : UMAXOF(t)))