utility

package
v4.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: BSD-2-Clause, BSD-2-Clause Imports: 23 Imported by: 1

Documentation

Index

Constants

View Source
const CurrentMessageBufferVersion = 0

Version of the file saved to the key value store

Variables

This section is empty.

Functions

func DeleteCID

func DeleteCID(kv *versioned.KV, key string) error

DeleteCID deletes a given cyclic key from storage

func DeleteContact

func DeleteContact(kv *versioned.KV, cid *id.ID) error

DeleteContact removes the contact identified by cid from the kv.

Parameters:

  • kv - the key value store to delete from
  • cid - the contacts unique *id.ID to delete

Returns:

  • error if an error occurs or nil otherwise

func DeleteCyclicKey

func DeleteCyclicKey(kv *versioned.KV, key string) error

DeleteCyclicKey deletes a given cyclic key from storage

func DeleteSIDHPrivateKey

func DeleteSIDHPrivateKey(kv *versioned.KV, key string) error

DeleteSIDHPrivateKey removes the key from the store

func DeleteSIDHPublicKey

func DeleteSIDHPublicKey(kv *versioned.KV, key string) error

DeleteSIDHPubKey removes the key from the store

func GenerateSIDHKeyPair

func GenerateSIDHKeyPair(variant sidh.KeyVariant, rng io.Reader) (
	*sidh.PrivateKey, *sidh.PublicKey)

GenerateSIDHKeyPair generates a SIDH keypair

func GetCompatibleSIDHVariant

func GetCompatibleSIDHVariant(otherVariant sidh.KeyVariant) sidh.KeyVariant

GetSIDHVariant returns the variant opposite the otherVariant

func LoadBucket

func LoadBucket(capacity, leaked uint32, leakDuration time.Duration,
	kv *versioned.KV) (*rateLimiting.Bucket, error)

LoadBucket is a storage operation which loads a bucket from storage.

func LoadContact

func LoadContact(kv *versioned.KV, cid *id.ID) (contact.Contact, error)

LoadContact reads a contact from a versioned.KV vie their contact ID.

Parameters:

  • kv - the key value store to read the contact
  • cid - the contacts unique *id.ID to load

Returns:

  • contact.Contact object populated with the user info, or empty on error.
  • version number of the contact loaded.
  • error if an error occurs, or nil otherwise

func LoadCyclicKey

func LoadCyclicKey(kv *versioned.KV, key string) (*cyclic.Int, error)

func LoadGroup

func LoadGroup(kv *versioned.KV, key string) (*cyclic.Group, error)

func LoadID

func LoadID(kv *versioned.KV, key string) (*id.ID, error)

func LoadNDF

func LoadNDF(kv *versioned.KV, key string) (*ndf.NetworkDefinition, error)

func LoadSIDHPrivateKey

func LoadSIDHPrivateKey(kv *versioned.KV, key string) (*sidh.PrivateKey, error)

LoadSIDHPrivateKeyA loads a public key from storage.

func LoadSIDHPublicKey

func LoadSIDHPublicKey(kv *versioned.KV, key string) (*sidh.PublicKey, error)

LoadSIDHPubKeyA loads a public key from storage.

func MakeSIDHPrivateKeyKey

func MakeSIDHPrivateKeyKey(cid *id.ID) string

func MakeSIDHPublicKeyKey

func MakeSIDHPublicKeyKey(cid *id.ID) string

func MakeStoredMessageKey

func MakeStoredMessageKey(key string, h MessageHash) string

MakeStoredMessageKey generates a new key for the message based on its has.

func NewOrLoadSalt

func NewOrLoadSalt(kv *versioned.KV, stream io.Reader) ([]byte, error)

NewOrLoadSalt will attempt to find a stored salt if one exists. If one does not exist in storage, a new one will be generated. The newly generated salt will be stored.

func NewSIDHPrivateKey

func NewSIDHPrivateKey(variant sidh.KeyVariant) *sidh.PrivateKey

NewSIDHPUblicKey is a helper which returns a proper new SIDH public key Right now this is set to Fp434 but it could change.

func NewSIDHPublicKey

func NewSIDHPublicKey(variant sidh.KeyVariant) *sidh.PublicKey

NewSIDHPUblicKey is a helper which returns a proper new SIDH public key Right now this is set to Fp434 but it could change.

func NewStoredBucket

func NewStoredBucket(capacity, leaked uint32, leakDuration time.Duration,
	kv *versioned.KV) *rateLimiting.Bucket

NewStoredBucket creates a new, empty Bucket and saves it to storage.

func SaveNDF

func SaveNDF(kv *versioned.KV, key string, ndf *ndf.NetworkDefinition) error

func StoreContact

func StoreContact(kv *versioned.KV, c contact.Contact) error

StoreContact writes a contact into a versioned.KV using the contact ID as the key.

Parameters:

  • kv - the key value store to write the contact.
  • c - the contact object to store.

Returns:

  • error if the write fails to succeed for any reason.

func StoreCyclicKey

func StoreCyclicKey(kv *versioned.KV, cy *cyclic.Int, key string) error

func StoreGroup

func StoreGroup(kv *versioned.KV, grp *cyclic.Group, key string) error

func StoreID

func StoreID(kv *versioned.KV, sid *id.ID, key string) error

func StoreSIDHPrivateKey

func StoreSIDHPrivateKey(kv *versioned.KV, sidH *sidh.PrivateKey, key string) error

StoreSIDHPrivateKeyA is a helper to store the requestor public key (which is always of type A)

func StoreSIDHPublicKey

func StoreSIDHPublicKey(kv *versioned.KV, sidH *sidh.PublicKey, key string) error

StoreSIDHPubKeyA is a helper to store the requestor public key (which is always of type A)

func StringSIDHPrivKey

func StringSIDHPrivKey(k *sidh.PrivateKey) string

String interface to dump the contents of the public key as b64 string NOTE: public key, not the private. We don't ever want to drop a private key into a log somewhere.

func StringSIDHPubKey

func StringSIDHPubKey(k *sidh.PublicKey) string

String interface impl to dump the contents of the public key as b64 string

Types

type BlockStore

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

func LoadBlockStore

func LoadBlockStore(kv *versioned.KV) (*BlockStore, [][]byte, error)

LoadBlockStore returns the BlockStore from storage and a concatenation of all blocks in storage.

func NewBlockStore

func NewBlockStore(numBlocks, blockSize int, kv *versioned.KV) (*BlockStore, error)

NewBlockStore returns a new BlockStore and saves it to storage.

func (*BlockStore) Store

func (bs *BlockStore) Store(iter Iterator) error

Store stores all items in the Iterator to storage in blocks.

type BucketParamStore

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

BucketParamStore is the storage object for bucket params. Updated via the network follower.

func LoadBucketParamsStore

func LoadBucketParamsStore(kv *versioned.KV) (*BucketParamStore, error)

LoadBucketParamsStore loads the bucket params data from storage and constructs a BucketParamStore.

func NewBucketParamsStore

func NewBucketParamsStore(capacity, leakedTokens uint32,
	leakDuration time.Duration, kv *versioned.KV) (*BucketParamStore, error)

NewBucketParamsStore is the constructor for a BucketParamStore.

func (*BucketParamStore) Get

Get reads and returns te bucket params.

func (*BucketParamStore) UpdateParams

func (s *BucketParamStore) UpdateParams(capacity, leakedTokens uint32,
	leakDuration time.Duration) error

UpdateParams updates the parameters to store.

type BucketStore

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

BucketStore stores a leaky bucket into storage. The bucket is saved in a JSON-able format.

type Iterator

type Iterator interface {
	Next() ([]byte, bool)
}

type MessageBuffer

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

MessageBuffer holds a list of messages in the "not processed" or "processing" state both in memory. Messages in the "not processed" state are held in the messages map and messages in the "processing" state are moved into the processingMessages map. When the message is done being processed, it is removed from the buffer. The actual messages are saved in the key value store along with a copy of the buffer that is held in memory.

func LoadMessageBuffer

func LoadMessageBuffer(kv *versioned.KV, handler MessageHandler,
	key string) (*MessageBuffer, error)

LoadMessageBuffer loads an existing message buffer from the key value store into memory at the given key. Returns an error if buffer cannot be loaded.

func NewMessageBuffer

func NewMessageBuffer(kv *versioned.KV, handler MessageHandler,
	key string) (*MessageBuffer, error)

NewMessageBuffer creates a new empty buffer and saves it to the passed in key value store at the specified key. An error is returned on an unsuccessful save.

func (*MessageBuffer) Add

func (mb *MessageBuffer) Add(m interface{}) interface{}

Add adds a message to the buffer in "not processing" state.

func (*MessageBuffer) AddProcessing

func (mb *MessageBuffer) AddProcessing(m interface{}) interface{}

Add adds a message to the buffer in "processing" state.

func (*MessageBuffer) Failed

func (mb *MessageBuffer) Failed(m interface{})

Failed sets a message as failed to process. It changes the message back to the "not processed" state.

func (*MessageBuffer) GetMessages

func (mb *MessageBuffer) GetMessages() map[MessageHash]struct{}

GetMessages is a getter function which retrieves the MessageBuffer.messages map.

func (*MessageBuffer) GetProcessingMessages

func (mb *MessageBuffer) GetProcessingMessages() map[MessageHash]struct{}

GetProcessingMessages is a getter function which retrieves the MessageBuffer.processingMessages map.

func (*MessageBuffer) Next

func (mb *MessageBuffer) Next() (interface{}, bool)

Next gets the next message from the buffer whose state is "not processing". The returned messages are moved to the processing state. If there are no messages remaining, then false is returned.

func (*MessageBuffer) Succeeded

func (mb *MessageBuffer) Succeeded(m interface{})

Remove sets a messaged as processed and removed it from the buffer.

type MessageHandler

type MessageHandler interface {
	// SaveMessage saves the message as a versioned object at the specified key
	// in the key value store.
	SaveMessage(kv *versioned.KV, m interface{}, key string) error

	// LoadMessage returns the message with the specified key from the key value
	// store.
	LoadMessage(kv *versioned.KV, key string) (interface{}, error)

	// DeleteMessage deletes the message with the specified key from the key
	// value store.
	DeleteMessage(kv *versioned.KV, key string) error

	// HashMessage generates a hash of the message.
	HashMessage(m interface{}) MessageHash
}

MessageHandler interface used to handle the passed in message type so the buffer can be used at different layers of the stack.

type MessageHash

type MessageHash [16]byte

MessageHash stores the hash of a message, which is used as the key for each message stored in the buffer.

func (MessageHash) String

func (m MessageHash) String() string

type MultiStateVector

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

MultiStateVector stores a list of a set number of keys and their state. It supports any number of states, unlike the StateVector. It is storage backed.

func LoadMultiStateVector

func LoadMultiStateVector(stateMap [][]bool, key string, kv *versioned.KV) (
	*MultiStateVector, error)

LoadMultiStateVector loads a MultiStateVector with the specified key from the given versioned storage.

func NewMultiStateVector

func NewMultiStateVector(numKeys uint16, numStates uint8, stateMap [][]bool,
	key string, kv *versioned.KV) (*MultiStateVector, error)

NewMultiStateVector generates a new MultiStateVector with the specified number of keys and bits pr state per keys. The max number of states in 64.

func (*MultiStateVector) DeepCopy

func (msv *MultiStateVector) DeepCopy() *MultiStateVector

DeepCopy creates a deep copy of the MultiStateVector without a storage backend. The deep copy can only be used for functions that do not access storage.

func (*MultiStateVector) Delete

func (msv *MultiStateVector) Delete() error

Delete removes the MultiStateVector from storage.

func (*MultiStateVector) Get

func (msv *MultiStateVector) Get(keyNum uint16) (uint8, error)

Get returns the state of the key.

func (*MultiStateVector) GetCount

func (msv *MultiStateVector) GetCount(state uint8) (uint16, error)

GetCount returns the number of keys with the given state.

func (*MultiStateVector) GetKeys

func (msv *MultiStateVector) GetKeys(state uint8) ([]uint16, error)

GetKeys returns a list of all keys with the specified status.

func (*MultiStateVector) GetNumKeys

func (msv *MultiStateVector) GetNumKeys() uint16

GetNumKeys returns the total number of keys.

func (*MultiStateVector) Set

func (msv *MultiStateVector) Set(keyNum uint16, state uint8) error

Set marks the key with the given state. Returns an error for an invalid state or if the state change is not allowed.

func (*MultiStateVector) SetMany

func (msv *MultiStateVector) SetMany(keyNums []uint16, state uint8) error

SetMany marks each of the keys with the given state. Returns an error for an invalid state or if the state change is not allowed.

type StateVector

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

StateVector stores a list of a set number of items and their binary state. It is storage backed.

func LoadStateVector

func LoadStateVector(kv *versioned.KV, key string) (*StateVector, error)

LoadStateVector loads a StateVector with the specified key from the given versioned storage.

func NewStateVector

func NewStateVector(kv *versioned.KV, key string, numKeys uint32) (
	*StateVector, error)

NewStateVector generates a new StateVector with the specified number of keys.

func (*StateVector) DeepCopy

func (sv *StateVector) DeepCopy() *StateVector

DeepCopy creates a deep copy of the StateVector without a storage backend. The deep copy can only be used for functions that do not access storage.

func (*StateVector) Delete

func (sv *StateVector) Delete() error

Delete remove the StateVector from storage.

func (*StateVector) GetNumAvailable

func (sv *StateVector) GetNumAvailable() uint32

GetNumAvailable returns the number of unused keys.

func (*StateVector) GetNumKeys

func (sv *StateVector) GetNumKeys() uint32

GetNumKeys returns the total number of keys.

func (*StateVector) GetNumUsed

func (sv *StateVector) GetNumUsed() uint32

GetNumUsed returns the number of used keys.

func (*StateVector) GetUnusedKeyNums

func (sv *StateVector) GetUnusedKeyNums() []uint32

GetUnusedKeyNums returns a list of all unused keys.

func (*StateVector) GetUsedKeyNums

func (sv *StateVector) GetUsedKeyNums() []uint32

GetUsedKeyNums returns a list of all used keys.

func (*StateVector) GoString

func (sv *StateVector) GoString() string

GoString returns the fields of the StateVector. This functions satisfies the fmt.GoStringer interface.

func (*StateVector) Next

func (sv *StateVector) Next() (uint32, error)

Next marks the first unused key as used. An error is returned if all keys are used or if the save to storage fails.

func (*StateVector) SaveTEST

func (sv *StateVector) SaveTEST(x interface{}) error

SaveTEST saves the StateVector to storage. This should only be used for testing.

func (*StateVector) SetFirstAvailableTEST

func (sv *StateVector) SetFirstAvailableTEST(keyNum uint32, x interface{})

SetFirstAvailableTEST sets the firstAvailable. This should only be used for testing.

func (*StateVector) SetKvTEST

func (sv *StateVector) SetKvTEST(kv *versioned.KV, x interface{})

SetKvTEST sets the kv. This should only be used for testing.

func (*StateVector) SetNumAvailableTEST

func (sv *StateVector) SetNumAvailableTEST(numAvailable uint32, x interface{})

SetNumAvailableTEST sets the numAvailable. This should only be used for testing.

func (*StateVector) SetNumKeysTEST

func (sv *StateVector) SetNumKeysTEST(numKeys uint32, x interface{})

SetNumKeysTEST sets the numKeys. This should only be used for testing.

func (*StateVector) String

func (sv *StateVector) String() string

String returns a unique string representing the StateVector. This functions satisfies the fmt.Stringer interface.

func (*StateVector) Unuse

func (sv *StateVector) Unuse(keyNum uint32)

Unuse marks the key as unused (sets it to 0).

func (*StateVector) UnuseMany

func (sv *StateVector) UnuseMany(keyNums ...uint32)

UnuseMany marks all the key as unused (sets them to 0). Saves only after all of the keys are set.

func (*StateVector) Use

func (sv *StateVector) Use(keyNum uint32)

Use marks the key as used (sets it to 1).

func (*StateVector) UseMany

func (sv *StateVector) UseMany(keyNums ...uint32)

UseMany marks all of the keys as used (sets them to 1). Saves only after all of the keys are set.

func (*StateVector) Used

func (sv *StateVector) Used(keyNum uint32) bool

Used returns true if the key is used (set to 1) or false if the key is unused (set to 0).

Jump to

Keyboard shortcuts

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