Skip to content

i2p: request post-quantum leasesets (6,4) and retry once with 4,0 on explicit rejection (#184 part 1) #185

Closed

Description

@djh58

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) send i2cp.leaseSetEncType=4,0 today.
  • 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) uses nConnectTimeout and does not watch the SAM interrupt, so a retry built only on SendRequestAndGetReply would not be bounded or interruptible.
  • src/i2p.cpp:323 builds its exception text from the raw request, which for SESSION CREATE contains the private key, even though a sanitized copy exists at :302.
  • Transient sessions are separate Session objects (src/net.cpp:473-491), so a rejection remembered inside one Session would not help the next one.

Scope

  • Send i2cp.leaseSetEncType=6,4 for persistent and transient sessions.
  • Retry trigger. Only a syntactically valid SESSION STATUS reply whose RESULT is present and is not OK, other than DUPLICATED_ID, DUPLICATED_DEST, INVALID_ID or INVALID_KEY: those cannot be about the encryption type, and fail as they do today. A SAM RESULT=TIMEOUT reply is a rejection and is retried. No reply (a timeout waiting for the router, EOF, a socket error), a malformed reply, a missing RESULT or 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 send SESSION CREATE once more with 4,0. Commit m_session_id and m_control_sock only after success.
  • One deadline. A single 180-second creation deadline covers connect, HELLO, optional DEST GENERATE and both CREATE attempts. Each connect is also capped by -timeout, whichever is shorter. Add a deadline-and-interrupt overload of Proxy::Connect that 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,4 rejected naming the encryption type, 4,0 accepted" observations for the same router. A rejection names the encryption type when its MESSAGE contains crypto type, encryption type, enc type or enctype (ASCII case-insensitive, matched before sanitizing), as Java I2P 2.9.x's Unsupported crypto type: 6 does. Any other rejection is still retried, but neither counts nor resets the streak, and logs one info line saying the next session asks for 6,4 again; a successful 6,4 session 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 with 4,0. If a retry fails too, nothing is counted, and the next creation tries 6,4 again.
  • Logging. Log each rejection at debug level in the i2p category, with RESULT and a sanitized, length-capped MESSAGE. At the first "6,4 rejected naming the encryption type, 4,0 accepted" 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 SAM RESULT token, otherwise other. The docs say to restart qbit after upgrading the router.
  • Never put the private-key-bearing request into an exception or log line; fix :323 to use the sanitized request.
  • A code comment marks the retry as qbit-only (upstream Core has no retry).
  • Docs: doc/user/network/i2p.md states the router requirement and the retry; add a release-note fragment doc/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 with 4,0; one warning) and against i2pd (accepts 6,4). Evidence on the PR.
  • i2p.md and 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

  1. added
    enhancement
    pq-transport
    on Oct 5, 2026
  2. changed the title [-]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)[/+] on Oct 5, 2026
  3. djh58 commented on Oct 23, 2026

    @djh58
    MemberAuthor

    Done in #223, merged into feature/pq-transport as 152117a. It reaches 1.1.0 with #233 and ships in 1.1.0.

  4. added a commit that references this issue on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpq-transport

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions