peerwriter

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: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockUploaded

type BlockUploaded struct {
	Length uint32
}

BlockUploaded is used to signal the Torrent when a piece block is uploaded to remote peer. BlockUploaded can be used to count the number of bytes uploaded to peers.

type PeerWriter

type PeerWriter struct {
	// contains filtered or unexported fields
}

PeerWriter is responsible for writing BitTorrent protocol messages to the peer connection.

func New

func New(conn net.Conn, l logger.Logger, maxQueuedRequests int, fastEnabled bool, b *ratelimit.Bucket) *PeerWriter

New returns a new PeerWriter by wrapping a net.Conn.

func (*PeerWriter) CancelRequest

func (p *PeerWriter) CancelRequest(msg peerprotocol.CancelMessage)

CancelRequest cancels the previously received "request" message.

func (*PeerWriter) Done

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

Done returns a channel that is closed when run loop exists.

func (*PeerWriter) Messages

func (p *PeerWriter) Messages() <-chan interface{}

Messages returns a channel. Various events from the writer are sent to this channel.

func (*PeerWriter) Run

func (p *PeerWriter) Run()

Run the writer loop.

func (*PeerWriter) SendMessage

func (p *PeerWriter) SendMessage(msg peerprotocol.Message)

SendMessage is used to send a protocol message to the Peer.

func (*PeerWriter) SendPiece

func (p *PeerWriter) SendPiece(msg peerprotocol.RequestMessage, pi io.ReaderAt)

SendPiece is used to send a "piece" message to the Peer. Data is not read when the method is called. Data is read by the run loop when writing the piece message.

func (*PeerWriter) Stop

func (p *PeerWriter) Stop()

Stop the writer loop.

type Piece

type Piece struct {
	Data io.ReaderAt
	peerprotocol.RequestMessage
}

Piece of the torrent. Data is read by the PeerWriter's Run loop.

func (Piece) ID

func (p Piece) ID() peerprotocol.MessageID

ID returns the BitTorrent protocol message ID.

func (Piece) Read

func (p Piece) Read(b []byte) (int, error)

Read piece data.

Jump to

Keyboard shortcuts

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