torrent

package
v0.0.0-...-ba61289 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

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 ServeAsInitiator(conn net.Conn, infoHash []byte, localPeerID string, remotePeerID string) (*Connection, error)

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 Packet

type Packet struct {
	ID      uint8
	Payload []byte
}

type PieceRequest

type PieceRequest struct {
	Index  uint32
	Begin  uint32
	Length uint32

	Callback func([]byte)
}

type SendPieceReply

type SendPieceReply func(piece []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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