Skip to content

Commit

Permalink
http2 tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jun 19, 2024
1 parent 56afc2b commit d8cf2c9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 31 deletions.
10 changes: 5 additions & 5 deletions tunnels/client/http2/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ static void onStreamLineResumed(void *arg)
static void onH2LinePaused(void *arg)
{
http2_client_con_state_t *con = (http2_client_con_state_t *) arg;
++(con->pause_counter);
if (con->pause_counter > 8)
{
// ++(con->pause_counter);
// if (con->pause_counter > 8)
// {
http2_client_child_con_state_t *stream_i;
for (stream_i = con->root.next; stream_i;)
{
pauseLineDownSide(stream_i->line);
stream_i = stream_i->next;
}
}
// }
}

static void onH2LineResumed(void *arg)
{
http2_client_con_state_t *con = (http2_client_con_state_t *) arg;
con->pause_counter = con->pause_counter > 0 ? (con->pause_counter - 1) : con->pause_counter;
// con->pause_counter = con->pause_counter > 0 ? (con->pause_counter - 1) : con->pause_counter;
http2_client_child_con_state_t *stream_i;
for (stream_i = con->root.next; stream_i;)
{
Expand Down
25 changes: 20 additions & 5 deletions tunnels/client/http2/http2_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,12 @@ static int onFrameRecvCallback(nghttp2_session *session, const nghttp2_frame *fr
{
return 0;
}
// http2_client_state_t *state = STATE(self);
resumeLineUpSide(stream->parent);
nghttp2_session_set_stream_user_data(con->session, stream->stream_id, NULL);
context_t *fc = newFinContext(stream->line);
context_t *fc = newFinContext(stream->line);
CSTATE_DROP(fc);
tunnel_t *dest = stream->tunnel->dw;
tunnel_t *dest = stream->tunnel->dw;
removeStream(con, stream);
deleteHttp2Stream(stream);
dest->downStream(dest, fc);
Expand Down Expand Up @@ -397,20 +398,26 @@ static void upStream(tunnel_t *self, context_t *c)
if (con->content_type == kApplicationGrpc && con->handshake_completed)
{
sendGrpcFinalData(self, con->line, stream->stream_id);
if (! isAlive(c->line))
{
destroyContext(c);
return;
}
}

resumeLineUpSide(con->line);
nghttp2_session_set_stream_user_data(con->session, stream->stream_id, NULL);
removeStream(con, stream);
deleteHttp2Stream(stream);

if (con->root.next == NULL && con->childs_added >= state->concurrency && isAlive(c->line))
{
context_t *con_fc = newFinContext(con->line);
tunnel_t *con_dest = con->tunnel->up;
deleteHttp2Connection(con);
con_dest->upStream(con_dest, con_fc);
}

deleteHttp2Stream(stream);

destroyContext(c);
return;
}
Expand All @@ -419,7 +426,8 @@ static void upStream(tunnel_t *self, context_t *c)

static void downStream(tunnel_t *self, context_t *c)
{
http2_client_con_state_t *con = CSTATE(c);
http2_client_state_t *state = STATE(self);
http2_client_con_state_t *con = CSTATE(c);
if (c->payload != NULL)
{
size_t len = 0;
Expand Down Expand Up @@ -471,6 +479,13 @@ static void downStream(tunnel_t *self, context_t *c)
}
}

if (con->root.next == NULL && con->childs_added >= state->concurrency)
{
context_t *con_fc = newFinContext(con->line);
deleteHttp2Connection(con);
self->up->upStream(self->up, con_fc);
}

reuseContextBuffer(c);
destroyContext(c);
}
Expand Down
25 changes: 12 additions & 13 deletions tunnels/server/http2/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ static void onH2LinePaused(void *arg)
{
http2_server_con_state_t *con = (http2_server_con_state_t *) arg;


++(con->pause_counter);
if (con->pause_counter > 16)
{
http2_server_child_con_state_t *stream_i;
for (stream_i = con->root.next; stream_i;)
{
pauseLineUpSide(stream_i->line);
stream_i = stream_i->next;
}
http2_server_child_con_state_t *stream_i;
for (stream_i = con->root.next; stream_i;)
{
pauseLineUpSide(stream_i->line);
stream_i = stream_i->next;
}
}
}

Expand All @@ -84,18 +83,18 @@ static void onH2LineResumed(void *arg)
}

http2_server_child_con_state_t *createHttp2Stream(http2_server_con_state_t *con, line_t *this_line, tunnel_t *self,
int32_t stream_id)
int32_t stream_id)
{
http2_server_child_con_state_t *stream;
stream = malloc(sizeof(http2_server_child_con_state_t));
memset(stream, 0, sizeof(http2_server_child_con_state_t));

stream->stream_id = stream_id;
stream->chunkbs = newBufferStream(getLineBufferPool(this_line));
stream->parent = this_line;
stream->line = newLine(this_line->tid);
stream->stream_id = stream_id;
stream->chunkbs = newBufferStream(getLineBufferPool(this_line));
stream->parent = this_line;
stream->line = newLine(this_line->tid);
LSTATE_MUT(stream->line) = stream;
stream->tunnel = self;
stream->tunnel = self;
nghttp2_session_set_stream_user_data(con->session, stream_id, stream);
setupLineDownSide(stream->line, onStreamLinePaused, stream, onStreamLineResumed);

Expand Down
9 changes: 7 additions & 2 deletions tunnels/server/http2/http2_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static int onFrameRecvCallback(nghttp2_session *session, const nghttp2_frame *fr
tunnel_t *dest = stream->tunnel->up;
CSTATE_DROP(fc);
removeStream(con, stream);
deleteHttp2Stream(stream);
deleteHttp2Stream(stream);
dest->upStream(dest, fc);
return 0;
}
Expand Down Expand Up @@ -353,7 +353,7 @@ static void upStream(tunnel_t *self, context_t *c)
return;
}
}

reuseContextBuffer(c);
destroyContext(c);
}
Expand Down Expand Up @@ -423,6 +423,11 @@ static void downStream(tunnel_t *self, context_t *c)
return;
}
}
if (! isAlive(c->line))
{
destroyContext(c);
return;
}

if (nghttp2_session_want_read(con->session) == 0 && nghttp2_session_want_write(con->session) == 0)
{
Expand Down
11 changes: 5 additions & 6 deletions tunnels/server/http2/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ typedef struct http2_server_child_con_state_s
char *request_path;
int32_t stream_id;
bool first_sent;

buffer_stream_t *chunkbs; // used for grpc
size_t bytes_needed;
line_t *parent;
line_t *line;
tunnel_t *tunnel;
buffer_stream_t *chunkbs; // used for grpc
size_t bytes_needed;
line_t *parent;
line_t *line;
tunnel_t *tunnel;
} http2_server_child_con_state_t;

typedef struct http2_server_con_state_s
Expand Down

0 comments on commit d8cf2c9

Please sign in to comment.