]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Add Peer.Torrent
authorMatt Joiner <anacrolix@gmail.com>
Wed, 1 Mar 2023 03:17:29 +0000 (14:17 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 1 Mar 2023 03:17:29 +0000 (14:17 +1100)
This was for accessing from callback events.

peer.go

diff --git a/peer.go b/peer.go
index dbff1ba155efda1a59312c234c312bad57f61509..d5ed19e53ac45471b589327afe0443805194f742 100644 (file)
--- a/peer.go
+++ b/peer.go
@@ -126,6 +126,13 @@ const (
        PeerSourceDirect = "M"
 )
 
+// Returns the Torrent a Peer belongs to. Shouldn't change for the lifetime of the Peer. May be nil
+// if we are the receiving end of a connection and the handshake hasn't been received or accepted
+// yet.
+func (p *Peer) Torrent() *Torrent {
+       return p.t
+}
+
 func (p *Peer) initRequestState() {
        p.requestState.Requests = &peerRequests{}
 }