tomp2p / TomP2P

A P2P-based high performance key-value pair storage library
http://tomp2p.net
Apache License 2.0
438 stars 122 forks source link

Example on complete DHT node #103

Closed lmatteis closed 9 years ago

lmatteis commented 9 years ago

I'm looking to implement an entire DHT node which also stores the state of the routing table to disk. I know the site provides nice examples to look into, but they're mostly showing how specific things would work, and doesn't provide a complete example of an actual DHT node. Would you know if I can find somewhere an implementation of a complete node, so all I need to do is run the program on several computers and the whole DHT network would just work (including hole-punching, NAT traversal and overlay network)? For example, one important feature of a DHT node is to keep the state of the IP addresses of other nodes that it successfully connected to, so that at next startup, they can find each other. Any help? Thanks.

tbocek commented 9 years ago

You can access all the peer via PeerMap.all() and get their peeraddress. This can be persisted to the disk and loaded via PeerMap.foundPeer() later on. You can achieve this with a few lines of code, however, there is no example source code, but this should help you

//serialize List list = peer.peerBean().peerMap().all() // get all addresses byte[] data = Utils.encodeJavaObject(list); //now write data to disk

//read from disk, then deserialize: List list = (List) Utils.decodeJavaObject(data, offset, length); for(PeerAddress pa:list) { peer.peerBean().peerMap().peerFound(pa, null, null, null); }

If you have any issues, please reopen this issue.