peer

package
v0.0.0-...-dcce029 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: MIT Imports: 20 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 interface{}
}

Message that is read from Peer

type Peer

type Peer struct {
	*peerconn.Conn

	ConnectedAt time.Time

	Source peersource.Source

	Bitfield            *bitfield.Bitfield
	ReceivedAllowedFast pieceset.PieceSet
	SentAllowedFast     pieceset.PieceSet

	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 []interface{}

	ExtensionHandshake *peerprotocol.ExtensionHandshakeMessage

	PEX *pex
	// 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

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

CancelPiece cancels previosly requested piece. Sends "cancel" protocol message.

func (*Peer) Choke

func (p *Peer) Choke()

Choke the connected Peer by sending a "choke" protocol message.

func (*Peer) Choking

func (p *Peer) Choking() bool

Choking returns true if we are choking the remote Peer.

func (*Peer) Client

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

func (p *Peer) Done() chan struct{}

Done returns a channel that is closed when a peers run loop is ended.

func (*Peer) DownloadSpeed

func (p *Peer) DownloadSpeed() int

DownloadSpeed of the Peer in bytes per second.

func (*Peer) EnabledFast

func (p *Peer) EnabledFast() bool

EnabledFast returns true if the remote Peer supports Fast extension.

func (*Peer) GenerateAndSendAllowedFastMessages

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

func (p *Peer) Interested() bool

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

func (*Peer) MetadataSize

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

func (p *Peer) Optimistic() bool

Optimistic returns true if we are unchoking the Peer optimistically.

func (*Peer) RequestMetadataPiece

func (p *Peer) RequestMetadataPiece(index uint32)

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

func (*Peer) RequestPiece

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 interface{}, snubbed, disconnect chan *Peer)

Run loop that reads messages from the Peer.

func (*Peer) SafeClose

func (p *Peer) SafeClose()

Close the closeC channel safely

func (*Peer) SetOptimistic

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

func (p *Peer) Unchoke()

Unchoke the connected Peer by sending an "unchoke" protocol message.

func (*Peer) UploadSpeed

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