peer_protocol

package
v0.0.0-...-796776c Latest Latest
Warning

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

Go to latest
Published: May 18, 2017 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Choke         MessageType = iota
	Unchoke                   // 1
	Interested                // 2
	NotInterested             // 3
	Have                      // 4
	Bitfield                  // 5
	Request                   // 6
	Piece                     // 7
	Cancel                    // 8
	Port                      // 9

	// BEP 6
	Suggest     = 0xd  // 13
	HaveAll     = 0xe  // 14
	HaveNone    = 0xf  // 15
	Reject      = 0x10 // 16
	AllowedFast = 0x11 // 17

	Extended = 20

	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 Bytes

type Bytes []byte

func (Bytes) MarshalBinary

func (b Bytes) MarshalBinary() ([]byte, error)

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.

type Integer

type Integer uint32

func (Integer) Int

func (i Integer) Int() int

It's perfectly fine to cast these to an int.

func (*Integer) Read

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

type Message

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

func (Message) MarshalBinary

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

type MessageType

type MessageType byte

Jump to

Keyboard shortcuts

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