'How to pass optional IP parâmeter to bittorrent tracker in announce request?

Thanks in advance for taking your time to read this.

I have implemented a bittorrent tracker client in python that successfully communicates with udp trackers and retrieves a peer list from them.

Example of peer list retreived from tracker. In this case the peer is my own computer because only I annouced in the tracker:

[('34.2.289.11', 53016)]

This is the code that turns the parameters passed into the annouce query into a byte object:

msg = struct.pack('!QII20s20sQQQIIIIH', self.client.connid, action, tid,
                  infohash, self.client.peerid, downloaded, left,
                  uploaded, event, ip, key, num_want, port)

The "ip" parâmeter is an integer and normally the value passed is 0. This is the default value which means the tracker itself will determine my IP and use it when it passes my endpoint information to other peers joining the swarm.

However the bittorrent specification tells we can optionally pass a custom IP or a DNS name for the tracker to use.

The problem is I change the value of ip parâmeter to any number > 0 before using struct.pack(), but it's not working as the response from the tracker is still my public IP, that is:

[('34.2.289.11', 53016), ('34.2.289.11', 59509)]

(Ignore the first tuple from the list, it is my own computer when I sent the announce request with "ip" parâmeter equals 0)

I know it might be possible that the trackers themselves may be ignoring the ip parâmeter. But I tested 50 different trackers and every one of them returns my IP address, not the custom one im trying to pass. Therefore I think the problem is in my implementation.



Solution 1:[1]

I know it might be possible that the trackers themselves may be ignoring the ip parĂ¢meter. But I tested 50 different trackers and every one of them returns my IP address, not the custom one im trying to pass. Therefore I think the problem is in my implementation.

Almost all public/open trackers will not accept the IP parameter due to security problems. In principle they could do active verification (some tracker software supports that) but that's too expensive for open trackers. In practice only trackers with smaller user-bases will allow it, either gated by client authentication or by active verification.

I have implemented a bittorrent tracker client in python that successfully communicates with udp trackers and retrieves a peer list from them.

I would expect UDP trackers to be even less likely to support this parameter since the UDP tracker protocol is meant for high-load scenarios which are even less likely to afford any kind of verification.

For testing purposes you should look for some tracker software that explicitly supports the IP parameter (maybe a HTTP tracker meant for private torrent sites or at least an implementation not trimmed for high load scenarios) and run it locally. Once you have ensured that the server side supports it you can test the client properly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 the8472