Skip to content

Re-resolve the right swarm after a 421 - #126

Open
jagerman wants to merge 1 commit into
session-foundation:devfrom
jagerman:reresolve-swarm-after-421
Open

Re-resolve the right swarm after a 421#126
jagerman wants to merge 1 commit into
session-foundation:devfrom
jagerman:reresolve-swarm-after-421

Conversation

@jagerman

@jagerman jagerman commented Aug 8, 2026

Copy link
Copy Markdown
Member

_handle_421_retry re-resolved the swarm using service_node::swarm_pubkey(), which returns compute_x25519_pubkey(remote_pubkey) -- the failing node's own X25519 key, not the account the request was about. So a misdirected request was retried against a swarm chosen by hashing the pubkey of the node that had just rejected it: an unrelated swarm, giving another 421 and then the retry limit. Recovering needs the swarm of the account, which may have moved.

Request now records the account whose swarm it addresses, and the retry re-resolves that. A request with no swarm recorded -- a snode cache refresh, a clock resync, anything aimed at a node rather than about an account -- is not redirected at all, rather than being sent somewhere arbitrary. session_request_params gains a swarm_pubkey_hex field (appended, so a caller that doesn't set it behaves as before).

service_node::swarm_pubkey() is removed rather than corrected: it had a single caller and the name invited exactly this mistake (it reads as "the swarm this node is in" while computing the node's own key). compute_x25519_pubkey() stays.

Adapted from pfs commit e5a93a8. On this branch the account-addressed sends originate above libsession and arrive through the C session_network_send_request (hence the swarm_pubkey_hex param); the only internal swarm sends -- the clock resync and snode-pool refreshes -- are node-directed and correctly leave swarm_pubkey unset.

_handle_421_retry re-resolved the swarm using service_node::swarm_pubkey(),
which returns compute_x25519_pubkey(remote_pubkey) -- the failing *node's
own* X25519 key, not the account the request was about. So a misdirected
request was retried against a swarm chosen by hashing the pubkey of the
node that had just rejected it: an unrelated swarm, giving another 421 and
then the retry limit. Recovering needs the swarm of the *account*, which
may have moved.

Request now records the account whose swarm it addresses, and the retry
re-resolves that. A request with no swarm recorded -- a snode cache
refresh, a clock resync, anything aimed at a node rather than about an
account -- is not redirected at all, rather than being sent somewhere
arbitrary. session_request_params gains a swarm_pubkey_hex field (appended,
so a caller that doesn't set it behaves as before).

service_node::swarm_pubkey() is removed rather than corrected: it had a
single caller and the name invited exactly this mistake (it reads as "the
swarm this node is in" while computing the node's own key).
compute_x25519_pubkey() stays.

Adapted from pfs commit e5a93a8. On this branch the account-addressed
sends originate above libsession and arrive through the C
session_network_send_request (hence the swarm_pubkey_hex param); the only
internal swarm sends -- the clock resync and snode-pool refreshes -- are
node-directed and correctly leave swarm_pubkey unset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant