message

package
v0.0.0-...-806d497 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MsgChoke chokes the receiver
	MsgChoke messageID = 0
	// MsgUnchoke unchokes the receiver
	MsgUnchoke messageID = 1
	// MsgInterested expresses interest in receiving data
	MsgInterested messageID = 2
	// MsgNotInterested expresses disinterest in receiving data
	MsgNotInterested messageID = 3
	// MsgHave alerts the receiver that the sender has downloaded a piece
	MsgHave messageID = 4
	// MsgBitfield encodes which pieces that the sender has downloaded
	MsgBitfield messageID = 5
	// MsgRequest requests a block of data from the receiver
	MsgRequest messageID = 6
	// MsgPiece delivers a block of data to fulfill a request
	MsgPiece messageID = 7
	// MsgCancel cancels a request
	MsgCancel messageID = 8
)

Variables

This section is empty.

Functions

func ParseHave

func ParseHave(msg *Message) (int, error)

ParseHave parses a HAVE message

func ParsePiece

func ParsePiece(index int, buf []byte, msg *Message) (int, error)

ParsePiece parses a PIECE message and copies its payload into a buffer

Types

type Message

type Message struct {
	ID      messageID
	Payload []byte
}

Message stores ID and payload of a message

func FormatHave

func FormatHave(index int) *Message

FormatHave creates a HAVE message

func FormatRequest

func FormatRequest(index, begin, length int) *Message

FormatRequest creates a REQUEST message

func Read

func Read(r io.Reader) (*Message, error)

Read parses a message from a stream. Returns `nil` on keep-alive message

func (*Message) Serialize

func (m *Message) Serialize() []byte

Serialize serializes a message into a buffer of the form <length prefix><message ID><payload> Interprets `nil` as a keep-alive message

func (*Message) String

func (m *Message) String() string

Jump to

Keyboard shortcuts

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