connection

package
v0.0.0-...-2f17533 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bitfield

type Bitfield []byte

Bitfield is byte array which stores the index of the parts available with a particular client

func (Bitfield) CheckPiece

func (bf Bitfield) CheckPiece(index int) bool

CheckPiece tells if a bitfield has a particular index set

func (Bitfield) PutPiece

func (bf Bitfield) PutPiece(index int)

PutPiece sets a bit in the bitfield

type Client

type Client struct {
	Conn     net.Conn
	Choked   bool
	Bitfield Bitfield
	// contains filtered or unexported fields
}

A Client is a TCP connection with a peer

func New

func New(peer string, pid []byte, infoHash [20]byte) (*Client, error)

New connects with a peer, completes a handshake, and receives a handshake returns an err if any of those fail.

func (*Client) ReadMessageFromPeer

func (c *Client) ReadMessageFromPeer() (*message.Message, error)

ReadMessageFromPeer read the peers response after handshake,i.e interprets have,choked,unchoked,and Piece messages

func (*Client) SendHave

func (c *Client) SendHave(index int) error

SendHave sends a Have message to the peer

func (*Client) SendInterested

func (c *Client) SendInterested() error

SendInterested sends an Interested message to the peer

func (*Client) SendRequest

func (c *Client) SendRequest(index, begin, length int) error

SendRequest sends a Request message to the peer

func (*Client) SendUnchoke

func (c *Client) SendUnchoke() error

SendUnchoke sends an Unchoke message to the peer

Jump to

Keyboard shortcuts

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