]> Sergey Matveev's repositories - btrtrc.git/blobdiff - torrent.go
Fix panic logging unknown holepunch error code
[btrtrc.git] / torrent.go
index eeac172d10641dc997a566f4980abea44f2d555c..82dfc0a54acf9ccea2d952faf0409ef7037f6798 100644 (file)
@@ -830,7 +830,10 @@ func (t *Torrent) newMetaInfo() metainfo.MetaInfo {
        }
 }
 
-// Get bytes left
+// Returns a count of bytes that are not complete in storage, and not pending being written to
+// storage. This value is from the perspective of the download manager, and may not agree with the
+// actual state in storage. If you want read data synchronously you should use a Reader. See
+// https://github.com/anacrolix/torrent/issues/828.
 func (t *Torrent) BytesMissing() (n int64) {
        t.cl.rLock()
        n = t.bytesMissingLocked()
@@ -1057,7 +1060,7 @@ func (t *Torrent) havePiece(index pieceIndex) bool {
 func (t *Torrent) maybeDropMutuallyCompletePeer(
        // I'm not sure about taking peer here, not all peer implementations actually drop. Maybe that's
        // okay?
-       p *Peer,
+       p *PeerConn,
 ) {
        if !t.cl.config.DropMutuallyCompletePeers {
                return
@@ -1071,7 +1074,7 @@ func (t *Torrent) maybeDropMutuallyCompletePeer(
        if p.useful() {
                return
        }
-       t.logger.WithDefaultLevel(log.Debug).Printf("dropping %v, which is mutually complete", p)
+       p.logger.Levelf(log.Debug, "is mutually complete; dropping")
        p.drop()
 }
 
@@ -2217,7 +2220,7 @@ func (t *Torrent) onPieceCompleted(piece pieceIndex) {
        t.piece(piece).readerCond.Broadcast()
        for conn := range t.conns {
                conn.have(piece)
-               t.maybeDropMutuallyCompletePeer(&conn.Peer)
+               t.maybeDropMutuallyCompletePeer(conn)
        }
 }
 
@@ -2801,6 +2804,7 @@ func (t *Torrent) handleReceivedUtHolepunchMsg(msg utHolepunch.Msg, sender *Peer
                }
                return nil
        case utHolepunch.Connect:
+               t.logger.Printf("got holepunch connect request for %v from %p", msg.AddrPort, sender)
                opts := outgoingConnOpts{
                        peerInfo: PeerInfo{
                                Addr:         msg.AddrPort,
@@ -2825,7 +2829,7 @@ func (t *Torrent) handleReceivedUtHolepunchMsg(msg utHolepunch.Msg, sender *Peer
        }
 }
 
-func (t *Torrent) startHolepunchRendezvous(addrPort netip.AddrPort) error {
+func (t *Torrent) trySendHolepunchRendezvous(addrPort netip.AddrPort) error {
        rzsSent := 0
        for pc := range t.conns {
                if !pc.supportsExtension(utHolepunch.ExtensionName) {
@@ -2859,11 +2863,3 @@ func (t *Torrent) getDialTimeoutUnlocked() time.Duration {
        defer cl.rUnlock()
        return t.dialTimeout()
 }
-
-func (t *Torrent) startHolepunchRendezvousForPeerRemoteAddr(addr PeerRemoteAddr) error {
-       addrPort, err := addrPortFromPeerRemoteAddr(addr)
-       if err != nil {
-               return err
-       }
-       return t.startHolepunchRendezvous(addrPort)
-}