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 ¶
- func OpenDB(args ...interface{}) (database.Db, error)
- type MemDb
- func (db *MemDb) Close() error
- func (db *MemDb) ExistsObject(hash *wire.ShaHash) (bool, error)
- func (db *MemDb) FetchIdentityByAddress(addr *bmutil.Address) (*identity.Public, error)
- func (db *MemDb) FetchObjectByCounter(objType wire.ObjectType, counter uint64) (*wire.MsgObject, error)
- func (db *MemDb) FetchObjectByHash(hash *wire.ShaHash) (*wire.MsgObject, error)
- func (db *MemDb) FetchObjectsFromCounter(objType wire.ObjectType, counter uint64, count uint64) ([]database.ObjectWithCounter, uint64, error)
- func (db *MemDb) FetchRandomInvHashes(count uint64) ([]*wire.InvVect, error)
- func (db *MemDb) GetCounter(objType wire.ObjectType) (uint64, error)
- func (db *MemDb) InsertObject(obj *wire.MsgObject) (uint64, error)
- func (db *MemDb) RemoveEncryptedPubKey(tag *wire.ShaHash) error
- func (db *MemDb) RemoveExpiredObjects() ([]*wire.ShaHash, error)
- func (db *MemDb) RemoveObject(hash *wire.ShaHash) error
- func (db *MemDb) RemoveObjectByCounter(objType wire.ObjectType, counter uint64) error
- func (db *MemDb) RemovePublicIdentity(addr *bmutil.Address) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.