Repository navigation
Conversation
… only_i2p_peers flag on torrents, to explicitly allow/disallow non i2p peers per torrent
There was a problem hiding this comment.
Pull request overview
This PR refactors I2P torrent handling by introducing a per-torrent torrent_flags::only_i2p_peers restriction flag and moving behavior checks from a global “mixed mode” setting to this per-torrent state (with backward compatibility for TORRENT_ABI_VERSION < 4). It also updates resume data, magnet parsing, and torrent loading to “fail closed” by default for I2P torrents.
Changes:
- Add and propagate
torrent_flags::only_i2p_peersthrough torrent lifecycle (load, magnet, resume, runtime updates). - Deprecate/alias legacy
i2p_torrenthandling viadeprecated_i2p_torrentand keepallow_i2p_mixedonly for ABI < 4 with a session callback to reconcile existing torrents. - Update tests and tooling/docs scripts to reflect the new flag and deprecation plumbing.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/test_torrent.cpp | Adds ABI<4 regression test covering allow_i2p_mixed reconciliation with only_i2p_peers. |
| test/test_resume.cpp | Adds resume migration test for only_i2p_peers; updates legacy I2P flag references. |
| test/test_read_resume.cpp | Updates flag masks to use deprecated_i2p_torrent. |
| test/test_magnet.cpp | Asserts .i2p trackers set both deprecated_i2p_torrent and only_i2p_peers. |
| src/write_resume_data.cpp | Serializes only_i2p_peers into resume data. |
| src/ut_pex.cpp | Disables uTP PEX for i2p-only torrents via only_i2p_peers(). |
| src/torrent.cpp | Introduces m_only_i2p_peers state; switches multiple behaviors to gate on i2p-only torrents; adds compatibility shim in set_flags(). |
| src/torrent_info.cpp | Marks torrent_info as I2P based on deprecated_i2p_torrent. |
| src/settings_pack.cpp | Introduces DEPRECATED4_SET and wires allow_i2p_mixed to a session update callback (ABI<4). |
| src/session_impl.cpp | Implements update_allow_i2p_mixed() and uses only_i2p_peers() for LSD peer add gating. |
| src/read_resume_data.cpp | Reads/writes deprecated_i2p_torrent and migrates missing only_i2p_peers by failing closed. |
| src/peer_connection.cpp | Disconnects non-I2P peers when torrent is i2p-only. |
| src/magnet_uri.cpp | Sets i2p-only on .i2p tracker detection (fail closed). |
| src/load_torrent.cpp | Sets i2p-only on .i2p tracker detection (fail closed). |
| include/libtorrent/torrent_flags.hpp | Deprecates i2p_torrent (ABI<4), adds deprecated_i2p_torrent alias and new only_i2p_peers flag. |
| include/libtorrent/settings_pack.hpp | Deprecates allow_i2p_mixed for ABI<4 and hides it for ABI>=4. |
| include/libtorrent/aux_/torrent.hpp | Adds only_i2p_peers() accessor and stores m_only_i2p_peers bit. |
| include/libtorrent/aux_/session_impl.hpp | Declares update_allow_i2p_mixed(). |
| docs/gen_settings_doc.py | Extends ABI skip handling and strips TORRENT_DEPRECATED_ENUM markers. |
| bindings/c/src/settings.cpp | Regenerates C settings mapping without SET_ALLOW_I2P_MIXED. |
| bindings/c/include/libtorrent_settings.h | Regenerates C settings tags without SET_ALLOW_I2P_MIXED. |
| .pre-commit-config.yaml | Adjusts git-clang-format hook to receive filenames and excludes generated sources. |
| .clang-format-ignore | Adds ignore list for generated files for editor/direct clang-format runs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| line = line.strip() | ||
| if line.endswith(","): | ||
| line = line[:-1] # strip trailing comma | ||
| if "=" in line: | ||
| line = line.split("=")[0].strip() | ||
| # strip a trailing deprecation marker, e.g. "name TORRENT_DEPRECATED_ENUM" | ||
| if line.endswith("TORRENT_DEPRECATED_ENUM"): | ||
| line = line[: -len("TORRENT_DEPRECATED_ENUM")].strip() |
| DEPRECATED_SET(ignore_limits_on_local_network, | ||
| true, | ||
| &session_impl::update_ignore_rate_limits_on_local_network), |
| { | ||
| m_only_i2p_peers = bool(flags & torrent_flags::only_i2p_peers); |
| if (mask & torrent_flags::deprecated_i2p_torrent) | ||
| { | ||
| m_i2p = bool(flags & torrent_flags::i2p_torrent); | ||
| bool const new_i2p = bool(flags & torrent_flags::deprecated_i2p_torrent); | ||
| m_i2p = new_i2p; | ||
| // backward compatibility: toggling the i2p_torrent flag also |
|
It would be great if these changes could still make it into 2.1.x, if you think that’s feasible. I understand you mentioned that this might be better targeted at master, though. |
It seems that this goes against users’ expectations regarding the use of I2P. Rather, they may or may not need to prohibit regular peers when using I2P. |
|
@glassez, do you mean two modes for I2P torrents: Mixed Mode, where both I2P and regular peers are allowed through the I2P network, and I2P-only mode, where only I2P peers are allowed to connect through the I2P network? If so, that does indeed seem like a more correct approach. |
perhaps this is better targeting
master.The idea is to simplify the control of i2p torrents with a single flag
allow_i2p_peers, instead of theallow_i2p_mixedsettings and thei2p_torrentflag.