Skip to content

Commit

Permalink
daemon/session2: protocol layer refactors + docs
Browse files Browse the repository at this point in the history
This makes some readability enhancements to the `protolayer_` API as
well as clarifies some of the documentation.

There is also a change where the definitions of protocol layer sequences
does not require a `_NULL` layer to be present at the end anymore, as
the number of layers in a sequence is determined at compile time. This
makes defining new sequences less error-prone.
  • Loading branch information
Oto Šťáva committed Jun 4, 2024
1 parent 870dc3a commit dfe44a9
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 102 deletions.
11 changes: 6 additions & 5 deletions daemon/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ static ssize_t send_callback(nghttp2_session *h2, const uint8_t *data, size_t le

kr_log_debug(DOH, "[%p] send_callback: %p\n", (void *)h2, (void *)send_ctx->data);
session2_wrap_after(http->h.session, PROTOLAYER_TYPE_HTTP,
protolayer_buffer(send_ctx->data, length, false), NULL,
callback_finished_free_baton, send_ctx);
protolayer_payload_buffer(send_ctx->data, length, false),
NULL, callback_finished_free_baton, send_ctx);

return length;
}
Expand Down Expand Up @@ -506,7 +506,7 @@ static int send_data_callback(nghttp2_session *h2, nghttp2_frame *frame, const u

kr_assert(cur == iovcnt);
int ret = session2_wrap_after(http->h.session, PROTOLAYER_TYPE_HTTP,
protolayer_iovec(dest_iov, cur, false),
protolayer_payload_iovec(dest_iov, cur, false),
NULL, callback_finished_free_baton, sdctx);

if (ret < 0)
Expand Down Expand Up @@ -733,7 +733,8 @@ static int submit_to_wirebuffer(struct pl_http_sess_data *ctx)

ret = 0;
session2_unwrap_after(ctx->h.session, PROTOLAYER_TYPE_HTTP,
protolayer_wire_buf(wb, false), NULL, NULL, NULL);
protolayer_payload_wire_buf(wb, false),
NULL, NULL, NULL);
cleanup:
http_cleanup_stream(ctx);
return ret;
Expand Down Expand Up @@ -938,7 +939,7 @@ static enum protolayer_iter_cb_result pl_http_unwrap(

struct protolayer_payload pld = ctx->payload;
if (pld.type == PROTOLAYER_PAYLOAD_WIRE_BUF) {
pld = protolayer_as_buffer(&pld);
pld = protolayer_payload_as_buffer(&pld);
}

if (pld.type == PROTOLAYER_PAYLOAD_BUFFER) {
Expand Down
12 changes: 6 additions & 6 deletions daemon/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void udp_recv(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf,
.comm_addr = comm_addr,
.src_addr = comm_addr
};
session2_unwrap(s, protolayer_wire_buf(&s->layers->wire_buf, false),
session2_unwrap(s, protolayer_payload_wire_buf(&s->layers->wire_buf, false),
&in_comm, udp_on_unwrapped, NULL);
}

Expand Down Expand Up @@ -146,7 +146,7 @@ struct pl_udp_iter_data {
static enum protolayer_iter_cb_result pl_udp_unwrap(
void *sess_data, void *iter_data, struct protolayer_iter_ctx *ctx)
{
ctx->payload = protolayer_as_buffer(&ctx->payload);
ctx->payload = protolayer_payload_as_buffer(&ctx->payload);
if (kr_fails_assert(ctx->payload.type == PROTOLAYER_PAYLOAD_BUFFER)) {
/* unsupported payload */
return protolayer_break(ctx, kr_error(EINVAL));
Expand Down Expand Up @@ -197,7 +197,7 @@ static enum protolayer_iter_cb_result pl_udp_unwrap(
}
}

ctx->payload = protolayer_buffer(
ctx->payload = protolayer_payload_buffer(
data + trimmed, data_len - trimmed, false);
}

Expand Down Expand Up @@ -278,7 +278,7 @@ static enum protolayer_iter_cb_result pl_tcp_unwrap(

memcpy(wire_buf_free_space(&tcp->wire_buf), buf, len);
wire_buf_consume(&tcp->wire_buf, ctx->payload.buffer.len);
ctx->payload = protolayer_wire_buf(&tcp->wire_buf, false);
ctx->payload = protolayer_payload_wire_buf(&tcp->wire_buf, false);
}

if (kr_fails_assert(ctx->payload.type == PROTOLAYER_PAYLOAD_WIRE_BUF)) {
Expand Down Expand Up @@ -511,7 +511,7 @@ static void tcp_recv(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf)
return;
}

session2_unwrap(s, protolayer_wire_buf(&s->layers->wire_buf, false),
session2_unwrap(s, protolayer_payload_wire_buf(&s->layers->wire_buf, false),
NULL, NULL, NULL);
}

Expand Down Expand Up @@ -950,7 +950,7 @@ static void xdp_rx(uv_poll_t* handle, int status, int events)
memcpy(comm.eth_from, msg->eth_from, sizeof(comm.eth_from));
memcpy(comm.eth_to, msg->eth_to, sizeof(comm.eth_to));
session2_unwrap(xhd->session,
protolayer_buffer(
protolayer_payload_buffer(
msg->payload.iov_base,
msg->payload.iov_len, false),
&comm, NULL, NULL);
Expand Down
Loading

0 comments on commit dfe44a9

Please sign in to comment.