peer

package
v0.0.0-...-101a212 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package peer is a client implementation (TCP only) to peers in the swarm.

The current implementation supports

  • the extension protocol BEP0010
  • metadata transfer between peers BEP0009
  • DHT Port transfer BEP0005

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInBitfield = errors.New("client does not have piece")

ErrNotInBitfield is returned on a call to *Client.GetPiece() if the peer does not have the requested piece.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(addr net.TCPAddr, infoHash, peerID [20]byte) (*Client, error)

NewClient initializes a connection with a peer, then:

  • completes the handshake
  • completes the extension handshake if applicable
  • receives the bitfield message
  • sends an unchoke and interested message to the peer

func (*Client) Addr

func (p *Client) Addr() net.Addr

Addr returns the address (IP and Port) of the remote peer.

func (*Client) Close

func (p *Client) Close() error

Close the underlying peer connection

func (*Client) DHTAddr

func (p *Client) DHTAddr() (net.UDPAddr, error)

DHTAddr returns the UDP address to reach this peer's DHT node. The peer should have sent a Port message after the BitTorrent handshake (per BEP0005). If it did not, a non-nil error is returned. http://bittorrent.org/beps/bep_0005.html

func (*Client) GetMetadata

func (p *Client) GetMetadata(infoHash [20]byte) ([]byte, error)

GetMetadata requests and receives the raw metadata/info dictionary from the peer (per BEP0009). If the peer does not support this extension, a non-nil error is returned. http://bittorrent.org/beps/bep_0009.html

func (*Client) GetPiece

func (p *Client) GetPiece(index, length int, hash [20]byte) ([]byte, error)

GetPiece starts a download for the specified piece. If the returned error is non-nil and not ErrNotInBitfield, the peer can be considered "bad" and can be disconnected from

Jump to

Keyboard shortcuts

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