Skip to content

Commit

Permalink
refix & format
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jun 14, 2024
1 parent 1fb022c commit 1c459f8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 33 deletions.
5 changes: 1 addition & 4 deletions tunnels/client/halfduplex/halfduplex_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
29 changes: 8 additions & 21 deletions tunnels/server/halfduplex/halfduplex_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -565,15 +551,16 @@ 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);
buf_ctx->payload = upload_line_cstate->buffering;
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
Expand Down
8 changes: 4 additions & 4 deletions tunnels/server/reality/reality_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions tunnels/server/reverse/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion ww/utils/mathutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
#define MAXOF(t) ((unsigned long long) (ISSIGNED(t) ? SMAXOF(t) : UMAXOF(t)))

0 comments on commit 1c459f8

Please sign in to comment.