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) 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 interface{}, snubbed, disconnect chan *Peer)
- func (p *Peer) SetOptimistic(value bool)
- 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
Host host.Host
Stream network.Stream
ConnectedAt time.Time
Source peersource.Source
Bitfield *bitfield.Bitfield
ReceivedAllowedFast pieceset.PieceSet
SentAllowedFast pieceset.PieceSet
ID string
P2pID p2pPeer.ID
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
// contains filtered or unexported fields
}
Peer of a Torrent. Wraps a BitTorrent connection.
func New ¶
func New(host host.Host, s network.Stream, source peersource.Source, id [20]byte, pieceReadTimeout, snubTimeout time.Duration, maxRequestsIn int, br, bw *ratelimit.Bucket) *Peer
New wraps the net.Conn and returns a new Peer.
func (*Peer) CancelPiece ¶
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) Client ¶
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 ¶
func (p *Peer) Done() chan struct{}
Done returns a channel that is closed when a peers run loop is ended.
func (*Peer) DownloadSpeed ¶
DownloadSpeed of the Peer in bytes per second.
func (*Peer) EnabledFast ¶
EnabledFast returns true if the remote Peer supports Fast extension.
func (*Peer) Interested ¶
Interested returns true if remote Peer is interested for pieces we have.
func (*Peer) MetadataSize ¶
MetadataSize returns the torrent metadata size that is received from the Peer with an extension handshake message.
func (*Peer) Optimistic ¶
Optimistic returns true if we are unchoking the Peer optimistically.
func (*Peer) RequestMetadataPiece ¶
RequestMetadataPiece is used to send a message that is requesting a metadata piece at index.
func (*Peer) RequestPiece ¶
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) SetOptimistic ¶
SetOptimistic sets the status of if we are chiking the peer optimistically.
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 ¶
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