How to setup a DHT server of bittorrent? - bittorrent

I am finding a way to setup my own DHT bootstrap server of bittorrent on a linux server. I tried bootstrap-dht, but I found it didn't work. It is designed to create your own DHT network instead of introducing the client to the bittorrent DHT network.
Anyone can help?

Related

Can using a dht replace the use of signaling servers in P2P networks holepunching?

While learning about p2p networks I found out that P2P networks need signaling servers but can modern DHT replace the need for signaling servers? (Holepunching mainly)
A vanilla DHT that only acts as hash table can't serve that purpose but a customized implementation where the nodes support some protocol-specific extensions it is possible. E.g. in the bittorent DHT clients can instruct DHT nodes to put whatever their externally visible port is into the hash table rather than simply publishing their internal port number. This only really works for full-cone NAT.
For restricted cone or symmetric nat more complicated signalling and guessing approaches like STUN would have to be added to all DHT nodes and peers behind NATs could then initiate traversal at a particular node by publishing it as their rendezvous.

How can I use BitTorrent DHT to get a P2P connection between two nodes?

I know that BitTorrent DHT can be used to coordinate torrents without the need for a tracker. Now, I would like to build a P2P network of nodes and I would prefer to avoid the hassle of developing my own discovery / signaling / handshaking / NAT traversal.
So I was wondering: is there any library (preferably nodejs) that I can use to just:
Generate an identifier on a node A.
On a node B, use A's identifier to connect to A.
Both nodes get some callback with a socket, ready to write on?
I mean, this should be somehow part of the handshaking protocol for BitTorrent, but instead of directly using the torrent protocol to send data, I would like to directly get to talk with the other node and implement my own protocol.
Is it possible?
The bittorrent DHT and the bittorrent data transfer protocol are separate things. So yes, it is possible to find other IP/Port contacts through the DHT and connect to them with a custom protocol.

How PEX protocol (Magnetic links) finds it first IP?

I'm trying to understand how can a magnetic link work, as I've read they use DHT and PEX to get the peers, but if I'm a new node in the network how can I find peers with only the hash of the file?! Doesn't it always require a link to a known host?
Thanks
The bittorrent DHT can be bootstrapped in many ways. It just needs the IP and Port of any other reachable DHT node out there.
Current clients generally use several of the following strategies:
bootstrap from a cache of long-lived nodes from a previous session
use a DNS A/AAAA record mapping to a known node (e.g. router.bittorrent.com or dht.transmissionbt.com) with a known port
use a node embedded in a .torrent file
retrieve the DHT port from a bittorrent client over a bittorrent connection established through other means, e.g. a conventional tracker.
If a peer is embedded in a magnet link one can also piggyback a DHT bootstrap on that through the port message
multicast neighbor discovery via LSD
cross-chatter from the IPv4 to the IPv6 DHTs and vice versa (if needed)
Other ways such as user-configurable bootstrap lists, DNS SRV records round-robin mapping to live nodes or - should everything else fail - adding the IP of your friend(s) manually work.
Once a node has joined the network the first strategy mentioned above will kick in and it is unlikely that it will have to bootstrap again.
So while most implementations rely on a single/few points of entry into the network for convenience, the protocol itself is flexible enough to decentralize the points of entry too.
Just for emphasis: Any node in the DHT can be used to join the network. Dedicated bootstrap nodes are an implementation detail, not part of the protocol, and could be replaced by other discovery mechanisms if necessary.

Torrent DHT udp

Im trying to get access to a Torrent DHT network, and im having a hard time figuring out howto get access to the "entry" node in DHT.
How does a DHT in a Bittorent client get "bootstrapped"?
Describes that a couple of standard entry nodes could be used router.bittorrent.com and router.utorrent.com running on port 6881 (UDP).
AND http://www.bittorrent.org/beps/bep_0005.html describes the protocol on howto interact with a DHT server.
But if i send a simple UDP message to router.utorrent.com:6881, how do i know which port messages will be sent back to me in response to my requests? i tried listening for messages on the same port as i send to 6881 but i receive nothing.
Is these entry points limited to their own client (uTorrent) or can any thirdparty client use their "router"?
DHT responses are always sent to the same port the query was sent from.
If you're not getting a response from router.utorrent.com, it could be because it's temporarily down or because its network interface is saturated (last time I checked it was handling 6000 requests per second, iirc). If you only sent a single message, it could have been lost in the network as well.
Another reason for the DHT router not to respond would be if your query is mal-formed. I would suggest running wireshark, comparing uTorrent's DHT messages with your own, side-by-side.
uTorrent's DHT router is not locked in to any specific client, anyone can use it for bootstrapping.
As an alternative way to bootstrap, you could download some popular .torrent files, announce to the tracker and bootstrap off of the peers.

How does a DHT in a Bittorent client get "bootstrapped"?

If I have a torrent w/o any trackers in it, and I just started a bittorent client so I have no peers yet...how do I know who to first connect with in the DHT? It seems like I would have to know at least ONE node in the DHT to get started....
The mainline DHT bootstrap nodes are router.utorrent.com and a CNAME to it, router.bittorrent.com. Port 6881.
When a BitTorrent client connects to DHT, there is an initial place that it goes to find peers. With the original BitTorrent client, there was a url to bitorrent.com that would help get things started. I tried looking up the reference but I couldn't find it. Once you've established connections with other clients, then you can do an announce on the DHT network to find peers for the torrent you're looking for.
Here's a link to the BitTorrent specs that discuss DHT.
A trackerless torrent dictionary does
not have an "announce" key. Instead, a
trackerless torrent has a "nodes" key.
This key should be set to the K
closest nodes in the torrent
generating client's routing table.
Alternatively, the key could be set to
a known good node such as one operated
by the person generating the torrent.
Please do not automatically add
"router.bittorrent.com" to torrent
files or automatically add this node
to clients routing tables.
the graph at the bottom of this DHT monitoring project site shows
dht.transmissionbt.com
router.utorrent.com
router.bittorrent.com
as bootstrapping peers
In BiTTorrent, you have three main options:
Torrent File: some torrent files can embed nodes for you to link into the DHT with (in fact, it's recommended when making a torrent file)
Hardcoding: Some torrent clients hard code a few bootstrap nodes (like the ones mentioned by stk). These are usually run by companies and organizations with long-running servers.
PEX / Peer Conversations: You can usually ask for DHT nodes from the people you are downloading other torrents from (if your clients understand eachothers language. ie some versions are incompatible).
Transmission uses a hardcoded bootstrap node for dht if there is no other way to get peers:
bootstrap_from_name( "dht.transmissionbt.com", 6881, bootstrap_af(session) );
I guess each torrent client uses their own bootstrap node.
For the record, Deluge also uses hardcoded boostrap nodes:
dht_bootstraps = set(
lt_bootstraps.split(',')
+ [
'router.bittorrent.com:6881',
'router.utorrent.com:6881',
'router.bitcomet.com:6881',
'dht.transmissionbt.com:6881',
'dht.aelitis.com:6881',
]
)
A client can learn about other DHT-capable peers through it's interactions with them. A peer's support for DHT is advertised in it's Handshake. Once a client discovers at least one good, well-connected DHT peer, it can navigate the DHT to find more and closer DHT peers. It will remember these peers, called nodes in DHT-speak, between restarts of the software and maintain/update the list continuously while it is running. In the worse case where a client knows of no good DHT-capable peers, it will require you to download a tracker-based torrent so it can hopefully contact a few good DHT-capable peers it learns about through the tracker.
Update:
For it's initial list of DHT peers, as #Seppo points out, a torrent client can use one or more hard-coded DNS names to find the addresses for well-known peers, and it may also include a hard-coded list of peers as a final fallback as well. One limitation of DNS, however, it no port information is provided so a default port of 6881 is generally assumed whereas other means support peers operating on different ports.
Here are the primary nodes I've come across.
dht.transmissionbt.com 6881
router.bittorrent.com 6881
router.bitcomet.com 6881
dht.aelitis.com 6881
bootstrap.jami.net 4222

Resources