From fb180897b37f5d9c7110d9365de742ab1d518681 Mon Sep 17 00:00:00 2001 From: pkova Date: Fri, 13 Oct 2023 14:27:59 +0300 Subject: [PATCH 1/5] ames: handle %nail gift, lanes to vere cache --- pkg/vere/io/ames.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 24baa6e042..0f5ef18fdd 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -920,27 +920,11 @@ _ames_lane_into_cache(u3p(u3h_root) lax_p, u3_noun who, u3_noun las) { u3z(who); } -/* _ames_lane_from_cache(): retrieve lane for who from cache, if any & fresh +/* _ames_lane_from_cache(): retrieve lane for who from cache, if any */ static u3_weak _ames_lane_from_cache(u3p(u3h_root) lax_p, u3_noun who) { u3_weak lac = u3h_git(lax_p, who); - - if ( u3_none != lac ) { - struct timeval tim_tv; - gettimeofday(&tim_tv, 0); - u3_noun now = u3_time_in_tv(&tim_tv); - u3_noun den = u3t(lac); - - // consider entries older than 2 minutes stale, ignore them - // - if ( 120000 > u3_time_gap_ms(u3k(den), now) ) { - lac = u3k(u3h(lac)); - } else { - lac = u3_none; - } - } - u3z(who); return lac; } @@ -2276,6 +2260,13 @@ _ames_kick_newt(u3_ames* sam_u, u3_noun tag, u3_noun dat) _ames_ef_turf(sam_u, u3k(dat)); ret_o = c3y; } break; + + case c3__nail: { + u3_noun who = u3k(u3h(dat)); + u3_noun las = u3k(u3t(dat)); + _ames_lane_into_cache(sam_u->lax_p, who, las); + ret_o = c3y; + } break; } u3z(tag); u3z(dat); From 4b523ada560b7b0eb011f940aeebfe53e348072f Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 16 Oct 2023 20:01:07 +0300 Subject: [PATCH 2/5] ames: wait for %nail before enabling new lane cache behavior --- pkg/vere/io/ames.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 0f5ef18fdd..646afa28ed 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -45,6 +45,7 @@ c3_w imp_w[256]; // imperial IPs time_t imp_t[256]; // imperial IP timestamps c3_o imp_o[256]; // imperial print status + c3_d nal_d; // lane cache backcompat flag struct { // config: c3_o net_o; // can send c3_o see_o; // can scry @@ -923,8 +924,24 @@ _ames_lane_into_cache(u3p(u3h_root) lax_p, u3_noun who, u3_noun las) { /* _ames_lane_from_cache(): retrieve lane for who from cache, if any */ static u3_weak -_ames_lane_from_cache(u3p(u3h_root) lax_p, u3_noun who) { +_ames_lane_from_cache(u3p(u3h_root) lax_p, u3_noun who, c3_o nal) { u3_weak lac = u3h_git(lax_p, who); + + if (nal == c3n && u3_none != lac ) { + struct timeval tim_tv; + gettimeofday(&tim_tv, 0); + u3_noun now = u3_time_in_tv(&tim_tv); + u3_noun den = u3t(lac); + + // consider entries older than 2 minutes stale, ignore them + // + if ( 120000 > u3_time_gap_ms(u3k(den), now) ) { + lac = u3k(u3h(lac)); + } else { + lac = u3_none; + } + } + u3z(who); return lac; } @@ -1461,7 +1478,7 @@ _ames_try_send(u3_pact* pac_u, c3_o for_o) // else { u3_noun key = u3i_chubs(2, pac_u->pre_u.rec_d); - lac = _ames_lane_from_cache(sam_u->lax_p, key); + lac = _ames_lane_from_cache(sam_u->lax_p, key, sam_u->nal_d); } // if we know there's no lane, drop the packet @@ -2265,6 +2282,7 @@ _ames_kick_newt(u3_ames* sam_u, u3_noun tag, u3_noun dat) u3_noun who = u3k(u3h(dat)); u3_noun las = u3k(u3t(dat)); _ames_lane_into_cache(sam_u->lax_p, who, las); + sam_u->nal_d = c3y; ret_o = c3y; } break; } @@ -2448,6 +2466,7 @@ u3_ames_io_init(u3_pier* pir_u) { u3_ames* sam_u = c3_calloc(sizeof(*sam_u)); sam_u->pir_u = pir_u; + sam_u->nal_d = c3n; sam_u->fig_u.net_o = c3y; sam_u->fig_u.see_o = c3y; sam_u->fig_u.fit_o = c3n; From 1e24bfbe119f9f6e7aa5e1eae5d9e50e5f2deaac Mon Sep 17 00:00:00 2001 From: Pyry Kovanen Date: Mon, 6 Nov 2023 18:36:50 +0200 Subject: [PATCH 3/5] ames: convert nal_d from c3_d to co_o --- pkg/vere/io/ames.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 646afa28ed..6f934bb062 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -45,7 +45,7 @@ c3_w imp_w[256]; // imperial IPs time_t imp_t[256]; // imperial IP timestamps c3_o imp_o[256]; // imperial print status - c3_d nal_d; // lane cache backcompat flag + c3_o nal_d; // lane cache backcompat flag struct { // config: c3_o net_o; // can send c3_o see_o; // can scry From c6dbc603918c9829b53b09aa81e601fa051a078d Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 6 Nov 2023 19:28:35 +0200 Subject: [PATCH 4/5] ames: rename nal_d to nal_o --- pkg/vere/io/ames.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 6f934bb062..424d6ca109 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -45,7 +45,7 @@ c3_w imp_w[256]; // imperial IPs time_t imp_t[256]; // imperial IP timestamps c3_o imp_o[256]; // imperial print status - c3_o nal_d; // lane cache backcompat flag + c3_o nal_o; // lane cache backcompat flag struct { // config: c3_o net_o; // can send c3_o see_o; // can scry @@ -1478,7 +1478,7 @@ _ames_try_send(u3_pact* pac_u, c3_o for_o) // else { u3_noun key = u3i_chubs(2, pac_u->pre_u.rec_d); - lac = _ames_lane_from_cache(sam_u->lax_p, key, sam_u->nal_d); + lac = _ames_lane_from_cache(sam_u->lax_p, key, sam_u->nal_o); } // if we know there's no lane, drop the packet @@ -2282,7 +2282,7 @@ _ames_kick_newt(u3_ames* sam_u, u3_noun tag, u3_noun dat) u3_noun who = u3k(u3h(dat)); u3_noun las = u3k(u3t(dat)); _ames_lane_into_cache(sam_u->lax_p, who, las); - sam_u->nal_d = c3y; + sam_u->nal_o = c3y; ret_o = c3y; } break; } @@ -2466,7 +2466,7 @@ u3_ames_io_init(u3_pier* pir_u) { u3_ames* sam_u = c3_calloc(sizeof(*sam_u)); sam_u->pir_u = pir_u; - sam_u->nal_d = c3n; + sam_u->nal_o = c3n; sam_u->fig_u.net_o = c3y; sam_u->fig_u.see_o = c3y; sam_u->fig_u.fit_o = c3n; From d1a4e34369da41d6584b979fb366d15fe4051d56 Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 6 Nov 2023 19:29:58 +0200 Subject: [PATCH 5/5] ames: fix _ames_lane_from_cache logic to return the head always --- pkg/vere/io/ames.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/vere/io/ames.c b/pkg/vere/io/ames.c index 424d6ca109..e6ca3dbdd6 100644 --- a/pkg/vere/io/ames.c +++ b/pkg/vere/io/ames.c @@ -924,10 +924,19 @@ _ames_lane_into_cache(u3p(u3h_root) lax_p, u3_noun who, u3_noun las) { /* _ames_lane_from_cache(): retrieve lane for who from cache, if any */ static u3_weak -_ames_lane_from_cache(u3p(u3h_root) lax_p, u3_noun who, c3_o nal) { +_ames_lane_from_cache(u3p(u3h_root) lax_p, u3_noun who, c3_o nal_o) { u3_weak lac = u3h_git(lax_p, who); - if (nal == c3n && u3_none != lac ) { + if ( u3_none == lac ) { + u3z(who); + return lac; + } + + if ( nal_o == c3y ) { + lac = u3k(u3h(lac)); + } + + else { struct timeval tim_tv; gettimeofday(&tim_tv, 0); u3_noun now = u3_time_in_tv(&tim_tv);