Skip to content

Commit

Permalink
ames, mesa: miscellaneous stuff (#754)
Browse files Browse the repository at this point in the history
This PR does all kinds of stuff. The main ones are the following:

The udp receive buffer for ames and mesa is now statically allocated.
The sending buffer for ames is also statically allocated, so now we use
`uv_udp_try_send` instead of `uv_udp_send` in ames.

The meaning of the bitset in the mesa pending request structure is
different. It used to answer the question whether we have an outstanding
request for a particular fragment, whereas now it answers the question
"do we have this fragment?".

The misordered queue for mesa is now arbitrarily large instead of 8
fragments long. This means that we can receive fragments in any order.
  • Loading branch information
pkova authored Dec 20, 2024
2 parents 9b527b6 + b44faf2 commit 53683dd
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 127 deletions.
5 changes: 5 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@ fn buildBinary(
.file = "pkg/noun/hashtable_tests.c",
.deps = noun_test_deps,
},
.{
.name = "hamt-test",
.file = "pkg/vere/hamt_test.c",
.deps = vere_test_deps,
},
.{
.name = "jets-test",
.file = "pkg/noun/jets_tests.c",
Expand Down
32 changes: 13 additions & 19 deletions pkg/vere/io/ames.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include <arpa/inet.h>

static c3_y pac_y[4096];

#define FINE_PAGE 4096 // packets per page
#define FINE_FRAG 1024 // bytes per fragment packet
#define FINE_PATH_MAX 384 // longest allowed scry path
Expand Down Expand Up @@ -252,7 +254,6 @@ _ames_pact_free(u3_pact* pac_u)
u3_pier_bail(u3_king_stub());
}

c3_free(pac_u->hun_y);
c3_free(pac_u);
}

Expand Down Expand Up @@ -696,7 +697,7 @@ _fine_etch_response(u3_pact* pac_u)
pre_w = _ames_prel_size(&pac_u->hed_u);
pur_w = _fine_purr_size(&pac_u->pur_u);
pac_u->len_w = HEAD_SIZE + pre_w + pur_w;
pac_u->hun_y = c3_calloc(pac_u->len_w);
pac_u->hun_y = pac_y;

// skip the header until we know what the mug should be
//
Expand Down Expand Up @@ -735,14 +736,14 @@ _lane_scry_path(u3_noun who)
/* _ames_send_cb(): send callback.
*/
static void
_ames_send_cb(uv_udp_send_t* req_u, c3_i sas_i)
_ames_send_cb(u3_pact* pac_u, c3_i sas_i)
{
u3_pact* pac_u = (u3_pact*)req_u;
u3_ames* sam_u = pac_u->sam_u;

if ( !sas_i ) {
if ( sas_i >= 0 ) {
net_o = c3y;
}

else if ( c3y == net_o ) {
u3l_log("ames: send fail: %s", uv_strerror(sas_i));
net_o = c3n;
Expand Down Expand Up @@ -776,15 +777,11 @@ _ames_send(u3_pact* pac_u)

{
uv_buf_t buf_u = uv_buf_init((c3_c*)pac_u->hun_y, pac_u->len_w);
c3_i sas_i = uv_udp_send(&pac_u->snd_u,
&u3_Host.wax_u,
&buf_u, 1,
(const struct sockaddr*)&add_u,
_ames_send_cb);

if ( sas_i ) {
_ames_send_cb(&pac_u->snd_u, sas_i);
}
c3_i sas_i = uv_udp_try_send(&u3_Host.wax_u,
&buf_u, 1,
(const struct sockaddr*)&add_u);

_ames_send_cb(pac_u, sas_i);
}
}
}
Expand Down Expand Up @@ -1344,7 +1341,7 @@ _ames_ef_send(u3_ames* sam_u, u3_noun lan, u3_noun pac)
pac_u->sam_u = sam_u;
pac_u->lan_u = lan_u;
pac_u->len_w = u3r_met(3, pac);
pac_u->hun_y = c3_malloc(pac_u->len_w);
pac_u->hun_y = pac_y;

u3r_bytes(0, pac_u->len_w, pac_u->hun_y, pac);

Expand Down Expand Up @@ -1977,7 +1974,7 @@ _ames_try_forward(u3_pact* pac_u)
old_y = pac_u->hun_y;

pac_u->len_w += 6;
pac_u->hun_y = c3_calloc(pac_u->len_w);
pac_u->hun_y = pac_y;

cur_w = 0;

Expand Down Expand Up @@ -2030,13 +2027,11 @@ _ames_hear(u3_ames* sam_u,
//
if ( c3y == u3_stun_is_request(hun_y, len_w) ) {
_stun_on_request(sam_u, hun_y, adr_u);
c3_free(hun_y);
}
else if ( c3y == u3_stun_is_our_response(hun_y,
sam_u->sun_u.tid_y, len_w) )
{
_stun_on_response(sam_u, hun_y, len_w);
c3_free(hun_y);
}
else {
struct sockaddr_in* add_u = (struct sockaddr_in*)adr_u;
Expand All @@ -2054,7 +2049,6 @@ _ames_hear(u3_ames* sam_u,
sam_u->sat_u.hed_d);
}

c3_free(hun_y);
return;
}

Expand Down
Loading

0 comments on commit 53683dd

Please sign in to comment.