Documentation
¶
Index ¶
- Constants
- func DecodePacket(packet []byte) (byte, []byte, error)
- func DistanceCompare(a, b, target ID) int
- type BootstrapReq
- type BootstrapRes
- type EndpointV6
- type EntryV6
- type FindNodeReq
- type FindNodeRes
- type Hello
- type ID
- type NodesDat
- type PacketCombiner
- type Ping
- type Pong
- type PublishKeysReq
- type PublishNotesReq
- type PublishRes
- type PublishSourcesReq
- type SearchEntry
- func (s SearchEntry) BytesTag(id byte) ([]byte, bool)
- func (s *SearchEntry) Get(src *bytes.Reader) error
- func (s SearchEntry) Put(dst *bytes.Buffer) error
- func (s SearchEntry) SourceAddr() (*net.TCPAddr, bool)
- func (s SearchEntry) StringTag(id byte) (string, bool)
- func (s SearchEntry) UIntTag(id byte) (uint64, bool)
- type SearchKeysReq
- type SearchNotesReq
- type SearchRes
- type SearchSourcesReq
- type Tag
Constants ¶
const ( BootstrapReqOp byte = 0x01 BootstrapResOp byte = 0x09 HelloReqOp byte = 0x11 HelloResOp byte = 0x19 FindNodeReqOp byte = 0x21 FindNodeResOp byte = 0x29 SearchKeysReqOp byte = 0x33 SearchSrcReqOp byte = 0x34 SearchNotesReqOp byte = 0x35 SearchResOp byte = 0x3B PublishKeysReqOp byte = 0x43 PublishSourceReqOp byte = 0x44 PublishNotesReqOp byte = 0x45 PublishResOp byte = 0x4B PingOp byte = 0x60 PongOp byte = 0x61 FindValue byte = 0x02 Store byte = 0x04 FindNode byte = 0x0B )
const ( // ProtocolHeader marks KADV6 UDP packets. ProtocolHeader byte = 0xE6 // KademliaVersion is the first published KADV6 protocol version. KademliaVersion byte = 0x01 // Tag types use a simpler typed tag encoding than legacy Kad. TagTypeString byte = 0x02 TagTypeUint32 byte = 0x03 TagTypeUint16 byte = 0x08 TagTypeUint8 byte = 0x09 TagTypeUint64 byte = 0x0B TagTypeBytes byte = 0x0C // Source-related tag identifiers. TagName byte = 0x01 TagFileSize byte = 0xD3 TagAddrFamily byte = 0xEE TagSourceIP6 byte = 0xF0 TagSourceUDPPort byte = 0xFC TagSourcePort byte = 0xFD TagSourceType byte = 0xFF // Supported address family in KADV6. AddrFamilyIPv6 byte = 6 )
Variables ¶
This section is empty.
Functions ¶
func DecodePacket ¶
DecodePacket extracts the opcode and payload from a packet.
func DistanceCompare ¶
DistanceCompare compares XOR distances to the target.
Types ¶
type BootstrapRes ¶
BootstrapRes returns contacts near the responder.
func (BootstrapRes) Pack ¶
func (b BootstrapRes) Pack() ([]byte, error)
Pack encodes the response payload.
func (*BootstrapRes) Unpack ¶
func (b *BootstrapRes) Unpack(payload []byte) error
Unpack decodes the response payload.
type EndpointV6 ¶
EndpointV6 stores a native IPv6 endpoint for KADV6 contacts.
func EndpointFromIP ¶
func EndpointFromIP(ip net.IP, udpPort, tcpPort uint16) (EndpointV6, error)
EndpointFromIP builds an endpoint from a native IPv6 address.
func EndpointFromUDPAddr ¶
func EndpointFromUDPAddr(addr *net.UDPAddr, tcpPort uint16) (EndpointV6, error)
EndpointFromUDPAddr builds an endpoint from a UDP address plus advertised TCP port.
func (*EndpointV6) Get ¶
func (e *EndpointV6) Get(src *bytes.Reader) error
Get decodes the endpoint from a reader.
func (EndpointV6) IPNet ¶
func (e EndpointV6) IPNet() net.IP
IPNet returns a copy of the stored IPv6 address as net.IP.
func (EndpointV6) Put ¶
func (e EndpointV6) Put(dst *bytes.Buffer) error
Put encodes the endpoint into a buffer.
func (EndpointV6) String ¶
func (e EndpointV6) String() string
String renders the endpoint in bracketed IPv6 form.
func (EndpointV6) TCPAddr ¶
func (e EndpointV6) TCPAddr() *net.TCPAddr
TCPAddr converts the endpoint to a TCP address.
func (EndpointV6) UDPAddr ¶
func (e EndpointV6) UDPAddr() *net.UDPAddr
UDPAddr converts the endpoint to a UDP address.
func (EndpointV6) Validate ¶
func (e EndpointV6) Validate() error
Validate checks whether the endpoint can be routed inside KADV6.
type EntryV6 ¶
type EntryV6 struct {
ID ID
Endpoint EndpointV6
Version byte
Verified bool
}
EntryV6 is a KADV6 routing entry.
type FindNodeReq ¶
FindNodeReq asks for closer contacts to a target id.
func (FindNodeReq) Pack ¶
func (r FindNodeReq) Pack() ([]byte, error)
Pack encodes a find-node request.
func (*FindNodeReq) Unpack ¶
func (r *FindNodeReq) Unpack(payload []byte) error
Unpack decodes a find-node request.
type FindNodeRes ¶
FindNodeRes returns contacts for a target id.
func (FindNodeRes) Pack ¶
func (r FindNodeRes) Pack() ([]byte, error)
Pack encodes a find-node response.
func (*FindNodeRes) Unpack ¶
func (r *FindNodeRes) Unpack(payload []byte) error
Unpack decodes a find-node response.
type Hello ¶
Hello confirms node identity and service port.
type NodesDat ¶
NodesDat stores bootstrap contacts for KADV6.
func LoadNodesDat ¶
LoadNodesDat loads and parses a KADV6 nodes file from disk.
func ParseNodesDat ¶
ParseNodesDat decodes a KADV6 nodes file from raw bytes.
type PacketCombiner ¶
type PacketCombiner struct{}
PacketCombiner packs and unpacks KADV6 packets by opcode.
type PublishKeysReq ¶
type PublishKeysReq struct {
KeywordID ID
Sources []SearchEntry
}
PublishKeysReq publishes keyword records.
func (PublishKeysReq) Pack ¶
func (p PublishKeysReq) Pack() ([]byte, error)
Pack encodes a keyword publish request.
func (*PublishKeysReq) Unpack ¶
func (p *PublishKeysReq) Unpack(payload []byte) error
Unpack decodes a keyword publish request.
type PublishNotesReq ¶
type PublishNotesReq struct {
FileID ID
Notes []SearchEntry
}
PublishNotesReq publishes note records.
func (PublishNotesReq) Pack ¶
func (p PublishNotesReq) Pack() ([]byte, error)
Pack encodes a notes publish request.
func (*PublishNotesReq) Unpack ¶
func (p *PublishNotesReq) Unpack(payload []byte) error
Unpack decodes a notes publish request.
type PublishRes ¶
PublishRes acknowledges one or more published records.
func (PublishRes) Pack ¶
func (p PublishRes) Pack() ([]byte, error)
Pack encodes a publish response.
func (*PublishRes) Unpack ¶
func (p *PublishRes) Unpack(payload []byte) error
Unpack decodes a publish response.
type PublishSourcesReq ¶
type PublishSourcesReq struct {
FileID ID
Source SearchEntry
}
PublishSourcesReq publishes one source record.
func (PublishSourcesReq) Pack ¶
func (p PublishSourcesReq) Pack() ([]byte, error)
Pack encodes a source publish request.
func (*PublishSourcesReq) Unpack ¶
func (p *PublishSourcesReq) Unpack(payload []byte) error
Unpack decodes a source publish request.
type SearchEntry ¶
SearchEntry stores source, keyword, or note metadata.
func (SearchEntry) BytesTag ¶
func (s SearchEntry) BytesTag(id byte) ([]byte, bool)
BytesTag returns the first matching raw-bytes tag.
func (*SearchEntry) Get ¶
func (s *SearchEntry) Get(src *bytes.Reader) error
Get decodes a search entry from a reader.
func (SearchEntry) Put ¶
func (s SearchEntry) Put(dst *bytes.Buffer) error
Put encodes a search entry into a buffer.
func (SearchEntry) SourceAddr ¶
func (s SearchEntry) SourceAddr() (*net.TCPAddr, bool)
SourceAddr extracts a direct IPv6 TCP source from the search entry.
type SearchKeysReq ¶
SearchKeysReq requests keyword records.
func (SearchKeysReq) Pack ¶
func (s SearchKeysReq) Pack() ([]byte, error)
Pack encodes a keyword search request.
func (*SearchKeysReq) Unpack ¶
func (s *SearchKeysReq) Unpack(payload []byte) error
Unpack decodes a keyword search request.
type SearchNotesReq ¶
SearchNotesReq requests note records.
func (SearchNotesReq) Pack ¶
func (s SearchNotesReq) Pack() ([]byte, error)
Pack encodes a notes search request.
func (*SearchNotesReq) Unpack ¶
func (s *SearchNotesReq) Unpack(payload []byte) error
Unpack decodes a notes search request.
type SearchRes ¶
type SearchRes struct {
Source ID
Target ID
Results []SearchEntry
}
SearchRes returns search entries for a target.
type SearchSourcesReq ¶
SearchSourcesReq requests source records for a file.
func (SearchSourcesReq) Pack ¶
func (s SearchSourcesReq) Pack() ([]byte, error)
Pack encodes a source search request.
func (*SearchSourcesReq) Unpack ¶
func (s *SearchSourcesReq) Unpack(payload []byte) error
Unpack decodes a source search request.