idgen

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HydraIdentityGenerator = NewBalancedIdentityGenerator()

HydraIdentityGenerator is a shared balanced ID generator.

Functions

func TrieKeyEqual

func TrieKeyEqual(x, y TrieKey) bool

Types

type BalancedIdentityGenerator

type BalancedIdentityGenerator struct {
	sync.Mutex
	// contains filtered or unexported fields
}

BalancedIdentityGenerator is a facility for generating IPFS identities (i.e. IPFS private keys), whose corresponding DHT keys are highly balanced, compared to just generating random keys. Balancing is accomplished using "the power of two choices" paradigm: https://www.eecs.harvard.edu/~michaelm/postscripts/mythesis.pdf

New identities are generated by calling AddBalanced. BalancedIdentityGenerator remembers generated identities, in order to ensure balance for future identities. Generated identities can be removed using Remove.

BalancedIdentityGenerator maintains the invariant that all identities, presently in its memory, form an almost-perfectly balanced set.

func NewBalancedIdentityGenerator

func NewBalancedIdentityGenerator() *BalancedIdentityGenerator

NewBalancedIdentityGenerator creates a new balanced identity generator.

func (*BalancedIdentityGenerator) AddBalanced

func (bg *BalancedIdentityGenerator) AddBalanced() (crypto.PrivKey, error)

AddBalanced generates a random identity, which is balanced with respect to the existing identities in the generator. The generated identity is stored in the generator's memory.

func (*BalancedIdentityGenerator) AddUnbalanced

func (bg *BalancedIdentityGenerator) AddUnbalanced() (crypto.PrivKey, error)

AddUnbalanced is used for testing purposes. It generates a purely random identity, which is not balanced with respect to the existing identities in the generator. The generated identity is stored in the generator's memory.

func (*BalancedIdentityGenerator) Count

func (bg *BalancedIdentityGenerator) Count() int

func (*BalancedIdentityGenerator) Depth

func (bg *BalancedIdentityGenerator) Depth() int

func (*BalancedIdentityGenerator) Remove

func (bg *BalancedIdentityGenerator) Remove(privKey crypto.PrivKey) error

Remove removes a previously generated identity from the generator's memory.

type TrieKey

type TrieKey []byte

TrieKey is a vector of bits backed by a Go byte slice in big endian byte order and big-endian bit order.

func (TrieKey) BitAt

func (bs TrieKey) BitAt(offset int) byte

func (TrieKey) BitLen

func (bs TrieKey) BitLen() int

type XorTrie

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

XorTrie is a trie for equal-length bit vectors, which stores values only in the leaves.

func NewXorTrie

func NewXorTrie() *XorTrie

func (*XorTrie) Depth

func (trie *XorTrie) Depth() int

func (*XorTrie) Insert

func (trie *XorTrie) Insert(q TrieKey) (insertedDepth int, insertedOK bool)

func (*XorTrie) Remove

func (trie *XorTrie) Remove(q TrieKey) (removedDepth int, removed bool)

Jump to

Keyboard shortcuts

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