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

Implement Peer ID Client column for Peers tab #17940

Merged
merged 10 commits into from
Nov 6, 2022
Merged

Implement Peer ID Client column for Peers tab #17940

merged 10 commits into from
Nov 6, 2022

Conversation

HanabishiRecca
Copy link
Contributor

@HanabishiRecca HanabishiRecca commented Oct 25, 2022

It is a fairly useful feature. Implemented both for desktop and WebUI.

Originally introduced in qBittorrent Enhanced Edition, initial source is ported from there.

Screenshot

peer-column-webui

@Chocobo1
Copy link
Member

It is a fairly useful feature.

Please elaborate.

@HanabishiRecca
Copy link
Contributor Author

HanabishiRecca commented Oct 26, 2022

Please elaborate.

Well, it's just "more info is better". Clients can omit user-agent (Client column contains Unknown in this case) or fake it. But peer id is always present, as far as I'm concerned. Of course technically it can be faked too, but still better than nothing.

And I don't see reasons for not having it. Columns are customizable and can be hidden for those who don't want to see em.

@Chocobo1
Copy link
Member

Please elaborate.

Well, it's just "more info is better".

This does not correlate with what you said in the opening post: "It is a fairly useful feature".
It doesn't even have a real world use case associated. Sounds like false advertising to me.

But peer id is always present, as far as I'm concerned.

IIRC Client column is parsed from peer_id. So effectively these 2 columns point to the same data but different representation.

While I don't strongly oppose this PR, I'm not going to back it up either.

@HanabishiRecca
Copy link
Contributor Author

HanabishiRecca commented Oct 29, 2022

So effectively these 2 columns point to the same data but different representation.

I'm not really sure. Libtorrent does resolve some clients this way:
https://github.com/arvidn/libtorrent/blob/64817e0e8793d0875fc10245de52ffb2540a223d/src/identify_client.cpp#L146

But I clearly can see clients that are not on the list:

screenshot

And peer ids here obviously can not represent such precise build numbers (like 5.26.13983).
But maybe I got it wrong and this PR is actually useless. Definitely need @arvidn help here.

@ghost
Copy link

ghost commented Oct 29, 2022

Client column is the advertised user agent while the peer_id is completely different thing. Peer id of two clients will not match(in small swarms) but user agents could be same. I guess the peer_id shown here is truncated as the actual peer_id is 20 bytes. Here only the non random bytes are being displayed.

@HanabishiRecca
Copy link
Contributor Author

HanabishiRecca commented Oct 29, 2022

Yeah. In fact even on my initial screenshot you can see a bunch of UW peers advertised themselfs as libtorrent/1.2.2.0, which is not very informative. But looking up by the peer id you can identify it as µTorrent Web + see the actual client version.
More comperhensive list can be found e.g. here.

@Chocobo1
Copy link
Member

Chocobo1 commented Oct 29, 2022

Client column is the advertised user agent while the peer_id is completely different thing.

Seems you are right on this. Here is the spec: https://www.bittorrent.org/beps/bep_0010.html
And interestingly from that spec:

v Client name and version (as a utf-8 string). This is a much more reliable way of identifying the client than relying on the peer id encoding.

So if the peer doesn't support this Extension Protocol then Client field will be determined from peer_id.
When peer support Extension Protocol: https://github.com/arvidn/libtorrent/blob/550d3c7d9faeb3c59584b16fd0fc90a05e047ce5/src/bt_peer_connection.cpp#L2037
When it doesn't: https://github.com/arvidn/libtorrent/blob/550d3c7d9faeb3c59584b16fd0fc90a05e047ce5/src/bt_peer_connection.cpp#L3533

@arvidn
Copy link
Contributor

arvidn commented Oct 29, 2022

I'll make a bunch of statements, and maybe some questions will be answered.

The peer_id is just a unique identifier to avoid multiple connections to the same peer, as well as avoiding connecting to oneself.
Very early on, clients started advertising themselves and their version, as a prefix to the peer_id, and the mainline (BitTorrent Inc.) client followed suit.

The peer_id, as it was originally intended (I believe), ended up not being very useful. You can't trust peers to use the same peer ID if they open multiple connections to you, so it's primarily helpful in identifying connections to yourself. The one other (subtle) use is if two clients connect to each other at the same time, the peer ID is used to determine which connection to disconnect and which one to keep. Both clients need to agree on this, otherwise they might also decide to close both connections (one each).

There are 4 places where a bittorrent client advertises a "user agent".

  1. The actual UserAgent field in the HTTP tracker request. Advertised to trackers.
  2. The peer ID field in the peer handshake. Advertised to other peers.
  3. The version field in the peer extension handshake. Advertised to other peers.
  4. The version field in DHT messages. Advertised to other DHT nodes.

I believe only (2) and maybe (3) is relevant for this ticket.

Presumably, in the screenshot above, where the Client column disagrees with the PeerID column, the peer advertised a different version than its peer_id suggested (e.g. peer ID UW and client version: libtorrent/2.2.0).

@HanabishiRecca HanabishiRecca marked this pull request as draft October 29, 2022 15:54
@HanabishiRecca
Copy link
Contributor Author

Changes:

  1. Sanitize peer id to only printable ASCII characters.
  2. Return full string (arguable).

image

@HanabishiRecca
Copy link
Contributor Author

Now I see a few possible ways:

  1. Keep showing the full string. Usefulness of the random part is questionable.
  2. Trim to 8 chars unconditionally. Kinda works 99% of the time.
  3. Trim to 8 chars if printable else show the full string. But do we really want to see it?
  4. Trim to 8 chars if printable else show nothing. Very high chance to show only sensible data and hide random noise. Sounds best to me.
  5. Implement some more complicated parsing. But there is not much real cases when it can be useful. Also natural randomness can still interfere.

Will be good to hear more thoughts about it.

@glassez
Copy link
Member

glassez commented Oct 30, 2022

4. Trim to 8 chars if printable else show nothing. Very high chance to show only sensible data and hide random noise. Sounds best to me.

In case it is really needed I would prefer this option. Also I would show some placeholder in case of non printable id.

@HanabishiRecca
Copy link
Contributor Author

Ok, will stick with this variant for now.

@HanabishiRecca HanabishiRecca marked this pull request as ready for review October 30, 2022 11:01
@ghost
Copy link

ghost commented Oct 30, 2022

I think this column should be hidden by default.

@HanabishiRecca
Copy link
Contributor Author

I think this column should be hidden by default.

Agree. But I can't figure out how to do it for desktop UI.
Easy for WebUI though, it has a dedicated column flag for that.

@HanabishiRecca
Copy link
Contributor Author

Nvm, I made it.

src/gui/properties/peerlistwidget.cpp Show resolved Hide resolved
src/base/bittorrent/peerinfo.cpp Outdated Show resolved Hide resolved
src/base/bittorrent/peerinfo.cpp Outdated Show resolved Hide resolved
`Peer ID` -> `Peer ID Client`
@Chocobo1 Chocobo1 added WebUI WebUI-related issues/changes GUI GUI-related issues/changes labels Nov 4, 2022
@Chocobo1
Copy link
Member

Chocobo1 commented Nov 4, 2022

@HanabishiRecca
You should also increment the PATCH version number of API_VERSION in webapplication.h.

@Chocobo1 Chocobo1 added this to the 5.0 milestone Nov 4, 2022
Copy link
Member

@Chocobo1 Chocobo1 left a comment

Choose a reason for hiding this comment

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

LGTM

@HanabishiRecca
Copy link
Contributor Author

Current state, just in case:

image

@Chocobo1 Chocobo1 merged commit 6a56001 into qbittorrent:master Nov 6, 2022
@Chocobo1 Chocobo1 changed the title Implement Peer ID column for Peers tab Implement Peer ID Client column for Peers tab Nov 6, 2022
@Chocobo1
Copy link
Member

Chocobo1 commented Nov 6, 2022

@HanabishiRecca
Thank you!

@HanabishiRecca HanabishiRecca deleted the peer-id-column branch November 6, 2022 04:46
@Chocobo1 Chocobo1 modified the milestones: 5.0, 4.6.0 Nov 8, 2022
sledgehammer999 pushed a commit to sledgehammer999/qBittorrent that referenced this pull request Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI GUI-related issues/changes WebUI WebUI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants