diff options
| author | Felix Hanley <felix@userspace.com.au> | 2018-03-23 04:37:46 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2018-03-23 04:37:57 +0000 |
| commit | 082c7506f302c93d7e2126f611058b536d262e31 (patch) | |
| tree | ee45b2823e543f262756a5da5535424388d72372 /dht | |
| parent | 2cb7f7a926d844b1fff65ccd386d774ba83bd561 (diff) | |
| download | dhtsearch-082c7506f302c93d7e2126f611058b536d262e31.tar.gz dhtsearch-082c7506f302c93d7e2126f611058b536d262e31.tar.bz2 | |
Basic sqlite functionality
Diffstat (limited to 'dht')
| -rw-r--r-- | dht/messages.go | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/dht/messages.go b/dht/messages.go index d972d65..4063f01 100644 --- a/dht/messages.go +++ b/dht/messages.go @@ -79,7 +79,7 @@ func (n *Node) onAnnouncePeerQuery(rn remoteNode, msg map[string]interface{}) er return err } - //n.log.Debug("announce_peer", "source", rn) + n.log.Debug("announce_peer", "source", rn) host, port, err := net.SplitHostPort(rn.addr.String()) if err != nil { @@ -89,6 +89,15 @@ func (n *Node) onAnnouncePeerQuery(rn remoteNode, msg map[string]interface{}) er return fmt.Errorf("ignoring port 0") } + ihStr, err := krpc.GetString(a, "info_hash") + if err != nil { + return err + } + ih, err := models.InfohashFromString(ihStr) + if err != nil { + return fmt.Errorf("invalid torrent: %s", err) + } + newPort, err := krpc.GetInt(a, "port") if err == nil { if iPort, err := krpc.GetInt(a, "implied_port"); err == nil && iPort == 0 { @@ -97,21 +106,13 @@ func (n *Node) onAnnouncePeerQuery(rn remoteNode, msg map[string]interface{}) er if err != nil { return err } + n.log.Debug("implied port", "infohash", ih, "original", rn.addr.String(), "new", addr.String()) rn = remoteNode{addr: addr, id: rn.id} } } // TODO do we reply? - ihStr, err := krpc.GetString(a, "info_hash") - if err != nil { - return err - } - ih, err := models.InfohashFromString(ihStr) - if err != nil { - n.log.Warn("invalid torrent", "infohash", ihStr) - } - p := models.Peer{Addr: rn.addr, Infohash: *ih} if n.OnAnnouncePeer != nil { go n.OnAnnouncePeer(p) |
