Repository navigation
Description
Part 1 of 9 · #184 · Size M · Base 1.x.x · Needs nothing: can start now
Can start now. It doesn't depend on the rest of #184 and isn't gated by its release gate, so it can ship in any release.
Goal
Backport Bitcoin Core #35696, which asks the I2P router for the post-quantum hybrid leaseset encryption type (i2cp.leaseSetEncType=6,4 instead of 4,0), and add one qbit-specific safety net: if the router explicitly rejects 6,4, retry once with 4,0 so I2P keeps working on older routers.
This is the I2P side of the post-quantum work. It has no dependency on the rest of #184 and is not gated by its release gate.
Context
src/i2p.cpp:428(transient sessions) and:446(persistent sessions) sendi2cp.leaseSetEncType=4,0today.- Router support, as the I2P developers stated on Core #35696:
- Java I2P older than 2.10.0 rejects the new type and fails the SAM session;
- i2pd of any version ignores unknown types and keeps working;
- Java I2P 2.10.0 or newer, and i2pd 2.58.0 or newer built with OpenSSL 3.5 or newer, use the post-quantum type.
- Each SAM request gets its own 3-minute receive timeout (
src/i2p.cpp:308).Proxy::Connect(src/netbase.cpp:672) usesnConnectTimeoutand does not watch the SAM interrupt, so a retry built only onSendRequestAndGetReplywould not be bounded or interruptible. src/i2p.cpp:323builds its exception text from the raw request, which forSESSION CREATEcontains the private key, even though a sanitized copy exists at:302.- Transient sessions are separate
Sessionobjects (src/net.cpp:473-491), so a rejection remembered inside oneSessionwould not help the next one.
Scope
- Send
i2cp.leaseSetEncType=6,4for persistent and transient sessions. - Retry trigger. Only a syntactically valid
SESSION STATUSreply whoseRESULTis present and is notOK, other thanDUPLICATED_ID,DUPLICATED_DEST,INVALID_IDorINVALID_KEY: those cannot be about the encryption type, and fail as they do today. A SAMRESULT=TIMEOUTreply is a rejection and is retried. No reply (a timeout waiting for the router, EOF, a socket error), a malformed reply, a missingRESULTor a lost success reply never triggers the retry. - Retry procedure. Close that control socket, connect again, send a fresh
HELLO, generate a new session id, keep the persistent destination key, and sendSESSION CREATEonce more with4,0. Commitm_session_idandm_control_sockonly after success. - One deadline. A single 180-second creation deadline covers connect,
HELLO, optionalDEST GENERATEand bothCREATEattempts. Each connect is also capped by-timeout, whichever is shorter. Add a deadline-and-interrupt overload ofProxy::Connectthat polls in slices of at most 100 ms, so shutdown interrupts promptly. Existing overloads and behavior for other SAM requests stay as they are.// src/i2p.h using SAMDeadline = std::chrono::steady_clock::time_point; static constexpr auto SAM_CREATE_TIMEOUT = std::chrono::seconds{180}; static constexpr unsigned SAM_CREATE_MAX_ATTEMPTS = 2; // Session, private: std::unique_ptr<Sock> Hello(SAMDeadline deadline) const; Reply SendRequestAndGetReply(const Sock& sock, const std::string& request, bool check_result_ok, SAMDeadline deadline) const;
- Remember the rejection only after two consecutive "
6,4rejected naming the encryption type,4,0accepted" observations for the same router. A rejection names the encryption type when itsMESSAGEcontainscrypto type,encryption type,enc typeorenctype(ASCII case-insensitive, matched before sanitizing), as Java I2P 2.9.x'sUnsupported crypto type: 6does. Any other rejection is still retried, but neither counts nor resets the streak, and logs one info line saying the next session asks for6,4again; a successful6,4session resets that router's streak. One transient router error must never turn post-quantum off until restart. Keep it for the process lifetime (until qbit restarts) in a mutex-protected, bounded map keyed by the SAM router (its TCP endpoint or Unix socket path), so later transient sessions through that router start with4,0. If a retry fails too, nothing is counted, and the next creation tries6,4again. - Logging. Log each rejection at debug level in the
i2pcategory, withRESULTand a sanitized, length-cappedMESSAGE. At the first "6,4rejected naming the encryption type,4,0accepted" observation for a router, log once per process at warning level:
I2P: the router rejected leaseSetEncType=6,4 (RESULT=<code>) and accepted 4,0, so this session has no post-quantum leaseset. Java I2P older than 2.10.0 does this; upgrade the router to get it.
<code>is printed only when it is a SAMRESULTtoken, otherwiseother. The docs say to restart qbit after upgrading the router. - Never put the private-key-bearing request into an exception or log line; fix
:323to use the sanitized request. - A code comment marks the retry as qbit-only (upstream Core has no retry).
- Docs:
doc/user/network/i2p.mdstates the router requirement and the retry; add a release-note fragmentdoc/release-notes-<PR number>.md.
Tests
src/test/i2p_tests.cpp, with a recording mock SAM router:
| Test | Setup | Expect |
|---|---|---|
hybrid_create_success |
Persistent and transient sessions | CREATE carries 6,4; one socket and session; no warning |
hybrid_rejection_retry |
First CREATE gets an explicit non-OK naming the encryption type, second OK |
Fresh socket, HELLO and session id; second CREATE uses 4,0; persistent key unchanged; one warning |
hybrid_rejection_cached |
Another transient session through the same router | Starts directly with 4,0, no second warning; a different router is unaffected |
hybrid_unrelated_rejection |
CREATE with 6,4 gets DUPLICATED_ID |
No retry and no cache entry |
hybrid_retry_also_fails |
6,4 gets I2P_ERROR, and the 4,0 retry fails too |
No cache entry and no warning; the next session tries 6,4 again |
hybrid_two_strike_cache |
One transient rejection then a 6,4 success; then two consecutive rejections naming the encryption type with 4,0 accepted |
The first does not cache and the success resets the streak; the pair caches; one warning per router |
hybrid_unnamed_rejection_neutral |
6,4 rejected without naming the encryption type (tunnel failure, RESULT=TIMEOUT, CANT_REACH_PEER, no MESSAGE), 4,0 accepted; also between two named rejections |
Retried each time; no count, no reset, no warning; one info line; the next session asks for 6,4 again; named, unnamed, named still caches |
hybrid_no_retry_on_transport_failure |
Send failure, EOF, malformed reply, missing RESULT, lost success reply |
No retry and no cache entry |
hybrid_retry_deadline_and_interrupt |
Interrupt during reconnect, HELLO and CREATE; exhaust the deadline |
Prompt exit, sockets released, no half-published session |
Plus src/test/netbase_tests.cpp cases for the deadline-and-interrupt connect.
Acceptance criteria
- The tests above pass and the existing I2P tests are unchanged.
- Checked by hand against a real Java I2P 2.9.x router (rejects
6,4; the retry connects with4,0; one warning) and against i2pd (accepts6,4). Evidence on the PR. -
i2p.mdand the release note describe the router requirement and the retry. - The PR states the rollback: a point release that restores
4,0.
Suggested commits: net: support bounded interruptible SAM session creation; i2p: prefer hybrid leasesets and retry explicit router rejection once; doc: document I2P hybrid router requirements and compatibility retry.
One pull request against 1.x.x closes this issue. The shared contract is the Design section of #184; change it there first if needed.
Activity
[-]i2p: request post-quantum leasesets (6,4) and retry once with 4,0 on explicit rejection (#184 A1)[/-][+]i2p: request post-quantum leasesets (6,4) and retry once with 4,0 on explicit rejection (#184 part 1)[/+]doc: document I2P hybrid router requirements and compatibility retry
i2p: prefer hybrid leasesets and retry explicit router rejection once
doc: document I2P hybrid router requirements and compatibility retry
i2p: request post-quantum leasesets (6,4) and retry once with 4,0 on …
djh58 commentedon Oct 23, 2026
Done in #223, merged into
feature/pq-transportas 152117a. It reaches1.1.0with #233 and ships in 1.1.0.Hybrid post-quantum v2 transport (#184) — integration (#233)