]> Sergey Matveev's repositories - btrtrc.git/blobdiff - torrent.go
Add holepunch message fuzzing
[btrtrc.git] / torrent.go
index 5184fc795971f6aa3987db55f51ce37ab439ab53..bb68cfc1e7af06dedb710a38341bc301fbeea1d9 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
@@ -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)
        }
 }
 
@@ -2774,6 +2777,7 @@ func (t *Torrent) handleReceivedUtHolepunchMsg(msg utHolepunch.Msg, sender *Peer
        switch msg.MsgType {
        case utHolepunch.Rendezvous:
                t.logger.Printf("got holepunch rendezvous request for %v from %p", msg.AddrPort, sender)
+               torrent.Add("holepunch rendezvous messages received", 1)
                sendMsg := sendUtHolepunchMsg
                senderAddrPort, err := sender.remoteDialAddrPort()
                if err != nil {
@@ -2801,6 +2805,7 @@ func (t *Torrent) handleReceivedUtHolepunchMsg(msg utHolepunch.Msg, sender *Peer
                }
                return nil
        case utHolepunch.Connect:
+               torrent.Add("holepunch connect messages received", 1)
                t.logger.Printf("got holepunch connect request for %v from %p", msg.AddrPort, sender)
                opts := outgoingConnOpts{
                        peerInfo: PeerInfo{
@@ -2819,6 +2824,7 @@ func (t *Torrent) handleReceivedUtHolepunchMsg(msg utHolepunch.Msg, sender *Peer
                initiateConn(opts, true)
                return nil
        case utHolepunch.Error:
+               torrent.Add("holepunch error messages received", 1)
                t.logger.Levelf(log.Debug, "received ut_holepunch error message from %v: %v", sender, msg.ErrCode)
                return nil
        default:
@@ -2839,6 +2845,7 @@ func (t *Torrent) trySendHolepunchRendezvous(addrPort netip.AddrPort) error {
                }
                t.logger.Levelf(log.Debug, "sent ut_holepunch rendezvous message to %v for %v", pc, addrPort)
                sendUtHolepunchMsg(pc, utHolepunch.Rendezvous, addrPort, 0)
+               torrent.Add("holepunch rendezvous messages sent", 1)
                rzsSent++
        }
        if rzsSent == 0 {