peer

package
v1.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	*Peer
	Message any
}

Message that is read from Peer

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

func (p *Peer) CancelPiece(index, begin, length uint32)

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) Choking added in v0.4.9

func (p *Peer) Choking() bool

Choking returns true if we are choking the remote Peer.

func (*Peer) Client added in v0.5.4

func (p *Peer) Client() string

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) Close

func (p *Peer) Close()

Close the peer connection.

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

func (p *Peer) DownloadSpeed() int

DownloadSpeed of the Peer in bytes per second.

func (*Peer) EnabledFast added in v0.5.4

func (p *Peer) EnabledFast() bool

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

func (p *Peer) Interested() bool

Interested returns true if remote Peer is interested for pieces we have.

func (*Peer) MetadataSize added in v0.5.0

func (p *Peer) MetadataSize() uint32

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

func (p *Peer) Optimistic() bool

Optimistic returns true if we are unchoking the Peer optimistically.

func (*Peer) RequestMetadataPiece added in v0.5.0

func (p *Peer) RequestMetadataPiece(index uint32)

RequestMetadataPiece is used to send a message that is requesting a metadata piece at index.

func (*Peer) RequestPiece added in v0.5.0

func (p *Peer) RequestPiece(index, begin, length uint32)

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

func (p *Peer) SetOptimistic(value bool)

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

func (p *Peer) UploadSpeed() int

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL