client

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2023 License: MIT Imports: 19 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

func (Bitfield) HasPiece

func (b Bitfield) HasPiece(index int) bool

HasPiece queries a bitfield if it has a index

func (Bitfield) SetPiece

func (b Bitfield) SetPiece(index int)

SetPiece set a bit in a bitfield

type Client

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

func NewClient

func NewClient(
	peer peer.Peer,
	peerID handshake.PeerID,
	infoHash handshake.Hash,
) (*Client, error)

NewClient returns a new client This also executes the handshake

func (*Client) Read

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

Read reads the message from the client

func (*Client) SendHave

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

SendHave send a new have message with a index

func (*Client) SendInterested

func (c *Client) SendInterested() error

SendInterested send a interested message

func (*Client) SendNotInterested

func (c *Client) SendNotInterested() error

SendNotInterested sends a not interested messaged

func (*Client) SendRequest

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

SendRequest sends a new request with the expected index, begin and length

func (*Client) SendUnchoke

func (c *Client) SendUnchoke() error

SendUnchoke send a new unchoke message

type Torrent

type Torrent struct {
	Peers       []peer.Peer
	PeerID      handshake.PeerID
	InfoHash    handshake.Hash
	PieceHashes []handshake.Hash
	PieceLength int
	Length      int
	Name        string
}

Torrent is the full representation for a torrent with peers and pieces

func TorrentFromTorrentFile

func TorrentFromTorrentFile(tFile string) (Torrent, error)

TorrentFromTorrrentFile returns a torrent from a torrent file

func (*Torrent) Download

func (t *Torrent) Download(path string) error

Download downloads a torrent

Jump to

Keyboard shortcuts

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