Skip to content

Commit

Permalink
fixes for http2 client / server (first packet mark)
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Mar 28, 2024
1 parent 668e47d commit 3deff8e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tunnels/client/http2/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static http2_client_con_state_t *take_http2_connection(tunnel_t *self, int tid,
if (vec_cons_size(vector) > 0)
{
// http2_client_con_state_t * con = *vec_cons_at(vector, round_index);
c_foreach(k, vec_cons, vector)
c_foreach(k, vec_cons, *vector)
{
if ((*k.ref)->childs_added < MAX_CHILD_PER_STREAM)
{
Expand Down
17 changes: 11 additions & 6 deletions tunnels/client/http2/http2_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static void sendGrpcFinalData(tunnel_t *self, line_t *line, size_t stream_id)
endstream_ctx->payload = buf;
self->up->upStream(self->up, endstream_ctx);
}
static bool trySendRequest(tunnel_t *self, http2_client_con_state_t *con, size_t stream_id,hio_t*stream_io, shift_buffer_t *buf)
static bool trySendRequest(tunnel_t *self, http2_client_con_state_t *con, size_t stream_id, hio_t *stream_io, shift_buffer_t *buf)
{
line_t *line = con->line;
if (con == NULL)
Expand All @@ -34,6 +34,11 @@ static bool trySendRequest(tunnel_t *self, http2_client_con_state_t *con, size_t
context_t *req = newContext(line);
req->payload = send_buf;
req->src_io = stream_io;
if (!con->first_sent)
{
con->first_sent = true;
req->first = true;
}
self->up->upStream(self->up, req);

if (nghttp2_session_want_read(con->session) == 0 &&
Expand Down Expand Up @@ -116,7 +121,7 @@ static void flush_write_queue(http2_client_con_state_t *con)
con->state = H2_SEND_HEADERS;

// consumes payload
while (trySendRequest(self, con, stream->stream_id,stream->io, stream_context->payload))
while (trySendRequest(self, con, stream->stream_id, stream->io, stream_context->payload))
;

if (con->line->chains_state[self->chain_index] == NULL)
Expand Down Expand Up @@ -309,7 +314,7 @@ static inline void upStream(tunnel_t *self, context_t *c)
con->state = H2_SEND_HEADERS;

// consumes payload
while (trySendRequest(self, con, stream->stream_id,stream->io , c->payload))
while (trySendRequest(self, con, stream->stream_id, stream->io, c->payload))
;
c->payload = NULL;
destroyContext(c);
Expand All @@ -318,7 +323,7 @@ static inline void upStream(tunnel_t *self, context_t *c)
{
if (c->init)
{
http2_client_con_state_t *con = take_http2_connection(self, c->line->tid,NULL);
http2_client_con_state_t *con = take_http2_connection(self, c->line->tid, NULL);
if (con->line->chains_state[self->chain_index] == NULL)
{
destroyContext(c);
Expand All @@ -328,7 +333,7 @@ static inline void upStream(tunnel_t *self, context_t *c)
while (trySendRequest(self, con, 0, NULL, NULL))
;

http2_client_child_con_state_t *stream = create_http2_stream(con, c->line,c->src_io);
http2_client_child_con_state_t *stream = create_http2_stream(con, c->line, c->src_io);
CSTATE_MUT(c) = stream;

if (!ISALIVE(c))
Expand Down Expand Up @@ -374,7 +379,7 @@ static inline void downStream(tunnel_t *self, context_t *c)
http2_client_state_t *state = STATE(self);
http2_client_con_state_t *con = CSTATE(c);
con->io = c->src_io;

if (c->payload != NULL)
{

Expand Down
1 change: 1 addition & 0 deletions tunnels/client/http2/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef struct http2_client_con_state_s
int host_port;
const char *scheme;
bool init_sent;
bool first_sent;

tunnel_t *tunnel;
line_t *line;
Expand Down
16 changes: 10 additions & 6 deletions tunnels/server/http2/http2_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ static int on_data_chunk_recv_callback(nghttp2_session *session,
context_t *stream_data = newContext(stream->line);
stream_data->payload = buf;
stream_data->src_io = con->io;

if (!stream->first_sent)
{
stream->first_sent = true;
stream_data->first = true;
}
stream->tunnel->upStream(stream->tunnel, stream_data);
// if (hp->parsed->http_cb)
// {
Expand Down Expand Up @@ -195,7 +199,7 @@ static int on_frame_recv_callback(nghttp2_session *session,
return 0;
}

static bool trySendResponse(tunnel_t *self, http2_server_con_state_t *con, size_t stream_id,hio_t*stream_io, shift_buffer_t *buf)
static bool trySendResponse(tunnel_t *self, http2_server_con_state_t *con, size_t stream_id, hio_t *stream_io, shift_buffer_t *buf)
{
line_t *line = con->line;
// http2_server_con_state_t *con = ((http2_server_con_state_t *)(((line->chains_state)[self->chain_index])));
Expand Down Expand Up @@ -314,15 +318,15 @@ static inline void upStream(tunnel_t *self, context_t *c)
return;
}

while (trySendResponse(self, con, 0,NULL, NULL))
while (trySendResponse(self, con, 0, NULL, NULL))
;
destroyContext(c);
}
else
{
if (c->init)
{
CSTATE_MUT(c) = create_http2_connection(self, c->line,c->src_io);
CSTATE_MUT(c) = create_http2_connection(self, c->line, c->src_io);
destroyContext(c);
}
else if (c->fin)
Expand All @@ -342,7 +346,7 @@ static inline void downStream(tunnel_t *self, context_t *c)
if (c->payload != NULL)
{
con->state = H2_SEND_HEADERS;
while (trySendResponse(self, con, stream->stream_id,stream->io, c->payload))
while (trySendResponse(self, con, stream->stream_id, stream->io, c->payload))
;
c->payload = NULL;
destroyContext(c);
Expand All @@ -359,7 +363,7 @@ static inline void downStream(tunnel_t *self, context_t *c)
}
else
nghttp2_submit_headers(con->session, flags, stream->stream_id, NULL, NULL, 0, NULL);
while (trySendResponse(self, con, stream->stream_id,NULL, NULL))
while (trySendResponse(self, con, stream->stream_id, NULL, NULL))
;

nghttp2_session_set_stream_user_data(con->session, stream->stream_id, NULL);
Expand Down
2 changes: 1 addition & 1 deletion tunnels/server/http2/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef struct http2_server_child_con_state_s
struct http2_server_child_con_state_s *prev, *next;
char *request_path;
int32_t stream_id;

bool first_sent;
line_t *parent;
line_t *line;
hio_t* io;
Expand Down

0 comments on commit 3deff8e

Please sign in to comment.