memdb

package
Version: v0.0.0-...-62b55fc Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2016 License: ISC Imports: 11 Imported by: 0

Documentation

Overview

Package memdb implements an instance of the database package that uses memory for object storage.

This is primary used for testing purposes as normal operations require a persistent object storage mechanism which this is not.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenDB

func OpenDB(args ...interface{}) (database.Db, error)

OpenDB opens a database, initializing it if necessary.

Types

type MemDb

type MemDb struct {
	// Embed a mutex for safe concurrent access.
	sync.RWMutex
	// contains filtered or unexported fields
}

MemDb is a concrete implementation of the database.Db interface which provides a memory-only database. Since it is memory-only, it is obviously not persistent and is mostly only useful for testing purposes.

func (*MemDb) Close

func (db *MemDb) Close() error

Close cleanly shuts down database. This is part of the database.Db interface implementation.

All data is purged upon close with this implementation since it is a memory-only database.

func (*MemDb) ExistsObject

func (db *MemDb) ExistsObject(hash *wire.ShaHash) (bool, error)

ExistsObject returns whether or not an object with the given inventory hash exists in the database. This is part of the database.Db interface implementation.

func (*MemDb) FetchIdentityByAddress

func (db *MemDb) FetchIdentityByAddress(addr *bmutil.Address) (*identity.Public,
	error)

FetchIdentityByAddress returns identity.Public stored in the form of a PubKey message in the pubkey database. It needs to go through all the public keys in the database to find this. The implementation must thus cache results, if needed. This is part of the database.Db interface implementation.

func (*MemDb) FetchObjectByCounter

func (db *MemDb) FetchObjectByCounter(objType wire.ObjectType,
	counter uint64) (*wire.MsgObject, error)

FetchObjectByCounter returns an object from the database as a byte array based on the object type and counter value. The implementation may cache the underlying data if desired. This is part of the database.Db interface implementation.

func (*MemDb) FetchObjectByHash

func (db *MemDb) FetchObjectByHash(hash *wire.ShaHash) (*wire.MsgObject, error)

FetchObjectByHash returns an object from the database as a wire.MsgObject.

func (*MemDb) FetchObjectsFromCounter

func (db *MemDb) FetchObjectsFromCounter(objType wire.ObjectType, counter uint64,
	count uint64) ([]database.ObjectWithCounter, uint64, error)

FetchObjectsFromCounter returns a slice of `count' objects which have a counter position starting from `counter'. It also returns the counter value of the last object, which could be useful for more queries to the function. This is part of the database.Db interface implementation.

func (*MemDb) FetchRandomInvHashes

func (db *MemDb) FetchRandomInvHashes(count uint64) ([]*wire.InvVect, error)

FetchRandomInvHashes returns the specified number of inventory hashes corresponding to random unexpired objects from the database.

This is part of the database.Db interface implementation.

func (*MemDb) GetCounter

func (db *MemDb) GetCounter(objType wire.ObjectType) (uint64, error)

GetCounter returns the highest value of counter that exists for objects of the given type. This is part of the database.Db interface implementation.

func (*MemDb) InsertObject

func (db *MemDb) InsertObject(obj *wire.MsgObject) (uint64, error)

InsertObject inserts data of the given type and hash into the database. It returns the calculated/stored inventory hash as well as the counter position (if object type has a counter associated with it). If the object is a PubKey, it inserts it into a separate place where it isn't touched by RemoveObject or RemoveExpiredObjects and has to be removed using RemovePubKey. This is part of the database.Db interface implementation.

func (*MemDb) RemoveEncryptedPubKey

func (db *MemDb) RemoveEncryptedPubKey(tag *wire.ShaHash) error

RemoveEncryptedPubKey removes a v4 PubKey with the specified tag from the encrypted PubKey store. Note that it doesn't touch the general object store and won't remove the public key from there. This is part of the database.Db interface implementation.

func (*MemDb) RemoveExpiredObjects

func (db *MemDb) RemoveExpiredObjects() ([]*wire.ShaHash, error)

RemoveExpiredObjects prunes all objects in the main circulation store whose expiry time has passed (along with a margin of 3 hours). This does not touch the pubkeys stored in the public key collection. This is part of the database.Db interface implementation.

func (*MemDb) RemoveObject

func (db *MemDb) RemoveObject(hash *wire.ShaHash) error

RemoveObject removes the object with the specified hash from the database. This is part of the database.Db interface implementation.

func (*MemDb) RemoveObjectByCounter

func (db *MemDb) RemoveObjectByCounter(objType wire.ObjectType,
	counter uint64) error

RemoveObjectByCounter removes the object with the specified counter value from the database. This is part of the database.Db interface implementation.

func (*MemDb) RemovePublicIdentity

func (db *MemDb) RemovePublicIdentity(addr *bmutil.Address) error

RemovePublicIdentity removes the public identity corresponding the given address from the database. This includes any v2/v3/previously used v4 identities. Note that it doesn't touch the general object store and won't remove the public key object from there. This is part of the database.Db interface implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL