Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reasoning behind BitTorrent KRPC using BEncode instead of BSON?

The Mainline DHT, used in BitTorrent to distribute lists of peers, implements a custom RPC protocol called KRPC. KRPC consists of BEncoded dictionaries, which are essentially a more compact form of JSON.

Is there any benefit of using BEncode over something like BSON (or even just compressing the data)?

like image 792
liamzebedee Avatar asked Oct 22 '22 16:10

liamzebedee


1 Answers

I suspect that bencode is being used for historical reasons and to lighten the burden on developers wanting to implement the DHT extension. Since all BitTorrent clients must have a working bencode implementation to work with torrent files (which are simply bencoded dictionaries of metadata), implementing the DHT with bencode would require no new project dependencies.

Also, consider that the DHT is using bencode along with binary encoding. Among others, the 26 byte node identifier string (20 bytes for the node-id, 6 bytes for the ipv4 address / port) is being stored as a binary string (see: http://bittorrent.org/beps/bep_0005.html#contact-encoding), so in-effect, there is already some minimal data-compression that is happening.

like image 89
gsk Avatar answered Oct 27 '22 11:10

gsk