node.jsbittorrentdht

Why there is this "ip" field in a bittorrent dht querying response?


I was debugging this dht implementation when I came across this query response (KRPC type r). Theres no documentation about an "ip" field in BEP5, so why is this happening? Why does sometimes the response have the "ip" field and other times it doesn't have the "ip" field but instead it has the "v" field (which is documented). In my understanding there shouldn't be such "ip" field. Where can I find documentation about it?

Edit: The ip field has my public IP and port.


Solution

  • Nodes supporting BEP42 add that field to allow other nodes to learn their own public address in case they are behind a NAT.

    Also, since bencoding is a non-fixed format (unlike some packed binary messages for example), one should not expect that only the fields specified by the core specification are present, this ensures forward-compatibility.