nictuku / dht

Kademlia/Mainline DHT node in Go.
Other
826 stars 144 forks source link

support the dht store extension #27

Open faried opened 10 years ago

faried commented 10 years ago

Summary of the changes so far:

I have a tarball of some partially working code here. It's the repository + my files. It really is a work in progress -- nowhere near ready for integration right now. Some of the code is likely incorrect; I explain why below.

I've tested libtorrent against my code, and using libtorrent's standalone dht_put program, I can both put and get immutable data from my modified DHT code. Here's what I did:

I started dht/examples/router on a server that's reachable from the internet. It's a small program that starts a DHT on port 9882, does not announce itself with the public routers, and waits forever for connections. I started the router with ./router -v=5 -logtostederr=true so I could see all the activity.
I downloaded and unpacked libtorrent-rasterbar-1.0.1, and added dht_put.cpp to the tools directory. I modified the file to make it use only my router node. To compile it, you can either modify tools/Makefile.am to add a build target for dht_put (you'll need automake 1.14 installed) or compile it manually.

After compiling dht_put, type ./dht_put put "hello there". It should talk to the router, and do a get followed by a put (you'll see that in the router's output). It'll print out the SHA-1 hash for the string 11:hello there, and you'll see the router store the value hello there. Next, if you try ./dht_put get <the hash>, it should talk to the router and return the string hello there. If you give it a different hash, it won't be able to fetch anything.

One thing that I didn't pay attention to carefully is the argument for put as described in the spec. You have to give it a valid object that can be bencoded -- a string, an integer, a list, or a dictionary. The code on both sides (the sending node and the storage node) will bencode the object before calculating the SHA-1 hash.

I'm sort of aiming for the same public UI for the DHT Get and Put methods: GET takes an infohash, and PUT takes a bencodable object (maybe as a string?).

One thing I haven't had much success with is using the DHT's methods to actually get/put stuff. I wrote a small amount of code (not in the tarball) to operate the same way as dht_put, but it seems to spin after it receives the string to be sent out over the network, somewhere in the put method in getput.go.

A problem I have is that I haven't looked at the client code (Taipei) yet, so I don't have a good idea on how to integrate things properly. I mean to work on this today (Thursday), but stuff came up at home, and I've been busy.

nictuku commented 10 years ago

Have a look at the examples directory, that might clarify how it is supposed to work.