Initial working Kademlia network - peer list exchange is working!

Using the announcement and response messages to exchange peer lists. Fixes in encoding.
Add arbitrary Info structure to DHT Lite/Node.
This commit is contained in:
Kleissner
2021-03-15 22:25:05 +01:00
parent 323f379ee7
commit 3080119fc1
13 changed files with 210 additions and 33 deletions

View File

@@ -91,8 +91,13 @@ func parseAddress(Address string) (remote *net.UDPAddr, err error) {
// contact tries to contact the root peer on all networks
func (peer *rootPeer) contact() {
packets, err := msgEncodeAnnouncement(true, true, nil, nil, nil)
if len(packets) == 0 || err != nil {
return
}
for _, address := range peer.addresses {
sendAllNetworks(peer.publicKey, &PacketRaw{Command: 0}, address)
sendAllNetworks(peer.publicKey, &PacketRaw{Command: CommandAnnouncement, Payload: packets[0]}, address)
}
}
@@ -188,3 +193,12 @@ func autoMulticastBroadcast() {
sendMulticastBroadcast()
}
}
func contactArbitraryPeer(publicKey *btcec.PublicKey, ip net.IP, port uint16) {
packets, err := msgEncodeAnnouncement(true, true, nil, nil, nil)
if len(packets) == 0 || err != nil {
return
}
sendAllNetworks(publicKey, &PacketRaw{Command: CommandAnnouncement, Payload: packets[0]}, &net.UDPAddr{IP: ip, Port: int(port)})
}