msgdb

package
v0.0.0-...-30b4a77 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2016 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package msgdb defines an encrypted database used to store messages.

Index

Constants

View Source
const (
	DBVersion = "Version"   // version string of msgdb
	WalletKey = "WalletKey" // 64-byte private Ed25519 wallet key, base64 encoded
	ActiveUID = "ActiveUID" // the active UID
)

Entries in KeyValueTable.

View Source
const Version = "1"

Version is the current msgdb version.

Variables

View Source
var ErrNilMessageID = errors.New("msgdb: messageID nil")

ErrNilMessageID is returned if the messageID argument is nil.

Functions

func Create

func Create(dbname string, passphrase []byte, iter int) error

Create returns a new message database with the given dbname. It is encrypted by passphrase (processed by a KDF with iter many iterations).

func Rekey

func Rekey(dbname string, oldPassphrase, newPassphrase []byte, newIter int) error

Rekey tries to rekey the message database dbname with the newPassphrase (processed by a KDF with iter many iterations). The supplied oldPassphrase must be correct, otherwise an error is returned.

Types

type ContactType

type ContactType int64

ContactType represents the different types of contacts (white list, gray list, and black list).

const (
	// WhiteList represents a white listed contact.
	WhiteList ContactType = iota
	// GrayList represents a gray listed contact.
	GrayList
	// BlackList represents a black listed contact.
	BlackList
)

type MsgDB

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

MsgDB is a handle for an encrypted database to store messsages and tokens.

func Open

func Open(dbname string, passphrase []byte) (*MsgDB, error)

Open opens the message database with dbname and passphrase.

func (*MsgDB) AddAccount

func (msgDB *MsgDB) AddAccount(
	myID, contactID string,
	privkey *[ed25519.PrivateKeySize]byte,
	server string,
	secret *[64]byte,
	minDelay, maxDelay int32,
) error

AddAccount adds an account for myID and contactID (which can be nil) with given privkey on server.

func (*MsgDB) AddContact

func (msgDB *MsgDB) AddContact(
	myID, mappedID, unmappedID, fullName string,
	contactType ContactType,
) error

AddContact adds or updates a contact in msgDB.

func (*MsgDB) AddInQueue

func (msgDB *MsgDB) AddInQueue(myID, contactID string, date int64, msg string) error

AddInQueue adds the given message corressponding to myID and contactID (can be nil) to the inqueue.

func (*MsgDB) AddMessage

func (msgDB *MsgDB) AddMessage(
	selfID, peerID string,
	date int64,
	sent bool,
	message string,
	sign bool,
	minDelay, maxDelay int32,
) error

AddMessage adds message between selfID and peerID to msgDB. If sent is true, it is a sent message. Otherwise a received message.

func (*MsgDB) AddMessageIDCache

func (msgDB *MsgDB) AddMessageIDCache(myID, contactID, messageID string) error

AddMessageIDCache adds messageID to the message ID cache for the myID and contactID pair.

func (*MsgDB) AddNym

func (msgDB *MsgDB) AddNym(mappedID, unmappedID, fullName string) error

AddNym adds or updates a mapping from a mapped ID to an unmapped ID and full name.

func (*MsgDB) AddOutQueue

func (msgDB *MsgDB) AddOutQueue(
	myID string,
	msgID int64,
	encMsg, nymaddress string,
	minDelay, maxDelay int32,
) error

AddOutQueue adds the encrypted message encMsg corresponding to the the plain text message with msgID to the outqueue.

func (*MsgDB) AddValue

func (msgDB *MsgDB) AddValue(key, value string) error

AddValue adds a key-value pair to msgDB.

func (*MsgDB) ClearResendOutQueue

func (msgDB *MsgDB) ClearResendOutQueue(myID string) error

ClearResendOutQueue clears the resend status in the outqueue for myID.

func (*MsgDB) Close

func (msgDB *MsgDB) Close() error

Close the message database.

func (*MsgDB) DB

func (msgDB *MsgDB) DB() *sql.DB

DB returns the internal database handle for message database. Usually this method should not be used!

func (*MsgDB) DelInQueue

func (msgDB *MsgDB) DelInQueue(iqIdx int64) error

DelInQueue deletes the entry with index iqIdx from inqueue.

func (*MsgDB) DelMessage

func (msgDB *MsgDB) DelMessage(myID string, msgNum int64) error

DelMessage deletes the message from user myID with the given msgNum.

func (*MsgDB) DelNym

func (msgDB *MsgDB) DelNym(mappedID string) error

DelNym deletes the nym mappedID and all associated contacts and messages!

func (*MsgDB) GetAccount

func (msgDB *MsgDB) GetAccount(
	myID, contactID string,
) (
	privkey *[ed25519.PrivateKeySize]byte,
	server string,
	secret *[64]byte,
	minDelay, maxDelay int32,
	lastMessageTime int64,
	err error,
)

GetAccount returns the privkey and server of the account for myID.

func (*MsgDB) GetAccountTime

func (msgDB *MsgDB) GetAccountTime(
	myID, contactID string,
) (int64, error)

GetAccountTime returns the account time for the given myID and contactID combination.

func (*MsgDB) GetAccounts

func (msgDB *MsgDB) GetAccounts(myID string) ([]string, error)

GetAccounts returns a list of contactIDs (including nil) of all accounts that exist for myID.

func (*MsgDB) GetContact

func (msgDB *MsgDB) GetContact(myID, contactID string) (
	unmappedID, fullName string,
	contactType ContactType,
	err error,
)

GetContact retrieves the (possibly blocked) contact contactID for myID.

func (*MsgDB) GetContacts

func (msgDB *MsgDB) GetContacts(myID string, blocked bool) ([]string, error)

GetContacts retrieves all the contacts list (or blacklist, if blocked equals true) for the given ownID user ID.

func (*MsgDB) GetInQueue

func (msgDB *MsgDB) GetInQueue() (
	iqIdx int64,
	myID, contactID, msg string,
	envelope bool,
	err error,
)

GetInQueue returns the first entry in the inqueue.

func (*MsgDB) GetMessage

func (msgDB *MsgDB) GetMessage(
	myID string,
	msgNum int64,
) (from, to, msg string, date int64, err error)

GetMessage returns the message from user myID with the given msgNum.

func (*MsgDB) GetMessageIDCache

func (msgDB *MsgDB) GetMessageIDCache(myID, contactID string) (
	map[string]bool,
	error,
)

GetMessageIDCache retursn the message ID cache for the myID and contactID pair.

func (*MsgDB) GetMsgIDs

func (msgDB *MsgDB) GetMsgIDs(myID string) ([]*MsgID, error)

GetMsgIDs returns all message IDs (sqlite row IDs) for the user ID myID.

func (*MsgDB) GetNym

func (msgDB *MsgDB) GetNym(mappedID string) (
	unmappedID, fullName string,
	err error,
)

GetNym gets the unmapped ID and (full) name for a mapped ID.

func (*MsgDB) GetNyms

func (msgDB *MsgDB) GetNyms(mapped bool) ([]string, error)

GetNyms returns all unmapped or mapped nyms in msgDB.

func (*MsgDB) GetOutQueue

func (msgDB *MsgDB) GetOutQueue(myID string) (
	oqIdx int64,
	msg, nymaddress string,
	minDelay, maxDelay int32,
	envelope bool,
	err error,
)

GetOutQueue returns the first entry in the outqueue for myID. Entries which need to be resend are ignored.

func (*MsgDB) GetUndeliveredMessage

func (msgDB *MsgDB) GetUndeliveredMessage(myID string) (
	msgNum int64,
	contactID string,
	msg []byte,
	sign bool,
	minDelay, maxDelay int32,
	err error,
)

GetUndeliveredMessage returns the oldest undelivered message for myID from msgDB.

func (*MsgDB) GetUpkeepAccounts

func (msgDB *MsgDB) GetUpkeepAccounts(myID string) (int64, error)

GetUpkeepAccounts retrieves the last execution time of 'upkeep accounts'.

func (*MsgDB) GetUpkeepAll

func (msgDB *MsgDB) GetUpkeepAll(myID string) (int64, error)

GetUpkeepAll retrieves the last execution time of 'upkeep all'.

func (*MsgDB) GetValue

func (msgDB *MsgDB) GetValue(key string) (string, error)

GetValue gets the value for the given key from msgDB.

func (*MsgDB) Incremental

func (msgDB *MsgDB) Incremental(pages int64) error

Incremental executes incremental_vacuum to free up to pages many pages. If pages is 0, all pages are freed. If the current auto_vacuum mode is not INCREMENTAL, an error is returned.

func (*MsgDB) ReadMessage

func (msgDB *MsgDB) ReadMessage(msgNum int64) error

ReadMessage sets the message with the given msgNum as read.

func (*MsgDB) RemoveContact

func (msgDB *MsgDB) RemoveContact(myID, contactID string) error

RemoveContact removes a contact between myID and contactID (normal or blocked) from the msgDB.

func (*MsgDB) RemoveInQueue

func (msgDB *MsgDB) RemoveInQueue(
	iqIdx int64, plainMsg, fromID string,
	drop bool,
) error

RemoveInQueue remove the entry with index iqIdx from inqueue and adds the descrypted message plainMsg to msgDB (if drop is not true).

func (*MsgDB) RemoveMessageIDCache

func (msgDB *MsgDB) RemoveMessageIDCache(
	myID, contactID, messageID string,
) error

RemoveMessageIDCache removes all entries from the message ID cache for the myID and contactID pair which are older than messageID.

func (*MsgDB) RemoveOutQueue

func (msgDB *MsgDB) RemoveOutQueue(oqIdx, date int64) error

RemoveOutQueue remove the message corresponding to oqIdx from the outqueue and sets the send time of the corresponding message to date.

func (*MsgDB) RetractOutQueue

func (msgDB *MsgDB) RetractOutQueue(oqIdx int64) error

RetractOutQueue retract the message corresponding to oqIdx from the outqueue and sets the corresponding message to 'ToSend' again.

func (*MsgDB) SetAccountLastMsg

func (msgDB *MsgDB) SetAccountLastMsg(
	myID, contactID string,
	lastMessageTime int64,
) error

SetAccountLastMsg sets the last message time and ID for the given myID and contactID combination (contactID can be nil).

func (*MsgDB) SetAccountTime

func (msgDB *MsgDB) SetAccountTime(
	myID, contactID string,
	loadTime int64,
) error

SetAccountTime sets the account time for the given myID and contactID combination (contactID can be nil).

func (*MsgDB) SetInQueue

func (msgDB *MsgDB) SetInQueue(iqIdx int64, msg string) error

SetInQueue replaces the encrypted message corresponding to iqIdx with the encrypted message msg.

func (*MsgDB) SetOutQueue

func (msgDB *MsgDB) SetOutQueue(oqIdx int64, envMsg string) error

SetOutQueue replaces the encrypted message corresponding to oqIdx with the envelope message envMsg.

func (*MsgDB) SetResendOutQueue

func (msgDB *MsgDB) SetResendOutQueue(oqIdx int64) error

SetResendOutQueue sets the message in outqueue with index oqIdx to resend.

func (*MsgDB) SetUpkeepAccounts

func (msgDB *MsgDB) SetUpkeepAccounts(myID string, t int64) error

SetUpkeepAccounts sets the last execution time of 'upkeep accounts' to t.

func (*MsgDB) SetUpkeepAll

func (msgDB *MsgDB) SetUpkeepAll(myID string, t int64) error

SetUpkeepAll sets the last execution time of 'upkeep all' to t.

func (*MsgDB) Status

func (msgDB *MsgDB) Status() (
	autoVacuum string,
	freelistCount int64,
	err error,
)

Status returns the autoVacuum mode and freelistCount of msgDB.

func (*MsgDB) Vacuum

func (msgDB *MsgDB) Vacuum(autoVacuumMode string) error

Vacuum executes VACUUM command in msgDB. If autoVacuumMode is not nil and different from the current one, the auto_vacuum mode is changed before VACUUM is executed.

func (*MsgDB) Version

func (msgDB *MsgDB) Version() (string, error)

Version returns the current version of msgDB.

type MsgID

type MsgID struct {
	MsgID    int64  // the message ID
	From     string // sender
	To       string // recipient
	Incoming bool   // an incoming message, outgoing otherwise
	Sent     bool   // outgoing message has been sent
	Date     int64
	Subject  string
	Read     bool
}

MsgID is the info type that is returned by GetMsgIDs.

Jump to

Keyboard shortcuts

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