]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Actually announce to DHT, don't just get peers
authorMatt Joiner <anacrolix@gmail.com>
Sun, 16 Nov 2014 19:18:08 +0000 (13:18 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 16 Nov 2014 19:18:08 +0000 (13:18 -0600)
client.go
misc.go

index 6a768606cfca89d9178f4dabfcf5147464bca403..017ebe7782f29a2c4ce4828acfbc587c69dbb58b 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1268,6 +1268,18 @@ func (cl *Client) announceTorrentDHT(t *torrent) {
                        }
                }
                ps.Close()
+
+               // After a GetPeers, we can announce on the best nodes that gave us an
+               // announce token.
+
+               port := cl.incomingPeerPort()
+               // If port is zero, then we're not listening, and there's nothing to
+               // announce.
+               if port != 0 {
+                       // We can't allow the port to be implied as long as the UTP and
+                       // DHT ports are different.
+                       cl.dHT.AnnouncePeer(port, false, t.InfoHash.AsString())
+               }
        }
 }
 
diff --git a/misc.go b/misc.go
index 4a903a359ee34f3860aa3a881aafb460178ff599..295415151fd8bd63517ef58dd76342de6cc634ca 100644 (file)
--- a/misc.go
+++ b/misc.go
@@ -27,6 +27,10 @@ type (
        pieceSum [20]byte
 )
 
+func (ih *InfoHash) AsString() string {
+       return string(ih[:])
+}
+
 type piece struct {
        Hash              pieceSum
        PendingChunkSpecs map[chunkSpec]struct{}