ames: produce (list lane) instead of (unit lane)

Making this change now allows us to more easily supply and handle
multiple lanes in the future.

Updates the runtime to handle these results properly, forwarding to
every lane that was returned in the scry.

Sneaks in some comment cleanup in ames.hoon.
This commit is contained in:
Fang 2020-07-16 01:56:55 +02:00
parent e98742cf8f
commit 6e0a7d009a
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
2 changed files with 21 additions and 15 deletions

View File

@ -702,7 +702,7 @@
==
~
:: /ax/protocol/version @
:: /ax/peers (map ship ?(%alien known))
:: /ax/peers (map ship ?(%alien %known))
:: /ax/peers/[ship] ship-state
:: /ax/peers/[ship]/forward-lane (unit lane)
:: /ax/bones/[ship] [snd=(set bone) rcv=(set bone)]
@ -727,21 +727,19 @@
~ ``noun+!>(u.peer)
::
[%forward-lane ~]
::TODO (list lane) instead?
::TODO refactor wrt +send-blob to share routing logic
:: find lane for u.who, or their galaxy
::
:^ ~ ~ %noun
!> ^- (unit lane)
!> ^- (list lane)
=/ ship-state (~(get by peers.ames-state) u.who)
?. ?=([~ %known *] ship-state)
~
=/ peer-state +.u.ship-state
?. =(~ route.peer-state) ::NOTE avoid tmi
`lane:(need route.peer-state)
|- ^- (unit lane)
[lane:(need route.peer-state)]~
|- ^- (list lane)
?: ?=(%czar (clan:title sponsor.peer-state))
`[%& sponsor.peer-state]
[%& sponsor.peer-state]~
=/ next (~(get by peers.ames-state) sponsor.peer-state)
?. ?=([~ %known *] next)
~

View File

@ -616,18 +616,26 @@ _ames_put_packet(u3_ames* sam_u,
_ames_cap_queue(sam_u);
}
/* _ames_forward(): forward pac_u onto lan, then free pac_u
/* _ames_forward(): forward pac_u onto the (list lane) las, then free pac_u
*/
static void
_ames_forward(u3_panc* pac_u, u3_noun lan)
_ames_forward(u3_panc* pac_u, u3_noun las)
{
pac_u->sam_u->fow_d++;
if ( 0 == (pac_u->sam_u->fow_d % 10000) ) {
u3l_log("ames: forwarded %" PRIu64 " total\n", pac_u->sam_u->fow_d);
}
{
u3_noun pac = _ames_serialize_packet(pac_u, c3y);
while (u3_nul != las) {
_ames_ef_send(pac_u->sam_u, u3h(las), u3k(pac));
las = u3t(las);
}
u3z(pac);
}
pac_u->sam_u->foq_d--;
_ames_ef_send(pac_u->sam_u, lan, _ames_serialize_packet(pac_u, c3y));
_ames_panc_free(pac_u);
}
@ -637,11 +645,11 @@ static void
_ames_lane_scry_cb(void* vod_p, u3_noun nun)
{
u3_panc* pac_u = vod_p;
u3_weak lan = u3r_at(15, nun); //TODO why [~ %noun ~ lane]
u3_weak las = u3r_at(15, nun); //TODO why [~ %noun ~ lane]
// if scry fails, remember we can't scry, and just inject the packet
//
if (u3_none == lan) {
if (u3_none == las) {
pac_u->sam_u->foq_d--;
u3l_log("ames: giving up scry\n");
pac_u->sam_u->see_o = c3n;
@ -652,8 +660,8 @@ _ames_lane_scry_cb(void* vod_p, u3_noun nun)
}
// if there is a lane, forward the packet on it
//
else if (u3_nul != lan) {
_ames_forward(pac_u, u3k(u3t(lan)));
else if (u3_nul != las) {
_ames_forward(pac_u, u3k(las));
}
// if there is no lane, drop the packet
@ -788,7 +796,7 @@ _ames_recv_cb(uv_udp_t* wax_u,
//
if ( (c3y == u3a_is_cat(rec))
&& (256 > rec) ) {
_ames_forward(pac_u, u3nc(c3y, u3k(rec)));
_ames_forward(pac_u, u3nc(u3nc(c3y, u3k(rec)), u3_nul));
}
// otherwise, if there's space in the queue, scry the lane out of ames
//