Discussion:
[libtorrent] plugin access to user agent
Jeff Waller
2017-06-22 23:30:41 UTC
Permalink
I am looking into writing a simplistic peer_plugin and I want to access the user agent
of a connected peer. It appears that the signature is available via peer_connection->pid(),
(not immediately, but on the first tick()) is this also true some other way for the user_agent if it exists?

-Jeff
Arvid Norberg
2017-06-28 02:08:59 UTC
Permalink
Post by Jeff Waller
I am looking into writing a simplistic peer_plugin and I want to access the user agent
of a connected peer. It appears that the signature is available via
peer_connection->pid(),
(not immediately, but on the first tick()) is this also true some other
way for the user_agent if it exists?
The peer_id (via pid()) should be available immediately after the
BitTorrent handshake, which may be after your plugin is constructed. For
outgoing connections the plugin is constructed when the peer is initiating
the connection. For incoming connections, the BitTorrent handshake has
already completed, since libtorrent must first determine which torrent the
peer belongs to. Which means the peer id will be available immediately.

The "user-agent" can mean two things:

1. The fingerprint in the peer_id (decoded by the deprecated function
identify_client(),
https://github.com/arvidn/libtorrent/blob/f3d319b6776545f044af010e3819f52b5d542a88/include/libtorrent/identify_client.hpp#L65
)

2. The client name/version string it advertise in the extended handshake
message. Your plugin will be notified of the handshake message on the
on_extension_handshake() callback. See ut_metadata for example:
https://github.com/arvidn/libtorrent/blob/master/src/ut_metadata.cpp#L208 .
In there, look for the "v" key, as documented here:
http://libtorrent.org/extension_protocol.html
--
Arvid Norberg
Loading...