kadtest

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: Apache-2.0, MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ctx

Ctx returns a Context and a CancelFunc. The context will be cancelled just before the test binary deadline (as specified by the -timeout flag when running the test). The CancelFunc may be called to cancel the context earlier than the deadline.

func Key256WithLeadingBytes

func Key256WithLeadingBytes(in []byte) bit256.Key

Key256WithLeadingBytes returns a 256-bit Kademlia key consisting of the given leading bytes padded by zero bytes to the end of the key.

func ReportTimePerItemMetric

func ReportTimePerItemMetric(b *testing.B, n int, name string)

ReportTimePerItemMetric adds a custom metric to a benchmark that reports the number of nanoseconds taken per item.

Types

type ID

type ID[K kad.Key[K]] struct {
	// contains filtered or unexported fields
}

ID is a concrete implementation of the NodeID interface.

func NewID

func NewID[K kad.Key[K]](k K) *ID[K]

NewID returns a new Kademlia identifier that implements the NodeID interface. Instead of deriving the Kademlia key from a NodeID, this method directly takes the Kademlia key.

func (ID[K]) Equal

func (i ID[K]) Equal(other K) bool

func (ID[K]) Key

func (i ID[K]) Key() K

Key returns the Kademlia key that is used by, e.g., the routing table implementation to group nodes into buckets. The returned key was manually defined in the ID constructor NewID and not derived via, e.g., hashing a preimage.

func (ID[K]) String

func (i ID[K]) String() string

type Key8

type Key8 uint8

Key8 is an 8-bit Kademlia key, suitable for testing and simulation of very small networks.

func (Key8) Bit

func (k Key8) Bit(i int) uint

Bit returns the value of the i'th bit of the key from most significant to least.

func (Key8) BitLen

func (Key8) BitLen() int

BitLen returns the length of the key in bits, which is always 8.

func (Key8) BitString

func (k Key8) BitString() string

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

func (Key8) CommonPrefixLength

func (k Key8) CommonPrefixLength(o Key8) int

CommonPrefixLength returns the number of leading bits the key shares with another key of the same type.

func (Key8) Compare

func (k Key8) Compare(o Key8) int

Compare compares the numeric value of the key with another key of the same type.

func (Key8) HexString

func (k Key8) HexString() string

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

func (Key8) String

func (k Key8) String() string

func (Key8) Xor

func (k Key8) Xor(o Key8) Key8

Xor returns the result of the eXclusive OR operation between the key and another key of the same type.

type Key32

type Key32 uint32

Key32 is a 32-bit Kademlia key, suitable for testing and simulation of small networks.

func RandomKey

func RandomKey() Key32

RandomKey returns a random 32-bit Kademlia key.

func RandomKeyWithPrefix

func RandomKeyWithPrefix(s string) Key32

RandomKeyWithPrefix returns a 32-bit Kademlia key having a prefix equal to the bit pattern held in s and random following bits. A prefix of up to 32 bits is supported.

func (Key32) Bit

func (k Key32) Bit(i int) uint

Bit returns the value of the i'th bit of the key from most significant to least.

func (Key32) BitLen

func (Key32) BitLen() int

BitLen returns the length of the key in bits, which is always 32.

func (Key32) BitString

func (k Key32) BitString() string

BitString returns a string containing the binary representation of the key.

func (Key32) CommonPrefixLength

func (k Key32) CommonPrefixLength(o Key32) int

CommonPrefixLength returns the number of leading bits the key shares with another key of the same type.

func (Key32) Compare

func (k Key32) Compare(o Key32) int

Compare compares the numeric value of the key with another key of the same type.

func (Key32) HexString

func (k Key32) HexString() string

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

func (Key32) String

func (k Key32) String() string

func (Key32) Xor

func (k Key32) Xor(o Key32) Key32

Xor returns the result of the eXclusive OR operation between the key and another key of the same type.

type StringID

type StringID string

func NewStringID

func NewStringID(s string) *StringID

func (StringID) Equal

func (s StringID) Equal(other string) bool

func (StringID) Key

func (s StringID) Key() bit256.Key

func (StringID) NodeID

func (s StringID) NodeID() kad.NodeID[bit256.Key]

func (StringID) String

func (s StringID) String() string

Jump to

Keyboard shortcuts

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