Skip to content

Commit

Permalink
associate randomly
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jun 16, 2024
1 parent 2a49d1f commit f6f8f4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 9 additions & 2 deletions tunnels/server/reverse/reverse_server.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "reverse_server.h"
#include "buffer_pool.h"
#include "frand.h"
#include "helpers.h"
#include "hplatform.h"
#include "loggers/network_logger.h"
Expand Down Expand Up @@ -68,6 +69,13 @@ static void upStream(tunnel_t *self, context_t *c)
{

reverse_server_con_state_t *ucstate = this_tb->u_cons_root.next;

size_t random_choosen = (fastRand() % this_tb->u_count);
while (random_choosen--)
{
ucstate = ucstate->next;
}

removeConnectionU(this_tb, ucstate);
ucstate->d = c->line;
ucstate->paired = true;
Expand Down Expand Up @@ -199,7 +207,6 @@ static void downStream(tunnel_t *self, context_t *c)
}
else
{

self->dw->downStream(self->dw, switchLine(c, dcstate->d));
}
}
Expand Down Expand Up @@ -251,7 +258,7 @@ static void downStream(tunnel_t *self, context_t *c)
{
doneLineUpSide(ucstate->d);
doneLineUpSide(ucstate->u);
line_t *d_line = ucstate->d;
line_t *d_line = ucstate->d;
LSTATE_I_MUT(ucstate->d, state->chain_index_d) = NULL;
cleanup(ucstate);
self->dw->downStream(self->dw, switchLine(c, d_line));
Expand Down
3 changes: 1 addition & 2 deletions tunnels/server/reverse/types.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#pragma once
#include "api.h"
#include "buffer_stream.h"
#include "hatomic.h"
#include "shiftbuffer.h"


typedef struct reverse_server_con_state_s
{
Expand Down

0 comments on commit f6f8f4e

Please sign in to comment.