Documentation ¶
Index ¶
- Constants
- Variables
- type Connection
- func (c *Connection) CancelPiece(request *PieceRequest) error
- func (c *Connection) Close() error
- func (c *Connection) GetPieceQueueLength() int
- func (c *Connection) InfoHash() []byte
- func (c *Connection) LocalPeerID() string
- func (c *Connection) ReadPacket() (*Packet, error)
- func (c *Connection) ReceiveHandshake(respondAfterInfoHash bool) error
- func (c *Connection) RemotePeerID() string
- func (c *Connection) RequestPiece(request *PieceRequest) error
- func (c *Connection) SendHavePiece(piece uint32) error
- func (c *Connection) SendHaveState(curState *state.State) error
- func (c *Connection) Serve() error
- func (c *Connection) SetChoked(choked bool) error
- func (c *Connection) SetPieceCount(pieces uint64)
- func (c *Connection) TransmitHandshake() error
- func (c *Connection) WritePacket(packet *Packet) error
- type InfoHashValidatorHandler
- type OnPieceCancelHandler
- type OnPieceRequestHandler
- type Packet
- type PieceRequest
- type SendPieceReply
Constants ¶
View Source
const ( PacketChoke = 0 PacketUnchoke = 1 PacketInterested = 2 PacketNotInterested = 3 PacketHave = 4 PacketBitfield = 5 PacketRequest = 6 PacketPiece = 7 PacketCancel = 8 PacketPort = 9 )
View Source
const BitBufferLen = 512
View Source
const HandshakeLenBeforeInfoHash = 1 + ProtocolStrLen + 8
View Source
const HandshakeLenFull = HandshakeLenMin + 20
View Source
const HandshakeLenMin = HandshakeLenBeforeInfoHash + 20
View Source
const ProtocolStr = "BitTorrent protocol"
View Source
const ProtocolStrLen = len(ProtocolStr)
Variables ¶
View Source
var ErrInvalidHandshake = errors.New("invalid handshake")
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct { OnPieceRequest OnPieceRequestHandler OnPieceCancel OnPieceCancelHandler OnRemoteChoke func(conn *Connection, choking bool) OnRemoteInterested func(conn *Connection, interested bool) InfoHashValidator InfoHashValidatorHandler OnHaveUpdated func(conn *Connection, piece int64) // contains filtered or unexported fields }
func ServeAsInitiator ¶
func ServeAsRecipient ¶
func ServeAsRecipient(conn net.Conn, infoHashValidator InfoHashValidatorHandler, localPeerID string, remotePeerID string) (*Connection, error)
func (*Connection) CancelPiece ¶
func (c *Connection) CancelPiece(request *PieceRequest) error
func (*Connection) Close ¶
func (c *Connection) Close() error
func (*Connection) GetPieceQueueLength ¶
func (c *Connection) GetPieceQueueLength() int
func (*Connection) InfoHash ¶
func (c *Connection) InfoHash() []byte
func (*Connection) LocalPeerID ¶
func (c *Connection) LocalPeerID() string
func (*Connection) ReadPacket ¶
func (c *Connection) ReadPacket() (*Packet, error)
func (*Connection) ReceiveHandshake ¶
func (c *Connection) ReceiveHandshake(respondAfterInfoHash bool) error
func (*Connection) RemotePeerID ¶
func (c *Connection) RemotePeerID() string
func (*Connection) RequestPiece ¶
func (c *Connection) RequestPiece(request *PieceRequest) error
func (*Connection) SendHavePiece ¶
func (c *Connection) SendHavePiece(piece uint32) error
func (*Connection) SendHaveState ¶
func (c *Connection) SendHaveState(curState *state.State) error
func (*Connection) Serve ¶
func (c *Connection) Serve() error
func (*Connection) SetChoked ¶
func (c *Connection) SetChoked(choked bool) error
func (*Connection) SetPieceCount ¶
func (c *Connection) SetPieceCount(pieces uint64)
func (*Connection) TransmitHandshake ¶
func (c *Connection) TransmitHandshake() error
func (*Connection) WritePacket ¶
func (c *Connection) WritePacket(packet *Packet) error
type InfoHashValidatorHandler ¶
type InfoHashValidatorHandler func(conn *Connection, infoHash []byte) (bool, error)
type OnPieceCancelHandler ¶
type OnPieceCancelHandler func(conn *Connection, index uint32, begin uint32, length uint32)
type OnPieceRequestHandler ¶
type OnPieceRequestHandler func(conn *Connection, index uint32, begin uint32, length uint32, reply SendPieceReply) error
type PieceRequest ¶
type SendPieceReply ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.