diff options
| author | Felix Hanley <felix@userspace.com.au> | 2018-02-16 11:40:39 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2018-02-16 11:40:39 +0000 |
| commit | c44fe2b9329586d46184b450a32f8771057f794c (patch) | |
| tree | 8f3cfcded1f8f347d7975f7c0f7328f8e7ad69c2 /dht/messages.go | |
| parent | 32a655f042a3752d93c4507b4c128b21bf6aa602 (diff) | |
| download | dhtsearch-c44fe2b9329586d46184b450a32f8771057f794c.tar.gz dhtsearch-c44fe2b9329586d46184b450a32f8771057f794c.tar.bz2 | |
Enable IPv6
Diffstat (limited to 'dht/messages.go')
| -rw-r--r-- | dht/messages.go | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/dht/messages.go b/dht/messages.go index 94b15ee..be7d6b6 100644 --- a/dht/messages.go +++ b/dht/messages.go @@ -3,6 +3,7 @@ package dht import ( "fmt" "net" + "strings" ) func (n *Node) onPingQuery(rn remoteNode, msg map[string]interface{}) { @@ -30,22 +31,35 @@ func (n *Node) onGetPeersQuery(rn remoteNode, msg map[string]interface{}) { token := []byte(*th)[:2] id := generateNeighbour(n.id, *th) + nodes := n.rTable.get(8) + compactNS := []string{} + for _, rn := range nodes { + ns := encodeCompactNodeAddr(rn.address.String()) + if ns == "" { + n.log.Warn("failed to compact node", "address", rn.address.String()) + continue + } + compactNS = append(compactNS, ns) + } + t := msg["t"].(string) n.queueMsg(rn, makeResponse(t, map[string]interface{}{ "id": string(id), "token": token, - "nodes": "", + "nodes": strings.Join(compactNS, ""), })) - nodes := n.rTable.get(50) - fmt.Printf("sending get_peers for %s to %d nodes\n", *th, len(nodes)) - q := makeQuery(newTransactionID(), "get_peers", map[string]interface{}{ - "id": string(id), - "info_hash": string(*th), - }) - for _, o := range nodes { - n.queueMsg(*o, q) - } + //nodes := n.rTable.get(50) + /* + fmt.Printf("sending get_peers for %s to %d nodes\n", *th, len(nodes)) + q := makeQuery(newTransactionID(), "get_peers", map[string]interface{}{ + "id": string(id), + "info_hash": string(*th), + }) + for _, o := range nodes { + n.queueMsg(*o, q) + } + */ } func (n *Node) onAnnouncePeerQuery(rn remoteNode, msg map[string]interface{}) { @@ -77,7 +91,7 @@ func (n *Node) onAnnouncePeerQuery(rn remoteNode, msg map[string]interface{}) { n.log.Warn("sent port 0", "source", rn) return } - addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", host, newPort)) + addr, err := net.ResolveUDPAddr(n.family, fmt.Sprintf("%s:%d", host, newPort)) rn = remoteNode{address: addr, id: rn.id} } |
