kad

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BootstrapReqOp        byte = 0x01
	BootstrapResOp        byte = 0x09
	ReqOp                 byte = 0x21
	ResOp                 byte = 0x29
	HelloReqOp            byte = 0x11
	HelloResOp            byte = 0x19
	HelloResAckOp         byte = 0x22
	SearchKeysReqOp       byte = 0x33
	SearchNotesResOp      byte = 0x3A
	CallbackReqOp         byte = 0x52
	FindBuddyReqOp        byte = 0x51
	FindBuddyResOp        byte = 0x5A
	LegacyFirewalledReqOp byte = 0x50
	FirewalledReqOp       byte = 0x53
	FirewalledResOp       byte = 0x58
	FirewalledUdpOp       byte = 0x62
	PingOp                byte = 0x60
	PongOp                byte = 0x61
	PublishSourceReqOp    byte = 0x44
	PublishKeysReqOp      byte = 0x43
	PublishNotesReqOp     byte = 0x45
	PublishNotesResOp     byte = 0x4A
	PublishResOp          byte = 0x4B
	PublishResAckOp       byte = 0x4C
	SearchNotesReqOp      byte = 0x35

	KademliaVersion byte = 0x05

	FindValue byte = 0x02
	Store     byte = 0x04
	FindNode  byte = 0x0B
)
View Source
const (
	ProtocolHeader byte = 0xE4
	SearchResOp    byte = 0x3B
	SearchSrcReqOp byte = 0x34

	TagTypeString byte = 0x02
	TagTypeUint32 byte = 0x03
	TagTypeUint16 byte = 0x08
	TagTypeUint8  byte = 0x09
	TagTypeUint64 byte = 0x0B
	TagTypeStr1   byte = 0x11

	TagEncryption  byte = 0xF3
	TagBuddyHash   byte = 0xF8
	TagClientLowID byte = 0xF9
	TagServerPort  byte = 0xFA
	TagServerIP    byte = 0xFB
	TagSourceUPort byte = 0xFC
	TagSourcePort  byte = 0xFD
	TagSourceIP    byte = 0xFE
	TagSourceType  byte = 0xFF
)

Variables

This section is empty.

Functions

func DecodePacket

func DecodePacket(packet []byte) (byte, []byte, error)

func DistanceCompare

func DistanceCompare(a, b, target ID) int

Types

type BootstrapReq

type BootstrapReq struct{}

func (BootstrapReq) Pack

func (BootstrapReq) Pack() ([]byte, error)

type BootstrapRes

type BootstrapRes struct {
	ID       ID
	TCPPort  uint16
	Version  byte
	Contacts []Entry
}

func (BootstrapRes) Pack

func (b BootstrapRes) Pack() ([]byte, error)

func (*BootstrapRes) Unpack

func (b *BootstrapRes) Unpack(payload []byte) error

type CallbackReq

type CallbackReq struct{}

func (CallbackReq) Pack

func (CallbackReq) Pack() ([]byte, error)

type EmptyPacket

type EmptyPacket struct {
	Opcode byte
}

func (EmptyPacket) Pack

func (e EmptyPacket) Pack() ([]byte, error)

type Endpoint

type Endpoint struct {
	IP      uint32
	UDPPort uint16
	TCPPort uint16
}

func (Endpoint) ED2K

func (e Endpoint) ED2K() protocol.Endpoint

func (*Endpoint) Get

func (e *Endpoint) Get(src *bytes.Reader) error

func (Endpoint) Put

func (e Endpoint) Put(dst *bytes.Buffer) error

type Entry

type Entry struct {
	ID       ID
	Endpoint Endpoint
	Version  byte
	Verified bool
}

func (*Entry) Get

func (e *Entry) Get(src *bytes.Reader) error

func (Entry) Put

func (e Entry) Put(dst *bytes.Buffer) error

type FindBuddyReq

type FindBuddyReq struct{}

func (FindBuddyReq) Pack

func (FindBuddyReq) Pack() ([]byte, error)

type FindBuddyRes

type FindBuddyRes struct{}

func (FindBuddyRes) Pack

func (FindBuddyRes) Pack() ([]byte, error)

type FirewalledReq

type FirewalledReq struct {
	TCPPort uint16
	ID      ID
	Options byte
}

func (FirewalledReq) Pack

func (f FirewalledReq) Pack() ([]byte, error)

func (*FirewalledReq) Unpack

func (f *FirewalledReq) Unpack(payload []byte) error

type FirewalledRes

type FirewalledRes struct {
	IP uint32
}

func (FirewalledRes) Pack

func (f FirewalledRes) Pack() ([]byte, error)

func (*FirewalledRes) Unpack

func (f *FirewalledRes) Unpack(payload []byte) error

type FirewalledUDP

type FirewalledUDP struct {
	ErrorCode byte
	TCPPort   uint16
}

func (FirewalledUDP) Pack

func (f FirewalledUDP) Pack() ([]byte, error)

func (*FirewalledUDP) Unpack

func (f *FirewalledUDP) Unpack(payload []byte) error

type Hello

type Hello struct {
	ID      ID
	TCPPort uint16
	Version byte
	Tags    []Tag
}

func (Hello) Pack

func (h Hello) Pack(opcode byte) ([]byte, error)

func (*Hello) Unpack

func (h *Hello) Unpack(payload []byte) error

type HelloResAck

type HelloResAck struct{}

func (HelloResAck) Pack

func (HelloResAck) Pack() ([]byte, error)

type ID

type ID struct {
	protocol.Hash
}

func NewID

func NewID(hash protocol.Hash) ID

func (*ID) Get

func (i *ID) Get(src *bytes.Reader) error

func (ID) Put

func (i ID) Put(dst *bytes.Buffer) error

type LegacyFirewalledReq

type LegacyFirewalledReq struct {
	TCPPort uint16
}

func (LegacyFirewalledReq) Pack

func (f LegacyFirewalledReq) Pack() ([]byte, error)

func (*LegacyFirewalledReq) Unpack

func (f *LegacyFirewalledReq) Unpack(payload []byte) error

type NodesDat

type NodesDat struct {
	Version          uint32
	BootstrapEdition uint32
	Contacts         []Entry
}

func LoadNodesDat

func LoadNodesDat(path string) (*NodesDat, error)

func ParseNodesDat

func ParseNodesDat(raw []byte) (*NodesDat, error)

func (*NodesDat) Unpack

func (n *NodesDat) Unpack(payload []byte) error

type PacketCombiner

type PacketCombiner struct{}

func (PacketCombiner) Pack

func (PacketCombiner) Pack(packet any, extra ...byte) ([]byte, error)

func (PacketCombiner) Unpack

func (PacketCombiner) Unpack(packet []byte) (byte, any, error)

type Ping

type Ping struct{}

func (Ping) Pack

func (Ping) Pack() ([]byte, error)

type Pong

type Pong struct {
	UDPPort uint16
}

func (Pong) Pack

func (p Pong) Pack() ([]byte, error)

func (*Pong) Unpack

func (p *Pong) Unpack(payload []byte) error

type PublishKeysReq

type PublishKeysReq struct {
	KeywordID ID
	Sources   []SearchEntry
}

func (PublishKeysReq) Pack

func (p PublishKeysReq) Pack() ([]byte, error)

func (*PublishKeysReq) Unpack

func (p *PublishKeysReq) Unpack(payload []byte) error

type PublishNotesReq

type PublishNotesReq struct {
	FileID ID
	Notes  []SearchEntry
}

func (PublishNotesReq) Pack

func (p PublishNotesReq) Pack() ([]byte, error)

func (*PublishNotesReq) Unpack

func (p *PublishNotesReq) Unpack(payload []byte) error

type PublishNotesRes

type PublishNotesRes struct {
	PublishRes
}

func (PublishNotesRes) Pack

func (p PublishNotesRes) Pack() ([]byte, error)

type PublishRes

type PublishRes struct {
	FileID ID
	Count  byte
}

func (PublishRes) Pack

func (p PublishRes) Pack() ([]byte, error)

func (*PublishRes) Unpack

func (p *PublishRes) Unpack(payload []byte) error

type PublishResAck

type PublishResAck struct{}

func (PublishResAck) Pack

func (PublishResAck) Pack() ([]byte, error)

type PublishSourcesReq

type PublishSourcesReq struct {
	FileID ID
	Source SearchEntry
}

func (PublishSourcesReq) Pack

func (p PublishSourcesReq) Pack() ([]byte, error)

func (*PublishSourcesReq) Unpack

func (p *PublishSourcesReq) Unpack(payload []byte) error

type Req

type Req struct {
	SearchType byte
	Target     ID
	Receiver   ID
}

func (Req) Pack

func (r Req) Pack() ([]byte, error)

func (*Req) Unpack

func (r *Req) Unpack(payload []byte) error

type Res

type Res struct {
	Target  ID
	Results []Entry
}

func (Res) Pack

func (r Res) Pack() ([]byte, error)

func (*Res) Unpack

func (r *Res) Unpack(payload []byte) error

type SearchEntry

type SearchEntry struct {
	ID   ID
	Tags []Tag
}

func (*SearchEntry) Get

func (s *SearchEntry) Get(src *bytes.Reader) error

func (SearchEntry) Put

func (s SearchEntry) Put(dst *bytes.Buffer) error

func (SearchEntry) SourceEndpoint

func (s SearchEntry) SourceEndpoint() (protocol.Endpoint, bool)

func (SearchEntry) StringTag

func (s SearchEntry) StringTag(id byte) (string, bool)

func (SearchEntry) UIntTag

func (s SearchEntry) UIntTag(id byte) (uint64, bool)

type SearchKeysReq

type SearchKeysReq struct {
	Target   ID
	StartPos uint16
}

func (SearchKeysReq) Pack

func (s SearchKeysReq) Pack() ([]byte, error)

func (*SearchKeysReq) Unpack

func (s *SearchKeysReq) Unpack(payload []byte) error

type SearchNotesReq

type SearchNotesReq struct {
	Target   ID
	FileSize uint64
}

func (SearchNotesReq) Pack

func (s SearchNotesReq) Pack() ([]byte, error)

func (*SearchNotesReq) Unpack

func (s *SearchNotesReq) Unpack(payload []byte) error

type SearchNotesRes

type SearchNotesRes struct{}

func (SearchNotesRes) Pack

func (SearchNotesRes) Pack() ([]byte, error)

type SearchRes

type SearchRes struct {
	Source  ID
	Target  ID
	Results []SearchEntry
}

func (SearchRes) Pack

func (s SearchRes) Pack() ([]byte, error)

func (*SearchRes) Unpack

func (s *SearchRes) Unpack(payload []byte) error

type SearchSourcesReq

type SearchSourcesReq struct {
	Target   ID
	StartPos uint16
	Size     uint64
}

func (SearchSourcesReq) Pack

func (s SearchSourcesReq) Pack() ([]byte, error)

func (*SearchSourcesReq) Unpack

func (s *SearchSourcesReq) Unpack(payload []byte) error

type Tag

type Tag struct {
	Type   byte
	ID     byte
	UInt64 uint64
	String string
}

func (*Tag) Get

func (t *Tag) Get(src *bytes.Reader) error

func (Tag) Put

func (t Tag) Put(dst *bytes.Buffer) error

Jump to

Keyboard shortcuts

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