Documentation ¶
Index ¶
- type Message
- type Peer
- func (p *Peer) CancelPiece(index, begin, length uint32)
- func (p *Peer) Choke()
- func (p *Peer) Choking() bool
- func (p *Peer) Client() string
- func (p *Peer) Close()
- func (p *Peer) Done() chan struct{}
- func (p *Peer) DownloadSpeed() int
- func (p *Peer) EnabledFast() bool
- func (p *Peer) GenerateAndSendAllowedFastMessages(k int, numPieces uint32, infoHash [20]byte, pieces []piece.Piece)
- func (p *Peer) Interested() bool
- func (p *Peer) MetadataSize() uint32
- func (p *Peer) Optimistic() bool
- func (p *Peer) RequestMetadataPiece(index uint32)
- func (p *Peer) RequestPiece(index, begin, length uint32)
- func (p *Peer) ResetSnubTimer()
- func (p *Peer) Run(messages chan Message, pieces chan PieceMessage, ...)
- func (p *Peer) SetOptimistic(value bool)
- func (p *Peer) StartPEX(initialPeers map[*Peer]struct{}, recentlySeen *pexlist.RecentlySeen)
- func (p *Peer) StopSnubTimer()
- func (p *Peer) Unchoke()
- func (p *Peer) UploadSpeed() int
- type PieceMessage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Peer ¶
type Peer struct { *peerconn.Conn ConnectedAt time.Time Source peersource.Source Bitfield *bitfield.Bitfield ReceivedAllowedFast sliceset.SliceSet[piece.Piece] SentAllowedFast sliceset.SliceSet[piece.Piece] ID [20]byte ExtensionsEnabled bool FastEnabled bool DHTEnabled bool EncryptionCipher mse.CryptoMethod ClientInterested bool ClientChoking bool PeerInterested bool PeerChoking bool OptimisticUnchoked bool // Snubbed means peer is sending pieces too slow. Snubbed bool Downloading bool // Messages received while we don't have info yet are saved here. Messages []any ExtensionHandshake *peerprotocol.ExtensionHandshakeMessage PEX *pex Closed bool // contains filtered or unexported fields }
Peer of a Torrent. Wraps a BitTorrent connection.
func New ¶
func New(conn net.Conn, source peersource.Source, id [20]byte, extensions [8]byte, cipher mse.CryptoMethod, pieceReadTimeout, snubTimeout time.Duration, maxRequestsIn int, br, bw *ratelimit.Bucket) *Peer
New wraps the net.Conn and returns a new Peer.
func (*Peer) CancelPiece ¶ added in v0.5.0
CancelPiece cancels previosly requested piece. Sends "cancel" protocol message.
func (*Peer) Choke ¶ added in v0.4.9
func (p *Peer) Choke()
Choke the connected Peer by sending a "choke" protocol message.
func (*Peer) Client ¶ added in v0.5.4
Client returns the name of the client. Returns client string in extension handshake. If extension handshake is not done, returns asciified version of the peer ID.
func (*Peer) Done ¶ added in v0.3.8
func (p *Peer) Done() chan struct{}
Done returns a channel that is closed when a peers run loop is ended.
func (*Peer) DownloadSpeed ¶ added in v0.3.0
DownloadSpeed of the Peer in bytes per second.
func (*Peer) EnabledFast ¶ added in v0.5.4
EnabledFast returns true if the remote Peer supports Fast extension.
func (*Peer) GenerateAndSendAllowedFastMessages ¶ added in v0.16.0
func (p *Peer) GenerateAndSendAllowedFastMessages(k int, numPieces uint32, infoHash [20]byte, pieces []piece.Piece)
GenerateAndSendAllowedFastMessages is used to send "allowed fast" protocol messages after handshake.
func (*Peer) Interested ¶ added in v0.4.9
Interested returns true if remote Peer is interested for pieces we have.
func (*Peer) MetadataSize ¶ added in v0.5.0
MetadataSize returns the torrent metadata size that is received from the Peer with an extension handshake message.
func (*Peer) Optimistic ¶ added in v0.4.9
Optimistic returns true if we are unchoking the Peer optimistically.
func (*Peer) RequestMetadataPiece ¶ added in v0.5.0
RequestMetadataPiece is used to send a message that is requesting a metadata piece at index.
func (*Peer) RequestPiece ¶ added in v0.5.0
RequestPiece is used to request a piece at index by sending a "piece" protocol message.
func (*Peer) ResetSnubTimer ¶
func (p *Peer) ResetSnubTimer()
ResetSnubTimer is called when some data received from the Peer.
func (*Peer) Run ¶
func (p *Peer) Run(messages chan Message, pieces chan PieceMessage, snubbed, disconnect chan *Peer)
Run loop that reads messages from the Peer.
func (*Peer) SetOptimistic ¶ added in v0.4.9
SetOptimistic sets the status of if we are chiking the peer optimistically.
func (*Peer) StartPEX ¶
func (p *Peer) StartPEX(initialPeers map[*Peer]struct{}, recentlySeen *pexlist.RecentlySeen)
StartPEX starts the PEX goroutine for sending PEX messages to the Peer periodically.
func (*Peer) StopSnubTimer ¶
func (p *Peer) StopSnubTimer()
StopSnubTimer is used to stop the timer that is for detecting if the Peer is snub.
func (*Peer) Unchoke ¶ added in v0.4.9
func (p *Peer) Unchoke()
Unchoke the connected Peer by sending an "unchoke" protocol message.
func (*Peer) UploadSpeed ¶ added in v0.3.0
UploadSpeed of the Peer in bytes per second.
type PieceMessage ¶
type PieceMessage struct { *Peer Piece peerreader.Piece }
PieceMessage is a Piece message that is read from Peer