bdb

package
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: 14 Imported by: 0

Documentation

Overview

Package bdb implements an instance of the database package backed by BoltDB. The structure of the database is: - objectsByHashes (bucket) -- Inventory hash (32 bytes) -> Object data

- objectsByCounters (bucket) -- Getpubkey/Pubkey/Msg/Broadcast/Unknown (bucket) --- Counter value (uint64) -> Inventory hash (32 bytes)

- counterPositions (bucket) -- Getpubkey/Pubkey/Msg/Broadcast/Unknown -> uint64

- encryptedPubkeysByTag (bucket) -- Tag (32 bytes) -> Encrypted pubkey

- publicIdentityByAddress (bucket) -- Address (string starting with BM-) (bucket) --- nonceTrials -> uint64 --- extraBytes -> uint64 --- signingKey -> compressed public key (33 bytes) --- encryptionKey -> compressed public key (33 bytes) --- behavior -> uint32

- misc -- version -> uint8

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 BoltDB

type BoltDB struct {
	*bolt.DB
}

BoltDB is an implementation of database.Database interface with BoltDB as a backend store.

func (*BoltDB) ExistsObject

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

ExistsObject returns whether or not an object with the given inventory hash exists in the database.

func (*BoltDB) FetchIdentityByAddress

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

FetchIdentityByAddress returns identity.Public stored in the form of a PubKey message in the pubkey database.

func (*BoltDB) FetchObjectByCounter

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

FetchObjectByCounter returns the corresponding object based on the counter. Note that each object type has a different counter, with unknown objects being consolidated into one counter. Counters are meant for use as a convenience method for fetching new data from database since last check.

func (*BoltDB) FetchObjectByHash

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

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

func (*BoltDB) FetchObjectsFromCounter

func (db *BoltDB) 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.

func (*BoltDB) FetchRandomInvHashes

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

FetchRandomInvHashes returns the specified number of inventory hashes corresponding to random unexpired objects from the database. It does not guarantee that the number of returned inventory vectors would be `count'.

func (*BoltDB) GetCounter

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

GetCounter returns the highest value of counter that exists for objects of the given type.

func (*BoltDB) InsertObject

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

InsertObject inserts the given object into the database and returns the counter position. 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.

func (*BoltDB) RemoveEncryptedPubKey

func (db *BoltDB) 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.

func (*BoltDB) RemoveExpiredObjects

func (db *BoltDB) 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.

func (*BoltDB) RemoveObject

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

RemoveObject removes the object with the specified hash from the database. Does not remove PubKeys.

func (*BoltDB) RemoveObjectByCounter

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

RemoveObjectByCounter removes the object with the specified counter value from the database.

func (*BoltDB) RemovePublicIdentity

func (db *BoltDB) 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.

Jump to

Keyboard shortcuts

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