keystore

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0, MIT Imports: 6 Imported by: 0

Documentation

Overview

Package keystore holds the keys a node provides, enumerable by prefix so a region publish can find every key that falls inside a surveyed region. It provides the Keystore contract and an in-memory Trie implementation of it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Keystore

type Keystore[K kad.Key[K]] interface {
	// KeysUnder yields every provided key whose leading bits equal prefix. The empty prefix yields
	// every key.
	KeysUnder(prefix bitstr.Key) iter.Seq[K]
}

Keystore enumerates the keys a node provides by prefix, so a region publish can find every key inside a surveyed region. An implementation must be safe for concurrent use: KeysUnder is called on the event loop while the provide path records keys. The in-memory Trie is the default; a driver may instead read from its own persistent datastore.

type Trie

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

Trie is an in-memory Keystore backed by a binary trie. It is safe for concurrent use: a read takes a lock-free snapshot of the trie while a write rebuilds the changed path and swaps the root in atomically.

func New

func New[K kad.Key[K]]() *Trie[K]

New returns an empty Trie.

func (*Trie[K]) Add

func (t *Trie[K]) Add(k K)

Add records a key this node provides. Adding a key already present has no effect.

func (*Trie[K]) KeysUnder

func (t *Trie[K]) KeysUnder(prefix bitstr.Key) iter.Seq[K]

KeysUnder yields every stored key whose leading bits equal prefix. The empty prefix yields every key. The sequence walks a snapshot taken when KeysUnder is called, so a concurrent Add or Remove does not affect it.

func (*Trie[K]) Remove

func (t *Trie[K]) Remove(k K)

Remove drops a key. Removing a key that is absent has no effect.

Jump to

Keyboard shortcuts

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