The new version of libtorrent-2.0, which has been testing for several months, is now compatible with BitTorrent v2. This new protocol seeks to put encryption aside SHA-1 in favor of SHA-256, much safer. This change began just after Google cracked SHA-1 using brute force, demonstrating how insecure this encryption is. Since this change in the hash function would make the new system non-backward compatible, they decided to introduce more changes.
Switching to SHA-256 makes hashes 32 bytes instead of 20 bytes. To maintain compatibility with the DHT and trackers, the information required to perform searches has been trimmed to remain at 20 bytes. However, two different “swarms” will still be created for each torrent depending on the supported protocol used by each user.
Magnet links will load earlier when downloading
To prevent torrent sizes from growing too large, the way hashes are identified has also been simplified. With BitTorrent v1, the hashes are chopped up and include the torrent file, taking up most of that file. To keep it at an acceptable size for large torrent sizes, you can reduce the number of pieces into which the torrent is divided, but that forces a larger part of the final file to be downloaded if there is a hash or download failure. .
For this reason, now with BitTorrent v2 a hashes tree is used, called «merkle hash tree«. Instead of using the hashes for each chunk, only the root hash of the tree is needed. As a result, the latency of adding a magnet link is reduced by having less information to download before starting a download. Second, it will be possible to discover if a peer sends a corrupt block, and it will only be necessary to reload 16 kiB.
Torrent files will include these hashes, and their size will be smaller than the current ones. Also, the part that the magnets need will be smaller, which will make your download start earlier. Current magnets are prefixed with »urn: btih:», and new ones are prefixed with «urn: btmh:», making them easier to identify.
There will be hybrid torrent files compatible with BitTorrent v1 and v2
Files that are identical will have the same hashes, allowing files to be easily moved from one torrent to another when creating them without having to create new hashes. Thanks to this, it will be possible to find more seeds in other swarms. With this, files uploaded to different trackers can be downloaded more easily, even if not all files within the same torrent are the same. For example, if you are downloading a greatest hits album from a music group, and one of their songs has the same hash as another that appears on the album it was originally released on, that particular song can be downloaded.
To ensure backward compatibility, it will be possible to create hybrid torrents, where the files we download can be obtained from users who are using both version v1 and version v2 of BitTorrent. Hybrid torrents will have two hashes, one SHA-1 and one SHA-256.
On the libtorrent website they have put an example of two torrent files: one v2 and another hybrid to check if our torrent manager is compatible. The size of v2 is 14 KB, for the 35 KB it would take to be a v1 torrent. The hybrid takes up a lot more, going up to 90 KB.