store

package
v0.0.0-...-dee8dd0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2017 License: ISC Imports: 15 Imported by: 0

README

store

Package store is a data store for everything that bmclient needs. Refer to godoc for more docs.

Database structure:

- powQueue (bucket) (FIFO data structure)
-- 0x0000000000000001 (Queue entry #1)
--- Target (8 bytes) || Object Hash (64 bytes)

- pubkeyRequests (bucket)
-- BM-blahblahblah
--- number of requests (uint32) || last request time (binary time serialized 
      using time.MarshalBinary)

- misc (bucket)
-- dbMasterKey (encrypted)
-- salt
-- mailboxLatestID
-- powQueueLatestID
-- counters (bucket)
--- 0x00000000 (wire.ObjectTypeGetPubKey)
--- 0x00000002 (wire.ObjectTypeMsg)
--- 0x00000003 (wire.ObjectTypeBroadcast)

- mailboxes (bucket)
-- name (bucket)
--- data (bucket)
---- createdOn
--- 0x00000000000000010000000000000001 (Message of ID 1 and suffix 1)
---- Nonce (24 bytes) || Encrypted Contents

- broadcastAddresses (bucket)
-- BM-blahblahblah (no value)

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

Constants

This section is empty.

Variables

View Source
var (
	// 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")
)

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 UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output 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 Loader

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

Loader transforms underlying database into Store.

func Open

func Open(file string) (*Loader, error)

Open creates a new Store from the given file.

func (*Loader) Close

func (l *Loader) Close() error

Close performs any necessary cleanups and then closes the database.

func (*Loader) Construct

func (l *Loader) Construct(pass []byte) (*Store, *PKRequests, error)

Construct creates a new Store from the given file.

func (*Loader) IsEncrypted

func (l *Loader) IsEncrypted() bool

IsEncrypted returns whether the store is encrypted.

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 Store

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

Store persists all information about public key requests, pending POW, incoming/outgoing/pending messages to disk.

func (*Store) ChangePassphrase

func (s *Store) ChangePassphrase(pass []byte) error

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) Close

func (s *Store) Close() error

Close performs any necessary cleanups and then closes the store.

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) GetUser

func (s *Store) GetUser(name string) (*User, error)

GetUser returns the User object for the given name.

func (*Store) NewUser

func (s *Store) NewUser(name string) (*User, error)

NewUser creates a new user.

func (*Store) SetCounter

func (s *Store) SetCounter(objType wire.ObjectType, counter uint64) error

SetCounter sets the counter value associated with the given object type.

func (*Store) Users

func (s *Store) Users() map[string]*User

Users returns the map of users in the Store.

type User

type User struct {
	BroadcastAddresses *BroadcastAddresses
	// contains filtered or unexported fields
}

User contains all the information relevant for a single user.

func (*User) Folders

func (u *User) Folders() (data.Folders, error)

Folders returns the email folders for this user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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