Documentation
¶
Overview ¶
Package store is a persistent database for everything that bmclient needs for operation. This includes storing mailboxes and messages, proof of work queue, list of requested pubkeys.
Take note that this store does not encrypt everything. Only messages contents are encrypted. Encryption scheme used is SalsaX20 stream cipher with Poly1305 MAC, based on secretbox in NaCl.
WARNING: If both your database and password were compromised, changing your
password won't accomplish anything. This is because store encrypts the master key using the password you specify when the database is created. A malicious user that knew your password and had a previous copy of the store knows the master key and can decrypt all messages.
WARNING 2: Master key is kept in memory. The package is vulnerable to memory
reading malware.
Index ¶
- Variables
- func DisableLog()
- func UseClientLogger(logger btclog.Logger)
- func UseServerLogger(logger btclog.Logger)
- type BroadcastAddresses
- type Folder
- type Loader
- type PKRequests
- type PowQueue
- type Store
- func (s *Store) ChangePassphrase(pass []byte) error
- func (s *Store) Close() error
- func (s *Store) GetCounter(objType wire.ObjectType) (uint64, error)
- func (s *Store) GetUser(name string) (*UserData, error)
- func (s *Store) NewUser(name string) (*UserData, error)
- func (s *Store) SetCounter(objType wire.ObjectType, counter uint64) error
- type UserData
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when a record matching the query or no record at // all is found in the database. ErrNotFound = errors.New("record not found") // ErrDecryptionFailed is returned when decryption of the master key fails. // This could be due to invalid passphrase or corrupt/tampered data. ErrDecryptionFailed = errors.New("invalid passphrase") // ErrDuplicateMailbox is returned by NewMailbox when a mailbox with the // given name already exists. ErrDuplicateMailbox = errors.New("duplicate mailbox") )
var ( // ErrDuplicateID is returned by InsertMessage when the a message with the // specified ID already exists in the folder. ErrDuplicateID = errors.New("duplicate ID") // ErrInvaidID is returned when an invalid id is provided. ErrInvalidID = errors.New("invalid ID") )
Data keys of a mailbox.
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
func UseClientLogger ¶
UseClientLogger uses a specified Logger to output client logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.
func UseServerLogger ¶
UseServerLogger uses a specified Logger to output client logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.
Types ¶
type BroadcastAddresses ¶
type BroadcastAddresses struct {
// contains filtered or unexported fields
}
BroadcastAddresses keeps track of the broadcasts that the user is listening to. It provides functionality for adding, removal and running a function for each address.
func (*BroadcastAddresses) Add ¶
func (b *BroadcastAddresses) Add(address string) error
Add adds a new address to the store.
func (*BroadcastAddresses) ForEach ¶
func (b *BroadcastAddresses) ForEach(f func(address *bmutil.Address) error) error
ForEach runs the specified function for each broadcast address, breaking early if an error occurs.
func (*BroadcastAddresses) Remove ¶
func (b *BroadcastAddresses) Remove(address string) error
Remove removes an address from the store.
type Folder ¶
type Folder interface { // Name returns the user-friendly name of the folder. Name() string // SetName changes the name of the folder. SetName(name string) error // InsertNewMessage inserts a new message with the specified suffix and // id into the folder and returns the ID. For normal folders, suffix // could be the encoding type. For special use folders like "Pending", // suffix could be used as a 'key', like a reason code (why the message is // marked as Pending). InsertNewMessage(msg []byte, suffix uint64) (uint64, error) // InsertMessage inserts a new message with the specified suffix and id // into the folder and returns the ID. If input id is 0 or >= NextID, // ErrInvalidID is returned. InsertMessage(id uint64, msg []byte, suffix uint64) error // GetMessage retrieves a message from the folder by its index. It returns the // suffix and the message. An error is returned if the message with the given // index doesn't exist in the database. GetMessage(id uint64) (uint64, []byte, error) // DeleteMessage deletes a message with the given index from the store. An error // is returned if the message doesn't exist in the store. DeleteMessage(id uint64) error // ForEachMessage runs the given function for messages that have IDs between // lowID and highID with the given suffix. If lowID is 0, it starts from the // first message. If highID is 0, it returns all messages with id >= lowID with // the given suffix. If suffix is zero, it returns all messages between lowID // and highID, irrespective of the suffix. Note that any combination of lowID, // highID and suffix can be zero for the desired results. Both lowID and highID // are inclusive. // // Suffix is useful for getting all messages of a particular type. For example, // retrieving all messages with encoding type 2. // // The function terminates early if an error occurs and iterates in the // increasing order of index. Make sure it doesn't take long to execute. DO NOT // execute any other database operations in it. ForEachMessage(lowID, highID, suffix uint64, fn func(id, suffix uint64, msg []byte) error) error // NextID returns the next index value that will be assigned in the mailbox.. NextID() uint64 // LastID returns the highest index value in the mailbox, followed by a // map containing the last indices for each suffix. LastID() (uint64, map[uint64]uint64) }
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Type for transforming underlying database into Store. (used to abstract the details of the underlying bolt db).
func (*Loader) IsEncrypted ¶
type PKRequests ¶
type PKRequests struct {
// contains filtered or unexported fields
}
PKRequests is a store that keeps track of getpubkey requests sent to the Bitmessage network. It stores the requested address along with the time the request was made. All addresses passed are expected to be valid Bitmessage addresses. A separate goroutine routinely queries the bmd RPC server for the public keys corresponding to the addresses in this store and removes them if bmd has received them. Thus, PKRequests serves as a watchlist.
func (*PKRequests) ForEach ¶
func (r *PKRequests) ForEach(f func(address string, reqCount uint32, lastReqTime time.Time) error) error
ForEach runs the specified function for each item in the public key requests store, breaking early if an error occurs.
func (*PKRequests) LastRequestTime ¶
func (r *PKRequests) LastRequestTime(addr string) (time.Time, error)
LastRequestTime returns the time that the last getpubkey request for the given address was sent out to the network. If the address doesn't exist, an ErrNotFound is returned.
func (*PKRequests) New ¶
func (r *PKRequests) New(addr string) (uint32, error)
New adds a new address to the watchlist along with the current timestamp. If the address already exists, it increments the counter value specifying the number of times a getpubkey request was sent for the given address and returns it.
func (*PKRequests) Remove ¶
func (r *PKRequests) Remove(addr string) error
Remove removes an address from the store.
type PowQueue ¶
type PowQueue struct {
// contains filtered or unexported fields
}
PowQueue is a FIFO queue for objects that need proof-of-work done on them. It implements Enqueue, Dequeue and Peek; the most basic queue operations.
func (*PowQueue) Dequeue ¶
Dequeue removes the object message at beginning of the queue and returns its index, the user that requested it, and itself.
type Store ¶
Store persists all information about public key requests, pending POW, incoming/outgoing/pending messages to disk.
func (*Store) ChangePassphrase ¶
ChangePassphrase changes the passphrase of the data store. It does not protect against a previous compromise of the data file. Refer to package docs for more details.
func (*Store) GetCounter ¶
func (s *Store) GetCounter(objType wire.ObjectType) (uint64, error)
GetCounter returns the stored counter value associated with the given object type.
func (*Store) SetCounter ¶
func (s *Store) SetCounter(objType wire.ObjectType, counter uint64) error
SetCounter sets the counter value associated with the given object type.
type UserData ¶
type UserData struct { BroadcastAddresses *BroadcastAddresses // contains filtered or unexported fields }
func (*UserData) DeleteFolder ¶
Delete deletes the folder. Any operations after a Delete are invalid.
func (*UserData) FolderByName ¶
FolderByName retrieves the mailbox associated with the name. If the mailbox doesn't exist, an error is returned.