head

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtoHello uint8 = iota
	ProtoNotify
	ProtoQuery
	ProtoData
)

Proto 类型定义

Variables

This section is empty.

Functions

func PutPacket

func PutPacket(p *Packet)

PutPacket 将 Packet 放回池中

Types

type Notify

type Notify = map[string]string

Notify 是 map[peerip]endpoint

type Packet

type Packet struct {
	// TeaTypeDataSZ len(Data)
	// 高 4 位指定加密所用 tea key
	// 高 4-16 位是递增值, 用于预共享密钥验证 additionalData
	// 不得超过 65507-head 字节
	TeaTypeDataSZ uint32
	// Proto 详见 head
	Proto uint8
	// TTL is time to live
	TTL uint8
	// SrcPort 源端口
	SrcPort uint16
	// DstPort 目的端口
	DstPort uint16
	// Flags 高3位为标志(xDM),低13位为分片偏移
	Flags uint16
	// Src 源 ip (ipv4)
	Src net.IP
	// Dst 目的 ip (ipv4)
	Dst net.IP
	// Hash 使用 BLAKE2 生成加密前 Packet 的摘要
	// 生成时 Hash 全 0
	// https://github.com/fumiama/blake2b-simd
	Hash [32]byte
	// CRC64 包头字段的 checksum 值,可以认为在一定时间内唯一
	CRC64 uint64
	// Data 承载的数据
	Data []byte
	// contains filtered or unexported fields
}

Packet 是发送和接收的最小单位

func NewPacket

func NewPacket(proto uint8, srcPort uint16, dst net.IP, dstPort uint16, data []byte) (p *Packet)

NewPacket 生成一个新包

func SelectPacket

func SelectPacket() *Packet

SelectPacket 从池中取出一个 Packet

func (*Packet) AdditionalData added in v0.9.4

func (p *Packet) AdditionalData() uint16

AdditionalData 获得 packet 的 additionalData

func (*Packet) FillHash

func (p *Packet) FillHash()

FillHash 生成 p.Data 的 Hash

func (*Packet) IsVaildHash

func (p *Packet) IsVaildHash() bool

IsVaildHash 验证 packet 合法性

func (*Packet) Marshal

func (p *Packet) Marshal(src net.IP, teatype uint8, additional uint16, datasz uint32, offset uint16, dontfrag, hasmore bool) ([]byte, func())

Marshal 将自身数据编码为 []byte offset 必须为 8 的倍数,表示偏移的 8 位

func (*Packet) Put

func (p *Packet) Put()

Put 将自己放回池中

func (*Packet) Unmarshal

func (p *Packet) Unmarshal(data []byte) (complete bool, err error)

Unmarshal 将 data 的数据解码到自身

type Query

type Query = []string

Query 是 peerips 组成的数组

Jump to

Keyboard shortcuts

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