kadt

package
v0.0.0-...-e07b07e Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package kadt contains the kademlia types for interacting with go-libdht.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddrInfo

type AddrInfo struct {
	Info peer.AddrInfo
}

AddrInfo is a type that wraps peer.AddrInfo and implements the kad.NodeInfo interface. This means we can use AddrInfo for any operation that interfaces with go-libdht.

A more accurate name would be PeerInfo or NodeInfo. However, for consistency and coherence with peer.AddrInfo we also name it AddrInfo.

func (AddrInfo) Addresses

func (ai AddrInfo) Addresses() []ma.Multiaddr

Addresses returns all Multiaddresses of this peer.

func (AddrInfo) ID

func (ai AddrInfo) ID() kad.NodeID[Key]

ID returns the kad.NodeID of this peer's information struct.

func (AddrInfo) PeerID

func (ai AddrInfo) PeerID() PeerID

PeerID returns the peer ID of this peer's information struct as a PeerID.

type Key

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

Key is a type alias for the type of key that's used with this DHT implementation. In the Amino DHT, we are sending around the preimage of the actual key that's used for calculating Kademlia distance. That's why this Key struct also holds the preimage bytes.

func NewKey

func NewKey(preimage []byte) Key

NewKey initializes a new key struct based on the given preimage bytes. These bytes are SHA256 hashed and stored as the actual Kademlia key that's used to calculate distances in the XOR keyspace.

func (Key) Bit

func (k Key) Bit(i int) uint

func (Key) BitLen

func (k Key) BitLen() int

func (Key) CommonPrefixLength

func (k Key) CommonPrefixLength(other Key) int

func (Key) Compare

func (k Key) Compare(other Key) int

func (Key) HexString

func (k Key) HexString() string

HexString returns a string containing the hexadecimal representation of the key.

func (Key) MsgKey

func (k Key) MsgKey() []byte

MsgKey returns the bytes that should be used inside Kademlia RPC messages. The returned value is the preimage to the actual Kademlia key. To arrive at the Kademlia key, these MsgKey bytes must be SHA256 hashed

func (Key) Xor

func (k Key) Xor(other Key) Key

type PeerID

type PeerID peer.ID

PeerID is a type alias for peer.ID that implements the kad.NodeID interface. This means we can use PeerID for any operation that interfaces with go-libdht.

func (PeerID) Equal

func (p PeerID) Equal(o PeerID) bool

Equal compares the PeerID with another by comparing the underlying peer.ID.

func (PeerID) Key

func (p PeerID) Key() Key

Key returns the Kademlia [KadKey] of PeerID. The amino DHT operates on SHA256 hashes of, in this case, peer.IDs. This means this Key method takes the peer.ID, hashes it and constructs a 256-bit key.

func (PeerID) String

func (p PeerID) String() string

String calls String on the underlying peer.ID and returns a string like QmFoo or 12D3KooBar.

type RoutingTable

type RoutingTable interface {
	kad.RoutingTable[Key, PeerID]

	// Cpl returns the longest common prefix length the supplied key shares with the table's key.
	Cpl(kk Key) int

	// CplSize returns the number of nodes in the table whose longest common prefix with the table's key is of length cpl.
	CplSize(cpl int) int
}

RoutingTable is a mapping between Key and PeerID and provides methods to interact with the mapping and find PeerIDs close to a particular Key.

Jump to

Keyboard shortcuts

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