Skip to content

Allow multiple connections from the same Peer ID - #8215

Merged
arvidn merged 13 commits into
arvidn:RC_2_0from
lzhzh1:allow_multiple_connections_per_pid
Apr 1, 2026
Merged

Allow multiple connections from the same Peer ID#8215
arvidn merged 13 commits into
arvidn:RC_2_0from
lzhzh1:allow_multiple_connections_per_pid

Conversation

@lzhzh1

@lzhzh1 lzhzh1 commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

if the value of settings_pack::allow_multiple_connections_per_ip is true, then skip the check for the same pid
Add a new option allow_multiple_connections_per_pid. When set to true, it skips the duplicate Peer ID check, thereby allowing multiple connections from the same peer.
The issue #8214

@arvidn

arvidn commented Mar 18, 2026

Copy link
Copy Markdown
Owner

if you want to allow multiple connections to the same peer via different IP addresses, I don't think this is the right solution. you would still want to avoid multiple connections to the same IP

@arvidn

arvidn commented Mar 18, 2026

Copy link
Copy Markdown
Owner

Maybe it's OK to accept multiple connections to the same peer as long as they use different address families. But you could also have multiple routes to the internet. But the common case is (most likely) that you don't want to have multiple connections to the same peer.

@lzhzh1

lzhzh1 commented Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

Maybe it's OK to accept multiple connections to the same peer as long as they use different address families. But you could also have multiple routes to the internet. But the common case is (most likely) that you don't want to have multiple connections to the same peer.

Thank you so much for your comments! I've introduced a new option, allow_multiple_connections_per_pid, to toggle the duplicate Peer ID check, which ensures other functionalities remain unaffected.

Since I'm still a beginner, I haven't been able to create a proper standalone test file yet. However, I've manually verified the logic by compiling my forked libtorrent and a simply modified version of qBittorrent to control the value of allow_multiple_connections_per_pid. It seems to be working as expected. Thanks again!"

allow_multiple_connections_per_pid = true
allow_multiple_connections_per_pid_true
allow_multiple_connections_per_pid = false
(The result of manually forcing Tixati to disconnect established connections and then retry the connection)
allow_multiple_connections_per_pid_false

Comment thread src/bt_peer_connection.cpp
Comment thread test/settings.cpp Outdated
Comment thread test/setup_transfer.cpp Outdated
Comment thread test/swarm_suite.cpp Outdated
@lzhzh1
lzhzh1 marked this pull request as draft March 24, 2026 17:27
@lzhzh1

lzhzh1 commented Mar 28, 2026

Copy link
Copy Markdown
Contributor Author

My apologies for the initial misunderstanding regarding the test files, which led me to place allow_multiple_connections_per_pid alongside allow_multiple_connections_per_ip. I have now added a new dedicated test file libtorrent/simulation/test_allow_multiple_connections_per_pid.cpp for it. I would appreciate any further feedback or suggestions you may have. Thank you!

root@hello-world:~/libtorrent/simulation# b2 test_allow_multiple_connections_per_pid
CXXFLAGS =
LDFLAGS =
OS = LINUX
BOOST_ROOT =
OS = LINUX
warning: No toolsets are configured.
warning: Configuring default toolset "gcc".
warning: If the default is wrong, your build may not work correctly.
warning: Use the "toolset=xxxxx" option to override our guess.
warning: For more configuration options, please consult
warning: https://www.bfgroup.xyz/b2/manual/release/index.html#bbv2.overview.configuration
warning: non-free usage requirements <threading>multi ignored
warning: in main-target simulator at libsimulator/Jamfile:105
...patience...
...found 2238 targets...
...updating 22 targets...
gcc.compile.c++ bin/test_allow_multiple_connections_per_pid.test/gcc-14/debug/asserts-on/crypto-built-in/cxxstd-14-iso/export-extra-on/invariant-checks-full/picker-debugging-on/simulator-on/threading-multi/test_allow_multiple_connections_per_pid.o
gcc.compile.c++ bin/test_allow_multiple_connections_per_pid.test/gcc-14/debug/asserts-on/crypto-built-in/cxxstd-14-iso/export-extra-on/invariant-checks-full/picker-debugging-on/simulator-on/threading-multi/create_torrent.o
gcc.compile.c++ bin/test_allow_multiple_connections_per_pid.test/gcc-14/debug/asserts-on/crypto-built-in/cxxstd-14-iso/export-extra-on/invariant-checks-full/picker-debugging-on/simulator-on/threading-multi/disk_io.o
gcc.compile.c++ bin/test_allow_multiple_connections_per_pid.test/gcc-14/debug/asserts-on/crypto-built-in/cxxstd-14-iso/export-extra-on/invariant-checks-full/picker-debugging-on/simulator-on/threading-multi/setup_dht.o
gcc.compile.c++ bin/test_allow_multiple_connections_per_pid.test/gcc-14/debug/asserts-on/crypto-built-in/cxxstd-14-iso/export-extra-on/invariant-checks-full/picker-debugging-on/simulator-on/threading-multi/setup_swarm.o
gcc.compile.c++ bin/test_allow_multiple_connections_per_pid.test/gcc-14/debug/asserts-on/crypto-built-in/cxxstd-14-iso/export-extra-on/invariant-checks-full/picker-debugging-on/simulator-on/threading-multi/transfer_sim.o
gcc.compile.c++ bin/test_allow_multiple_connections_per_pid.test/gcc-14/debug/asserts-on/crypto-built-in/cxxstd-14-iso/export-extra-on/invariant-checks-full/picker-debugging-on/simulator-on/threading-multi/utils.o
gcc.link bin/test_allow_multiple_connections_per_pid.test/gcc-14/debug/asserts-on/crypto-built-in/cxxstd-14-iso/export-extra-on/invariant-checks-full/picker-debugging-on/simulator-on/threading-multi/test_allow_multiple_connections_per_pid
testing.capture-output bin/test_allow_multiple_connections_per_pid.test/gcc-14/debug/asserts-on/crypto-built-in/cxxstd-14-iso/export-extra-on/invariant-checks-full/picker-debugging-on/simulator-on/threading-multi/test_allow_multiple_connections_per_pid.run
**passed** bin/test_allow_multiple_connections_per_pid.test/gcc-14/debug/asserts-on/crypto-built-in/cxxstd-14-iso/export-extra-on/invariant-checks-full/picker-debugging-on/simulator-on/threading-multi/test_allow_multiple_connections_per_pid.test
...updated 22 targets...

@lzhzh1
lzhzh1 marked this pull request as ready for review March 28, 2026 05:09
Comment thread simulation/test_allow_multiple_connections_per_pid.cpp Outdated
Comment thread include/libtorrent/peer_list.hpp Outdated
@lzhzh1

lzhzh1 commented Mar 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for your review! I removed the unnecessary code and merged the test code.

@arvidn
arvidn merged commit b9a4a53 into arvidn:RC_2_0 Apr 1, 2026
51 checks passed
@lzhzh1
lzhzh1 deleted the allow_multiple_connections_per_pid branch April 2, 2026 04:40
// a peer has multiple IP addresses, enabling this feature
// may improve transfer efficiency, but it may also
// increase network load.
allow_multiple_connections_per_pid,

@milahu milahu May 12, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: this should be renamed

-allow_multiple_connections_per_pid
+allow_multiple_connections_per_peer_id

-simulation/test_allow_multiple_connections_per_pid.cpp
+simulation/test_allow_multiple_connections_per_peer_id.cpp

to make it consistent with the rest of the codebase

fixed in #8373

@Rootax

Rootax commented Jun 20, 2026

Copy link
Copy Markdown

Was this merged into 2.1 rc2 ?

@lzhzh1

lzhzh1 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

Was this merged into 2.1 rc2 ?

Yes!

@Rootax

Rootax commented Jun 20, 2026

Copy link
Copy Markdown

Was this merged into 2.1 rc2 ?

Yes!

Thx, I was not sure. it seems qbittorrent master doesn't expose de setting in the gui yet.

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.

4 participants