i2p: pass base32 address directly to stream connect

bitcoin/bitcoin: PR #36570

1 suggestion

Optional improvements

Link

[suggestion] · Connect tests omit proxy-error STREAM replies

The new Connect test would still pass if router-error replies incorrectly cleared proxy_error, leaving the boundary that gates AddrMan attempt recording unprotected.

Location: src/test/i2p_tests.cpp:238 (head).

Details and suggested fix

The fixture supplies only CANT_REACH_PEER, TIMEOUT and OK. Adding INVALID_KEY to the peer-failure branch would leave these assertions passing, but would make CConnman record an AddrMan attempt for that router error. Add INVALID_KEY and I2P_ERROR cases with proxy_error initially false, then assert that Connect returns false and resets the flag to true. Keep check_sent() and update the final socket-count expectation.

To cover a missing RESULT as well, make the mocked reply line configurable and supply STREAM STATUS\n. An empty stream_connect_result currently produces RESULT=, which parses as a present empty value rather than a missing field.


Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

Peer connection failures should be recorded to avoid retrying the same address too soon, but failure to connect to a proxy should not affect the status of individual peers.

This distinction predates I2P support. In both pinned versions, CConnman calls AddrMan::Attempt only when proxyConnectionFailed is false. Session::Connect preserves that distinction by treating CANT_REACH_PEER and TIMEOUT as peer failures, while initially classifying failures as proxy errors. Changing the command path matters because it changes which replies reach that existing classification.

Source 1

Failure accounting must avoid destroying useful address history during local connectivity outages, while still limiting wasteful retries.

The historical offline-attempt proposal warned that repeated failures while offline could effectively erase AddrMan state. It distinguished retry timing from failure penalties and acknowledged that apparent connectivity is only an imperfect heuristic. This explains why the pinned caller has both a proxy-failure gate and a separate fCountFailure argument: recording an attempt is not identical to unconditionally increasing a peer’s failure penalty.

Source 1 · Source 2

SAM replies are an untrusted interface: missing required fields must be handled safely, and even malicious router replies are within the defensive assumptions.

During the original I2P integration, a question about a missing VALUE field was answered by pointing to handled exceptions; the author separately stated that arbitrary, including malicious, proxy replies should be expected. The pinned base applies this boundary to the lookup’s VALUE and RESULT fields. The head removes that lookup but retains required-field parsing and exception handling for STREAM CONNECT.

Source 1 · Source 2 · Source 3

Ralph's inferences

The separate lookup is best understood as part of the Bitcoin-to-router connection interface, rather than a Bitcoin consensus or peer-discovery requirement.

The original integration described implementing only the SAM operations needed for outbound and inbound connections. In the pinned base, Bitcoin already has the peer’s .b32.i2p address and asks the router for a VALUE to pass to STREAM CONNECT. The head instead passes that same peer address directly. Thus the affected boundary is how connection establishment is requested from the router, not how Bitcoin chooses or identifies the target peer.

Source 1

Removing the explicit lookup has two distinct system-level implications: fewer client/router exchanges and a different point at which failure information enters peer accounting.

The pinned base performs a lookup request/reply before STREAM CONNECT; the head omits that exchange. Separately, the unchanged caller uses the resulting proxy-error classification to decide whether to record an AddrMan attempt. The historical rationale supports examining these as latency and evidence-attribution concerns, not treating every failed router operation as evidence against a peer. It does not establish that underlying I2P resolution work disappears or that all router versions return identical errors.

Source 1 · Source 2 · Source 3