message

package
v0.0.0-...-6621f61 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageChoke         messageID = 0 // 阻塞接收
	MessageUnChoke       messageID = 1 // 不阻塞接收
	MessageInterested    messageID = 2 // 有兴趣接收数据
	MessageNotInterested messageID = 3 // 没有兴趣接受数据
	MessageHave          messageID = 4 // 发送者已经下载好了一个 piece
	MessageBitfield      messageID = 5 // 判断哪些 piece 是 peers 有的,哪些没有
	MessageRequest       messageID = 6 // 从接收者那里请求一个 message
	MessagePiece         messageID = 7 // 执行请求,交付一个 piece
	MessageCancel        messageID = 8 // 取消请求
)

Variables

This section is empty.

Functions

func ParseHave

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

func ParsePiece

func ParsePiece(index int, buffer []byte, message *Message) (int, error)

Types

type Message

type Message struct {
	ID      messageID
	Payload []byte
}

func FormatMessageHave

func FormatMessageHave(index int) *Message

func FormatMessageRequest

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

func Read

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

func (*Message) Name

func (message *Message) Name() string

func (*Message) Serialize

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

序列化 message,结果为 --------------------------------------- |length| |message ID| |message Payload| ---------------------------------------

 ↓           ↓               ↓
4 byte      1 byte          n byte

这样的一个字节数组

func (*Message) String

func (message *Message) String() string

Jump to

Keyboard shortcuts

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