Documentation ¶
Index ¶
- type Conn
- func (p *Conn) Addr() *net.TCPAddr
- func (p *Conn) CancelRequest(msg peerprotocol.CancelMessage)
- func (p *Conn) Close()
- func (p *Conn) IP() string
- func (p *Conn) Logger() logger.Logger
- func (p *Conn) Messages() <-chan any
- func (p *Conn) Run()
- func (p *Conn) SendMessage(msg peerprotocol.Message)
- func (p *Conn) SendPiece(msg peerprotocol.RequestMessage, pi io.ReaderAt)
- func (p *Conn) String() string
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) 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) Messages ¶
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.