message

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseHave

func ParseHave(msg Message) (int, error)

ParseHave parses a message have, and returns the index

func ParsePiece

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

ParsePiece parses and validates a piece from a index, buffer and a message Checks for message type, min payload, index, offset returns the

Types

type Message

type Message struct {
	ID      MessageID
	Payload []byte
	Buffer  io.Reader
	Length  uint32
}

Message is the structure of a new peer message Formed by the MessageID and a payload

func NewHaveMessage

func NewHaveMessage(index int) Message

NewHaveMessage builds a message have It accepts a index

func NewMessage

func NewMessage(ID MessageID, payload []byte) Message

NewMessage returns a new message

func NewRequestMessage

func NewRequestMessage(index, begin, length int) Message

NewRequestMessage build a new request message A request is formed by a index, begin and length

func Unmarshal

func Unmarshal(r io.Reader) (Message, error)

Read generates a message from a steam

func (*Message) Serialize

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

Serialize a message into bytes Each message is formed by: - Length of the payload as big endian - The message ID - The payload at the end

type MessageID

type MessageID uint8
const (
	MsgChoke         MessageID = 0
	MsgUnchoke       MessageID = 1
	MsgInterrested   MessageID = 2
	MsgNotInterested MessageID = 3
	MsgHave          MessageID = 4
	MsgBitfield      MessageID = 5
	MsgRequest       MessageID = 6
	MsgPiece         MessageID = 7
	MsgCancel        MessageID = 8
)

Types of messages More information can me found on https://wiki.theory.org/BitTorrentSpecification#Messages

Jump to

Keyboard shortcuts

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