]> Sergey Matveev's repositories - btrtrc.git/blobdiff - connection.go
Prepare to allow max conns per torrent to be configured
[btrtrc.git] / connection.go
index 7f8e10b41d6254f87ffc0b723e0e0a0aa54b4e19..1f8d3e749b5d2ebdbcaed830eaa25e11ce52c075 100644 (file)
@@ -653,3 +653,19 @@ func (cn *connection) wroteBytes(b []byte) {
        cn.stats.wroteBytes(b)
        cn.t.stats.wroteBytes(b)
 }
+
+// Returns whether the connection is currently useful to us. We're seeding and
+// they want data, we don't have metainfo and they can provide it, etc.
+func (c *connection) useful() bool {
+       t := c.t
+       if c.closed.IsSet() {
+               return false
+       }
+       if !t.haveInfo() {
+               return c.supportsExtension("ut_metadata")
+       }
+       if t.seeding() {
+               return c.PeerInterested
+       }
+       return t.connHasWantedPieces(c)
+}