peerconn

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn is a peer connection that provides a channel for receiving messages and methods for sending messages.

func New

func New(conn net.Conn, l logger.Logger, pieceTimeout time.Duration, maxRequestsIn int, fastEnabled bool, br, bw *ratelimit.Bucket) *Conn

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

func (*Conn) Addr

func (p *Conn) Addr() *net.TCPAddr

Addr returns the net.TCPAddr of the peer.

func (*Conn) CancelRequest

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

CancelRequest removes previously queued piece message matching msg.

func (*Conn) Close

func (p *Conn) Close()

Close stops receiving and sending messages and closes underlying net.Conn.

func (*Conn) IP

func (p *Conn) IP() string

IP returns the string representation of IP address.

func (*Conn) Logger

func (p *Conn) Logger() logger.Logger

Logger for the peer that logs messages prefixed with peer address.

func (*Conn) Messages

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

Messages received from the peer will be sent to the channel returned. The channel and underlying net.Conn will be closed if any error occurs while receiving or sending.

func (*Conn) Run

func (p *Conn) Run()

Run starts receiving messages from peer and starts sending queued messages. If any error happens during receiving or sending messages, the connection and the underlying net.Conn will be closed.

func (*Conn) SendMessage

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

SendMessage queues a message for sending. Does not block.

func (*Conn) SendPiece

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

SendPiece queues a piece message for sending. Does not block. Piece data is read just before the message is sent. If queued messages greater than `maxRequestsIn` specified in constructor, the last message is dropped.

func (*Conn) String

func (p *Conn) String() string

String returns the remote address as string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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