jbitor / issues

GitHub Issues for jbitor.
https://github.com/jbitor/issues/issues
0 stars 0 forks source link

Peer Exchange (ut_pex) #6

Open banksJeremy opened 10 years ago

banksJeremy commented 10 years ago

The first BitTorrent feature I want is peer exchange, because without tracker support (not planned) I need peer exchange + DHT to be able to properly connect to a swarm.

I probably won't implement any of the BitTorrent or BEP-10 extension protocols that aren't necessary to get peer exchange working.


Since it's such a key feature, I always assumed that the peer exchange protocol was defined by a BEP document. I didn't realize I was wrong until I went to look at it yesterday.

Similar to the DHT, there is an Azureus peer exchange protocol, which is the oldest and uses their custom protocol, and a newer alternative that is more widely used and uses the common BEP-10 extension protocol (ut_pex).

libtorrent's implementation can probably be used to figure out the simple protocol, but it doesn't seem to be explicitly documented anywhere, surprisingly.

banksJeremy commented 10 years ago

I found a description of the PEX protocol in deleted Transmission documentation.

uTorrent peer exchange messages use the key "ut_pex" in the m dictionary. If the uTorrent peer has pex disabled, this key will not be present. Exchanges messages should be sent approximately once every minute when peers have been added or dropped.

If peers have not been added or dropped, uTorrent does not send the periodic PEX message. If uTorrent 1.8.1 recieves an "empty" pex message from Transmission 1.40, it appears to interpret this as an invalid message and disconnect from Transmission.

The payload of a peer exchange message is a bencoded dictionary with the following keys:

  • added string, contains peers in the compact tracker format (ie: 6 bytes for IPv4 address and port in network byte order) added since the last peer exchange message
  • added.f string, one byte of flags for each peer in the above added string. according to libtorrent's ut_pex.c: 0x01 - peer supports encryption 0x02 - peer is a seed or a partial seed
  • dropped
    same format as added, contains peers dropped since last peer exchange

In contrast to Azureus' maximum of 50 peers per pex burst, uTorrent will hold up to 200. alus reports: "uT stores max 200 from other peers, but it will send everything it has."