]> Sergey Matveev's repositories - btrtrc.git/blobdiff - pex.go
PEX: impede full-meching in tracker-less swarms by adding a cooldown minute
[btrtrc.git] / pex.go
diff --git a/pex.go b/pex.go
index 83376d481c16b30b4d342c0322d90fc7742f84c5..a808af2bc0f9bc6c3724b5d8c4663e03182d67e6 100644 (file)
--- a/pex.go
+++ b/pex.go
@@ -3,6 +3,7 @@ package torrent
 import (
        "net"
        "sync"
+       "time"
 
        "github.com/anacrolix/dht/v2/krpc"
        pp "github.com/anacrolix/torrent/peer_protocol"
@@ -179,6 +180,7 @@ func shortestIP(ip net.IP) net.IP {
 type pexState struct {
        ev        []pexEvent    // event feed, append-only
        hold      []pexEvent    // delayed drops
+       rest      time.Time     // cooldown deadline on inbound
        nc        int           // net number of alive conns
        initCache pexMsgFactory // last generated initial message
        initSeq   int           // number of events which went into initCache
@@ -190,6 +192,7 @@ func (s *pexState) Reset() {
        s.ev = nil
        s.hold = nil
        s.nc = 0
+       s.rest = time.Time{}
        s.initLock.Lock()
        s.initCache = pexMsgFactory{}
        s.initSeq = 0