peer_protocol

package
v0.0.0-...-0290a16 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HandshakeExtendedID = 0

	RequestMetadataExtensionMsgType = 0
	DataMetadataExtensionMsgType    = 1
	RejectMetadataExtensionMsgType  = 2
)
View Source
const (
	Protocol = "\x13BitTorrent protocol"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	R         *bufio.Reader
	Pool      *sync.Pool
	MaxLength Integer // TODO: Should this include the length header or not?
}

func (*Decoder) Decode

func (d *Decoder) Decode(msg *Message) (err error)

io.EOF is returned if the source terminates cleanly on a message boundary. TODO: Is that before or after the message?

type Integer

type Integer uint32

func (Integer) Int

func (i Integer) Int() int

It's perfectly fine to cast these to an int. TODO: Or is it?

func (*Integer) Read

func (i *Integer) Read(r io.Reader) error

func (Integer) Uint64

func (i Integer) Uint64() uint64

type Message

type Message struct {
	Keepalive            bool
	Type                 MessageType
	Index, Begin, Length Integer
	Piece                []byte
	Bitfield             []bool
	ExtendedID           byte
	ExtendedPayload      []byte
	Port                 uint16
}

func MakeCancelMessage

func MakeCancelMessage(piece, offset, length Integer) Message

func (Message) MarshalBinary

func (msg Message) MarshalBinary() (data []byte, err error)

func (Message) MustMarshalBinary

func (msg Message) MustMarshalBinary() []byte

type MessageType

type MessageType byte
const (
	// BEP 3
	Choke         MessageType = 0
	Unchoke       MessageType = 1
	Interested    MessageType = 2
	NotInterested MessageType = 3
	Have          MessageType = 4
	Bitfield      MessageType = 5
	Request       MessageType = 6
	Piece         MessageType = 7
	Cancel        MessageType = 8
	Port          MessageType = 9

	// BEP 6
	Suggest     MessageType = 0x0d // 13
	HaveAll     MessageType = 0x0e // 14
	HaveNone    MessageType = 0x0f // 15
	Reject      MessageType = 0x10 // 16
	AllowedFast MessageType = 0x11 // 17

	// BEP 10
	Extended MessageType = 20
)

func (MessageType) FastExtension

func (mt MessageType) FastExtension() bool

func (MessageType) String

func (i MessageType) String() string

Jump to

Keyboard shortcuts

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