Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Announce(ctx context.Context) (*bencode.AnnounceResponse, error)
- func (c *Client) Close() error
- func (c *Client) ConnectionCount() int64
- func (c *Client) Connections() []*Connection
- func (c *Client) DiscoverPeers(ctx context.Context) ([]bencode.Peer, error)
- func (c *Client) Download(w io.Writer) error
- func (c *Client) HasConnection(addr string) bool
- func (c *Client) PieceLengths() []int
- func (c *Client) Pieces() []Piece
- type Command
- type CommandDecoder
- type CommandEncoder
- type Connection
- type HandshakeDecoder
- type HandshakeEncoder
- type HandshakeMessage
- type MessageID
- type Piece
Constants ¶
Variables ¶
View Source
var ( ErrInvalidHandshakeFormat = errors.New("p2p: invalid handshake format") ErrNoPeers = errors.New("p2p: no peers") ErrWriteConn = errors.New("p2p: failed to write to the connection") ErrPieceNotFound = errors.New("p2p: downloaded piece was not found in the buffer") // Should technically never happen? ErrInvalidPieceHash = errors.New("p2p: invalid downloaded piece hash") ErrNoCommand = errors.New("p2p: command from the connection was nil") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the structure for receiving and sending commands between bittorrent clients.
func NewClient ¶
NewClient returns a new client that immediately tries to initiate a handshake with the peer.
func (*Client) Announce ¶
Announce sends the request to the tracker to get the latest announce message.
func (*Client) Close ¶
Close closes all of the clients connections and stops the refetch announce goroutine.
func (*Client) ConnectionCount ¶
func (*Client) Connections ¶
func (c *Client) Connections() []*Connection
Connections returns all the current connections as a slice.
func (*Client) DiscoverPeers ¶
DiscoverPeers returns the peers from the announce message.
func (*Client) Download ¶
Download starts the download and blocks until the download finished or errors out.
func (*Client) HasConnection ¶
HasConnection returns whether or not the current connection pool includes the provided connection (addr).
func (*Client) PieceLengths ¶
type CommandDecoder ¶
type CommandDecoder struct {
// contains filtered or unexported fields
}
func NewCommandDecoder ¶
func NewCommandDecoder(r io.Reader) *CommandDecoder
func (CommandDecoder) Decode ¶
func (dec CommandDecoder) Decode() (*Command, error)
type CommandEncoder ¶
type CommandEncoder struct {
// contains filtered or unexported fields
}
func NewCommandEncoder ¶
func NewCommandEncoder(w io.Writer) *CommandEncoder
func (CommandEncoder) Encode ¶
func (enc CommandEncoder) Encode(cmd *Command) error
type Connection ¶
func (*Connection) Addr ¶
func (c *Connection) Addr() string
func (*Connection) PeerID ¶
func (c *Connection) PeerID() string
type HandshakeDecoder ¶
type HandshakeDecoder struct {
// contains filtered or unexported fields
}
func NewHandshakeDecoder ¶
func NewHandshakeDecoder(r io.Reader) *HandshakeDecoder
func (*HandshakeDecoder) Decode ¶
func (dec *HandshakeDecoder) Decode() (*HandshakeMessage, error)
type HandshakeEncoder ¶
type HandshakeEncoder struct {
// contains filtered or unexported fields
}
func NewHandshakeEncoder ¶
func NewHandshakeEncoder(w io.Writer) *HandshakeEncoder
func (*HandshakeEncoder) Encode ¶
func (enc *HandshakeEncoder) Encode(msg *HandshakeMessage) error
type HandshakeMessage ¶
type HandshakeMessage struct { ProtocolLength uint8 Protocol string Reserved [8]byte InfoHash []byte PeerID []byte }
func (*HandshakeMessage) MarshalBinary ¶
func (msg *HandshakeMessage) MarshalBinary() (data []byte, err error)
func (*HandshakeMessage) UnmarshalBinary ¶
func (msg *HandshakeMessage) UnmarshalBinary(data []byte) error
Click to show internal directories.
Click to hide internal directories.