idgen

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 11 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 CleaningIDGenerator added in v0.2.0

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

CleaningIDGenerator is an identity generator that provides an extra method to remove all previously generated identities without passing any arguments.

func NewCleaningIDGenerator added in v0.2.0

func NewCleaningIDGenerator(idgen IdentityGenerator) *CleaningIDGenerator

NewCleaningIDGenerator creates a new delegated identity generator that provides an extra method to remove all previously generated identities without passing any arguments.

func (*CleaningIDGenerator) AddBalanced added in v0.2.0

func (c *CleaningIDGenerator) AddBalanced() (crypto.PrivKey, error)

AddBalanced stores the result of calling AddBalanced on the underlying identify generator and then returns it.

func (*CleaningIDGenerator) Clean added in v0.2.0

func (c *CleaningIDGenerator) Clean() error

Clean removes ALL previously generated keys by calling Remove on the underlying identity generator for each key in it's memory.

func (*CleaningIDGenerator) Remove added in v0.2.0

func (c *CleaningIDGenerator) Remove(privKey crypto.PrivKey) error

Remove calls Remove on the underlying identity generator and also removes the passed key from it's memory of keys generated.

type DelegatedIDGenerator added in v0.2.0

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

DelegatedIDGenerator is an identity generator whose work is delegated to another worker.

func NewDelegatedIDGenerator added in v0.2.0

func NewDelegatedIDGenerator(addr string) *DelegatedIDGenerator

NewDelegatedIDGenerator creates a new delegated identity generator whose work is delegated to another worker. The delegate must be reachable on the passed HTTP address and respond to HTTP POST messages sent to the following endpoints: `/idgen/add` - returns a JSON string, a base64 encoded private key. `/idgen/remove` - accepts a JSON string, a base64 encoded private key.

func (*DelegatedIDGenerator) AddBalanced added in v0.2.0

func (g *DelegatedIDGenerator) AddBalanced() (crypto.PrivKey, error)

AddBalanced generates a balanced random identity by sending a HTTP POST request to `/idgen/add`.

func (*DelegatedIDGenerator) Remove added in v0.2.0

func (g *DelegatedIDGenerator) Remove(privKey crypto.PrivKey) error

Remove removes a previously generated identity by sending a HTTP POST request to `/idgen/remove`.

type IdentityGenerator added in v0.2.0

type IdentityGenerator interface {
	AddBalanced() (crypto.PrivKey, error)
	Remove(privKey crypto.PrivKey) error
}

IdentityGenerator describes a facility that can generate IPFS private keys.

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