dht

package module
v0.0.0-...-f63d3a6 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2021 License: MIT Imports: 11 Imported by: 0

README

The WatNet DHT

This is the Distributed Hash Table of WatNet, based on the Kademlia algorithm.

Documentation

Index

Constants

View Source
const (
	BucketSize  = 20
	AddrTimeout = 24 * time.Hour
)
View Source
const (
	VersionSeparator = '.'
)

Variables

View Source
var (
	ErrNoSeparator = errors.New("no separator")
)

Functions

This section is empty.

Types

type Address

type Address struct {
	// contains filtered or unexported fields
}

func NewAddressV1

func NewAddressV1(key ecdh.PublicKey) Address

NewAddressV1 creates a new version 1 address from the ecdh.PublicKey.

func ParseAddress

func ParseAddress(s string) (a Address, err error)

ParseAddress parses a string representation of an address into an address.

func (Address) MarshalBinary

func (a Address) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler.

func (Address) MarshalText

func (a Address) MarshalText() (data []byte, err error)

MarshalText implements encoding.TextMarshaler.

func (Address) String

func (a Address) String() string

String returns the string representation of the address in the following format:

wn<version>.<encoded bytes>

For example:

wn1.ybndrfg8ejkmcpqxot1uwisza345h769

func (*Address) UnmarshalBinary

func (a *Address) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(data []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Address) Version

func (a Address) Version() int

type Distance

type Distance struct {
	// contains filtered or unexported fields
}

Distance represents a distance between two addresses.

func Dist

func Dist(a1, a2 Address) Distance

Dist returns the distance between two Addresses as a new Distance.

The order of the arguments has no effect on the output, so that:

Dist(a1, a2) == Dist(a2, a1)

func (Distance) Less

func (d Distance) Less(other Distance) bool

Less returns true if the distance is less than the other Distance.

type Node

type Node struct {
	// contains filtered or unexported fields
}

func NewNode

func NewNode(address Address) (*Node, error)

NewNode creates a new node.

func (*Node) Add

func (n *Node) Add(addr Address, ip []net.IPAddr)

Add adds the address to one of the Node's buckets.

func (*Node) Neighbors

func (n *Node) Neighbors(address Address) []PeerInfo

Neighbors returns the k closest nodes to the Node.

func (*Node) String

func (n *Node) String() string

String returns the string representation of the node.

type PeerInfo

type PeerInfo struct {
	Addr Address
	IP   []net.IPAddr
}

PeerInfo is a type that bundles together an Address and the IP addresses associated with it.

Jump to

Keyboard shortcuts

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