dht

package
v0.0.0-...-9721c62 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: GPL-3.0 Imports: 10 Imported by: 9

Documentation

Index

Constants

View Source
const PublicKeySize = crypto.PublicKeySize

Variables

This section is empty.

Functions

This section is empty.

Types

type EncryptedPacket

type EncryptedPacket struct {
	Type            PacketType
	SenderPublicKey *PublicKey
	Nonce           *[crypto.NonceSize]byte
	Payload         []byte /* encrypted */
}

EncryptedPacket represents an encrypted DHT packet.

func (*EncryptedPacket) MarshalBinary

func (p *EncryptedPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*EncryptedPacket) UnmarshalBinary

func (p *EncryptedPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryMarshaler interface.

type GetNodesPacket

type GetNodesPacket struct {
	PublicKey *PublicKey
	PingID    uint64
}

GetNodesPacket represents the encrypted portion of the GetNodes request.

func (GetNodesPacket) ID

func (p GetNodesPacket) ID() PacketType

ID returns the packet ID of this packet.

func (*GetNodesPacket) MarshalBinary

func (p *GetNodesPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*GetNodesPacket) UnmarshalBinary

func (p *GetNodesPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryMarshaler interface.

type Identity

type Identity struct {
	PublicKey *PublicKey
	SecretKey *[crypto.SecretKeySize]byte
	// contains filtered or unexported fields
}

Identity represents a DHT identity.

func NewIdentity

func NewIdentity(opts IdentityOptions) (*Identity, error)

NewIdentity creates a new DHT identity and generates a new keypair for it.

func (*Identity) DecryptBlob

func (i *Identity) DecryptBlob(data []byte, publicKey *PublicKey, nonce *[crypto.NonceSize]byte) ([]byte, error)

DecryptBlob decrypts the given slice of data.

func (*Identity) DecryptPacket

func (i *Identity) DecryptPacket(p *EncryptedPacket) (Packet, error)

DecryptPacket decrypts the given packet.

func (*Identity) EncryptBlob

func (i *Identity) EncryptBlob(data []byte, publicKey *PublicKey) ([]byte, *[crypto.NonceSize]byte, error)

EncryptBlob encrypts the given slice of data.

func (*Identity) EncryptPacket

func (i *Identity) EncryptPacket(packet Packet, publicKey *PublicKey) (*EncryptedPacket, error)

EncryptPacket encrypts the given packet.

type IdentityOptions

type IdentityOptions struct {
	// SharedKeyCacheSize is the size of the LRU cache for precomputed shared keys.
	SharedKeyCacheSize int
}

type Node

type Node struct {
	Type      NodeType
	PublicKey *PublicKey
	IP        net.IP
	Port      int
}

Node represents a node in the DHT.

func (*Node) Addr

func (n *Node) Addr() net.Addr

func (*Node) MarshalBinary

func (n *Node) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*Node) UnmarshalBinary

func (n *Node) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type NodeType

type NodeType byte
const (
	NodeTypeUDPIP4 NodeType = 0x02
	NodeTypeUDPIP6 NodeType = 0x0A
	NodeTypeTCPIP4 NodeType = 0x82
	NodeTypeTCPIP6 NodeType = 0x8A
)

func (NodeType) Net

func (t NodeType) Net() string

func (*NodeType) UnmarshalText

func (t *NodeType) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

type Packet

type PacketType

type PacketType byte
const (
	PacketTypePingRequest  PacketType = 0x00
	PacketTypePingResponse PacketType = 0x01
	PacketTypeGetNodes     PacketType = 0x02
	PacketTypeSendNodes    PacketType = 0x04
)

func (PacketType) String

func (t PacketType) String() string

type PingRequestPacket

type PingRequestPacket struct {
	//ping type: 0x00
	PingID uint64
}

PingRequestPacket represents the encrypted portion of the PingRequest packet.

func (PingRequestPacket) ID

ID returns the packet ID of this packet.

func (*PingRequestPacket) MarshalBinary

func (p *PingRequestPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*PingRequestPacket) UnmarshalBinary

func (p *PingRequestPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type PingResponsePacket

type PingResponsePacket struct {
	//ping type: 0x01
	PingID uint64
}

PingResponsePacket represents the encrypted portion of the PingResponse packet.

func (PingResponsePacket) ID

ID returns the packet ID of this packet.

func (*PingResponsePacket) MarshalBinary

func (p *PingResponsePacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*PingResponsePacket) UnmarshalBinary

func (p *PingResponsePacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type PublicKey

type PublicKey [PublicKeySize]byte

func (*PublicKey) Closest

func (pk *PublicKey) Closest(pk1 *PublicKey, pk2 *PublicKey) *PublicKey

func (*PublicKey) DistanceTo

func (pk1 *PublicKey) DistanceTo(pk2 *PublicKey) *[PublicKeySize]byte

func (*PublicKey) String

func (pk *PublicKey) String() string

type SendNodesPacket

type SendNodesPacket struct {
	Nodes  []*Node
	PingID uint64
}

SendNodesPacket represents the encrypted portion of the SendNodes packet.

func (SendNodesPacket) ID

func (p SendNodesPacket) ID() PacketType

ID returns the packet ID of this packet.

func (*SendNodesPacket) MarshalBinary

func (p *SendNodesPacket) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*SendNodesPacket) UnmarshalBinary

func (p *SendNodesPacket) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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