Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"peer id" reported to tracker isn't used for peer connections #7479

Open
glassez opened this issue Aug 1, 2023 · 15 comments
Open

"peer id" reported to tracker isn't used for peer connections #7479

glassez opened this issue Aug 1, 2023 · 15 comments

Comments

@glassez
Copy link
Contributor

glassez commented Aug 1, 2023

According to The BitTorrent Protocol Specification during handshake peer should use the same peer_id as reported to the tracker:

After the download hash comes the 20-byte peer id which is reported in tracker requests and contained in peer lists in tracker responses. If the receiving side's peer id doesn't match the one the initiating side expects, it severs the connection.

But for some reason libtorrent uses different peer_id for each peer connection. Moreover, judging by the code comment near the "peer id" field of torrent:

// this is the peer id we generate when we add the torrent. Peers won't
// use this (they generate their own peer ids) but this is used in case
// the tracker returns peer IDs, to identify ourself in the peer list to
// avoid connecting back to it.

this was done on purpose, because of "Peers won't use this (they generate their own peer ids)" without any details of why do "peers won't use" the peer id that should be used according to the Specification

@glassez
Copy link
Contributor Author

glassez commented Aug 2, 2023

Related qBittorrent Issue.

@luzpaz
Copy link
Contributor

luzpaz commented Aug 12, 2023

@arvidn would you have a moment to look at this ?

@glassez
Copy link
Contributor Author

glassez commented Aug 24, 2023

@arvidn, welcome back!
Could you take a look at this as a priority?

@ghost
Copy link

ghost commented Aug 25, 2023

If libtorrent employs the same peer_id for all interfaces during communication with other peers, it will result in those peers not establishing connections with all peers originating from the user. This is because many clients consider peers with identical peer_id values as duplicates.

@glassez
Copy link
Contributor Author

glassez commented Aug 25, 2023

If libtorrent employs the same peer_id for all interfaces during communication with other peers, it will result in those peers not establishing connections with all peers originating from the user.

I don't know much about the details, but I think it should be something like the following. Announces through different interfaces use different peer_id. Peer connections associated with some interface must use the same peer_id that was announced to the tracker through this interface.

IMO, in order to support something, it is better to do it at the protocol level (i.e. change/supplement the protocol), and not just violate it.

@SeaHOH
Copy link
Contributor

SeaHOH commented Aug 25, 2023

If libtorrent employs the same peer_id for all interfaces during communication with other peers, it will result in those peers not establishing connections with all peers originating from the user.

This does not only occur on each interfaces, even each ports. I can understand different interfaces imply different peers, maybe one of them has a good connection, but same torrent and same interface MUST report a coherent peer_id.

@ghost
Copy link

ghost commented Aug 26, 2023

If libtorrent employs the same peer_id for all interfaces during communication with other peers, it will result in those peers not establishing connections with all peers originating from the user.

I don't know much about the details, but I think it should be something like the following. Announces through different interfaces use different peer_id. Peer connections associated with some interface must use the same peer_id that was announced to the tracker through this interface.

IMO, in order to support something, it is better to do it at the protocol level (i.e. change/supplement the protocol), and not just violate it.

If announcements employ distinct peer_id values for each interface, it will become challenging for trackers to maintain accurate statistics. This situation is particularly relevant to private trackers. Such behavior might be interpreted as unfair, given that statistics would be calculated per interface and result in multiplication of the recorded data.

@ghost
Copy link

ghost commented Aug 26, 2023

If libtorrent employs the same peer_id for all interfaces during communication with other peers, it will result in those peers not establishing connections with all peers originating from the user.

This does not only occur on each interfaces, even each ports. I can understand different interfaces imply different peers, maybe one of them has a good connection, but same torrent and same interface MUST report a coherent peer_id.

In my opinion, it's entirely logical to assign distinct peer_id values for each port. Consider a scenario where a single interface has both an IPv4 and an IPv6 address. Utilizing the same peer_id for both IP versions could result in peers only connecting via one of the IPs. This might not align with your preferences, especially if one of the IP versions or a combined connection offers better speed.

@SeaHOH
Copy link
Contributor

SeaHOH commented Aug 26, 2023

@Outbid9727 So, you prefer always report a same peer_id to trackers even different torrents, and different peer_ids to all other connections?

PS: my views is "same torrent and same interface MUST report a coherent peer_id", "an IPv4 and an IPv6 address" are different interfaces.

@SeaHOH
Copy link
Contributor

SeaHOH commented Aug 26, 2023

And, I remember private trackers donot use peer_id to identify users.

@SeaHOH
Copy link
Contributor

SeaHOH commented Aug 26, 2023

Sorry, maybe above I wrote was a bit off the point, I means we need to follow the BEPs.

@arvidn
Copy link
Owner

arvidn commented Aug 26, 2023

the peer ID in the bittorrent peer protocol has essentially been useless since its inception. There was a brief window, when trackers would still return peer IDs, where there was a slight use of them, as a poor man's authentication that the peer you're talking to was the same as talked to the tracker. This was removed with compact tracker responses (circa 2008).

Since then, both uTorrent and libtorrent (for well over 10 years by now) have randomized peer_ids to mitigate surveillance of users. This was reported by torrent-freak.

I think a strong justification would be needed to change this.

@SeaHOH
Copy link
Contributor

SeaHOH commented Aug 26, 2023

I forgot a issue, qBittorrent also disconnected a second incoming connection for same peer, even through different IP. Who did this, qBittorrent or libtorrent?

@ghost
Copy link

ghost commented Aug 26, 2023

@Outbid9727 So, you prefer always report a same peer_id to trackers even different torrents, and different peer_ids to all other connections?

No, I prefer the current version. Same peer_id reported for all interfaces/ports on announcement, different peer_id for peer connections.
Also it doesn't matter to the tracker if the peer_id sent to it is different from the peer_id used for peer connections. This is because trackers no longer return peer_ids to clients. Most have resorted to compact lists.

Also it seems like the issue your reported in qbittorrent/qBittorrent#19391 is not due to peer id but because of multiple connections to same IP address being disabled in your settings.
The example you provided where same IP has different ports, those are most likely different peers using the same external IP address.

@SeaHOH
Copy link
Contributor

SeaHOH commented Aug 26, 2023

The example you provided where same IP has different ports, those are most likely different peers using the same external IP address.

Good catch! I did not considered that.
@arvidn How does libtorrent do in the case (accept or reject), or left it to the client code?

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

No branches or pull requests

4 participants