Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeChannelPoint(cp string) (string, uint32, error)
- func HideBytes(tx PrivacyMapTx, realBytes []byte) ([]byte, error)
- func HideChanPoint(tx PrivacyMapTx, txid string, index uint32) (string, uint32, error)
- func HideChanPointStr(tx PrivacyMapTx, cp string) (string, error)
- func HideString(tx PrivacyMapTx, real string) (string, error)
- func HideUint64(tx PrivacyMapTx, real uint64) (uint64, error)
- func NewMockSessionDB() *mockSessionDB
- func NewPseudoChanPoint() (string, error)
- func NewPseudoStr(n int) (string, error)
- func NewPseudoUint32() uint32
- func NewPseudoUint64() (uint64, string)
- func RevealBytes(tx PrivacyMapTx, pseudoBytes []byte) ([]byte, error)
- func RevealChanPoint(tx PrivacyMapTx, txid string, index uint32) (string, uint32, error)
- func RevealString(tx PrivacyMapTx, pseudo string) (string, error)
- func RevealUint64(tx PrivacyMapTx, pseudo uint64) (uint64, error)
- func SerializeAction(w io.Writer, action *Action) error
- func StrToUint64(s string) (uint64, error)
- func Uint64ToStr(i uint64) string
- func UseLogger(logger btclog.Logger)
- type Action
- type ActionLocator
- type ActionReadDBGetter
- type ActionState
- type ActionsDB
- type ActionsReadDB
- type ActionsWriteDB
- type DB
- func (db *DB) AddAction(sessionID session.ID, action *Action) (uint64, error)
- func (db *DB) GetActionsReadDB(groupID session.ID, featureName string) ActionsReadDB
- func (db *DB) GetKVStores(rule string, groupID session.ID, feature string) KVStores
- func (db *DB) ListActions(filterFn ListActionsFilterFn, query *ListActionsQuery) ([]*Action, uint64, uint64, error)
- func (db *DB) ListGroupActions(groupID session.ID, filterFn ListActionsFilterFn) ([]*Action, error)
- func (db *DB) ListSessionActions(sessionID session.ID, filterFn ListActionsFilterFn, query *ListActionsQuery) ([]*Action, uint64, uint64, error)
- func (db *DB) PrivacyDB(groupID session.ID) PrivacyMapDB
- func (db *DB) SetActionState(al *ActionLocator, state ActionState, errorReason string) error
- type KVStore
- type KVStoreTx
- type KVStores
- type ListActionsFilterFn
- type ListActionsQuery
- type NewPrivacyMapDB
- type PrivacyMapDB
- type PrivacyMapPairs
- type PrivacyMapReader
- type PrivacyMapTx
- type RuleAction
- type RulesDB
- type SessionDB
Constants ¶
const ( // DBFilename is the default filename of the rules' database. DBFilename = "rules.db" // DefaultRulesDBTimeout is the default maximum time we wait for the // db bbolt database to be opened. If the database is already // opened by another process, the unique lock cannot be obtained. With // the timeout we error out after the given time instead of just // blocking for forever. DefaultRulesDBTimeout = 5 * time.Second )
const Subsystem = "FWDB"
Variables ¶
var ( // ErrDBReversion is returned when detecting an attempt to revert to a // prior database version. ErrDBReversion = errors.New("cannot revert to prior version") )
var ( // ErrNoSuchKeyFound is returned when there is no key-value pair found // for the given key. ErrNoSuchKeyFound = fmt.Errorf("no such key found") )
Functions ¶
func HideChanPoint ¶
func HideChanPointStr ¶
func HideChanPointStr(tx PrivacyMapTx, cp string) (string, error)
func HideString ¶
func HideString(tx PrivacyMapTx, real string) (string, error)
func HideUint64 ¶
func HideUint64(tx PrivacyMapTx, real uint64) (uint64, error)
func NewMockSessionDB ¶
func NewMockSessionDB() *mockSessionDB
NewMockSessionDB creates a new mock privacy map details instance.
func NewPseudoChanPoint ¶
func NewPseudoStr ¶
func NewPseudoUint32 ¶
func NewPseudoUint32() uint32
func NewPseudoUint64 ¶
func RevealBytes ¶
func RevealBytes(tx PrivacyMapTx, pseudoBytes []byte) ([]byte, error)
func RevealChanPoint ¶
func RevealString ¶
func RevealString(tx PrivacyMapTx, pseudo string) (string, error)
func RevealUint64 ¶
func RevealUint64(tx PrivacyMapTx, pseudo uint64) (uint64, error)
func SerializeAction ¶
SerializeAction binary serializes the given action to the writer using the tlv format.
func StrToUint64 ¶
func Uint64ToStr ¶
Types ¶
type Action ¶
type Action struct { // SessionID is the ID of the session that this action belongs to. // Note that this is not serialized on persistence since the action is // already stored under a bucket identified by the session ID. SessionID session.ID // ActorName is the name of the entity who performed the Action. ActorName string // FeatureName is the name of the feature that the Action is being // performed by. FeatureName string // Trigger is the meta info detailing what caused this action to be // executed. Trigger string // Intent is the meta info detailing what the intended outcome of this // action will be. Intent string // StructuredJsonData is extra, structured, info that the Autopilot can // send to Litd serialised as a json string. StructuredJsonData string // RPCMethod is the URI that was called. RPCMethod string // RPCParams is the method parameters of the request in JSON form. RPCParamsJson []byte // AttemptedAt is the time at which this action was created. AttemptedAt time.Time // State represents the state of the Action. State ActionState // ErrorReason is the human-readable reason for why the action failed. // It will only be set if State is ActionStateError. ErrorReason string }
Action represents an RPC call made through the firewall.
type ActionLocator ¶
ActionLocator helps us find an action in the database.
type ActionReadDBGetter ¶
type ActionReadDBGetter interface {
GetActionsReadDB(groupID session.ID, featureName string) ActionsReadDB
}
ActionReadDBGetter represents a function that can be used to construct an ActionsReadDB.
type ActionState ¶
type ActionState uint8
ActionState represents the state of an action.
const ( // ActionStateUnknown means that the action's state was never // initialised. This should never be the case. ActionStateUnknown ActionState = 0 // ActionStateInit represents that an Action has been created but that // is still in the pending state. ActionStateInit ActionState = 1 // ActionStateDone represents that an Action has been executed // successfully. ActionStateDone ActionState = 2 // ActionStateError represents that an Action did not complete // successfully. ActionStateError ActionState = 3 )
type ActionsDB ¶
type ActionsDB interface { // ListActions returns a list of past Action items. ListActions(ctx context.Context) ([]*RuleAction, error) }
ActionsDB represents a DB backend that contains Action entries that can be queried. It allows us to abstract away the details of the data storage method.
type ActionsReadDB ¶
ActionsReadDB is an abstraction gives a caller access to either a group specific or group and feature specific rules.ActionDB.
type ActionsWriteDB ¶
type ActionsWriteDB interface { AddAction(sessionID session.ID, action *Action) (uint64, error) SetActionState(al *ActionLocator, state ActionState, errReason string) error }
ActionsWriteDB is an abstraction over the Actions DB that will allow a caller to add new actions as well as change the values of an existing action.
type DB ¶
DB is a bolt-backed persistent store.
func (*DB) GetActionsReadDB ¶
func (db *DB) GetActionsReadDB(groupID session.ID, featureName string) ActionsReadDB
GetActionsReadDB is a method on DB that constructs an ActionsReadDB.
func (*DB) GetKVStores ¶
GetKVStores constructs a new rules.KVStores backed by a bbolt db.
func (*DB) ListActions ¶
func (db *DB) ListActions(filterFn ListActionsFilterFn, query *ListActionsQuery) ([]*Action, uint64, uint64, error)
ListActions returns a list of Actions that pass the filterFn requirements. The indexOffset and maxNum params can be used to control the number of actions returned. The return values are the list of actions, the last index and the total count (iff query.CountTotal is set).
func (*DB) ListGroupActions ¶
ListGroupActions returns a list of the given session group's Actions that pass the filterFn requirements.
TODO: update to allow for pagination.
func (*DB) ListSessionActions ¶
func (db *DB) ListSessionActions(sessionID session.ID, filterFn ListActionsFilterFn, query *ListActionsQuery) ([]*Action, uint64, uint64, error)
ListSessionActions returns a list of the given session's Actions that pass the filterFn requirements.
func (*DB) PrivacyDB ¶
func (db *DB) PrivacyDB(groupID session.ID) PrivacyMapDB
PrivacyDB constructs a PrivacyMapDB that will be indexed under the given group ID key.
func (*DB) SetActionState ¶
func (db *DB) SetActionState(al *ActionLocator, state ActionState, errorReason string) error
SetActionState finds the action specified by the ActionLocator and sets its state to the given state.
type KVStore ¶
type KVStore interface { // Get fetches the value under the given key from the underlying kv // store. If no value is found, nil is returned. Get(ctx context.Context, key string) ([]byte, error) // Set sets the given key-value pair in the underlying kv store. Set(ctx context.Context, key string, value []byte) error // Del deletes the value under the given key in the underlying kv store. Del(ctx context.Context, key string) error }
KVStore is in interface representing a key value store. It allows us to abstract away the details of the data storage method.
type KVStoreTx ¶
type KVStoreTx interface { // Global returns a persisted global, rule-name indexed, kv store. A // rule with a given name will have access to this store independent of // group ID or feature. Global() KVStore // Local returns a persisted local kv store for the rule. Depending on // how the implementation is initialised, this will either be under the // group ID namespace or the group ID _and_ feature name namespace. Local() KVStore // GlobalTemp is similar to the Global store except that its contents // is cleared upon restart of the database. The reason persisting the // temporary store changes instead of just keeping an in-memory store is // that we can then guarantee atomicity if changes are made to both // the permanent and temporary stores. GlobalTemp() KVStore // LocalTemp is similar to the Local store except that its contents is // cleared upon restart of the database. The reason persisting the // temporary store changes instead of just keeping an in-memory store is // that we can then guarantee atomicity if changes are made to both // the permanent and temporary stores. LocalTemp() KVStore }
KVStoreTx represents a database transaction that can be used for both read and writes of the various different key value stores offered for the rule.
type KVStores ¶
type KVStores interface { // Update opens a database read/write transaction and executes the // function f with the transaction passed as a parameter. After f exits, // if f did not error, the transaction is committed. Otherwise, if f did // error, the transaction is rolled back. If the rollback fails, the // original error returned by f is still returned. If the commit fails, // the commit error is returned. Update(f func(tx KVStoreTx) error) error // View opens a database read transaction and executes the function f // with the transaction passed as a parameter. After f exits, the // transaction is rolled back. If f errors, its error is returned, not a // rollback error (if any occur). View(f func(tx KVStoreTx) error) error }
KVStores provides an Update and View method that will allow the caller to perform atomic read and write transactions on and of the key value stores offered the KVStoreTx.
type ListActionsFilterFn ¶
ListActionsFilterFn defines a function that can be used to determine if an action should be included in a set of results or not. The reversed parameter indicates if the actions are being traversed in reverse order or not. The first return boolean indicates if the action should be included or not and the second one indicates if the iteration should be stopped or not.
type ListActionsQuery ¶
type ListActionsQuery struct { // IndexOffset is index of the action to inspect. IndexOffset uint64 // MaxNum is the maximum number of actions to return. If it is set to 0, // then no maximum is enforced. MaxNum uint64 // Reversed indicates whether the actions should be returned in reverse // order. Reversed bool // CountAll should be set to true if the total number of actions that // satisfy the query should be counted and returned. Note that this will // make the query slower. CountAll bool }
ListActionsQuery can be used to tweak the query to ListActions and ListSessionActions.
type NewPrivacyMapDB ¶
type NewPrivacyMapDB func(groupID session.ID) PrivacyMapDB
NewPrivacyMapDB is a function type that takes a group ID and uses it to construct a new PrivacyMapDB.
type PrivacyMapDB ¶
type PrivacyMapDB interface { // Update opens a database read/write transaction and executes the // function f with the transaction passed as a parameter. After f exits, // if f did not error, the transaction is committed. Otherwise, if f did // error, the transaction is rolled back. If the rollback fails, the // original error returned by f is still returned. If the commit fails, // the commit error is returned. Update(f func(tx PrivacyMapTx) error) error // View opens a database read transaction and executes the function f // with the transaction passed as a parameter. After f exits, the // transaction is rolled back. If f errors, its error is returned, not a // rollback error (if any occur). View(f func(tx PrivacyMapTx) error) error }
PrivacyMapDB provides an Update and View method that will allow the caller to perform atomic read and write transactions defined by PrivacyMapTx on the underlying DB.
type PrivacyMapPairs ¶
type PrivacyMapPairs struct {
// contains filtered or unexported fields
}
PrivacyMapPairs is an in memory implementation of the PrivacyMapReader.
func NewPrivacyMapPairs ¶
func NewPrivacyMapPairs(m map[string]string) *PrivacyMapPairs
NewPrivacyMapPairs constructs a new PrivacyMapPairs struct. It may be initialised with either a nil map or a pre-defined real-to-pseudo strings map.
type PrivacyMapReader ¶
type PrivacyMapReader interface { // GetPseudo returns the associated pseudo value for a given real value. // If no such real value exists in the DB, then false is returned. GetPseudo(real string) (string, bool) }
PrivacyMapReader is an interface that gives read access to a privacy map DB.
type PrivacyMapTx ¶
type PrivacyMapTx interface { // NewPair persists a new real-pseudo pair. NewPair(real, pseudo string) error // PseudoToReal returns the real value associated with the given pseudo // value. If no such pair is found, then ErrNoSuchKeyFound is returned. PseudoToReal(pseudo string) (string, error) // RealToPseudo returns the pseudo value associated with the given real // value. If no such pair is found, then ErrNoSuchKeyFound is returned. RealToPseudo(real string) (string, error) // FetchAllPairs loads and returns the real-to-pseudo pairs in the form // of a PrivacyMapPairs struct. FetchAllPairs() (*PrivacyMapPairs, error) }
PrivacyMapTx represents a db that can be used to create, store and fetch real-pseudo pairs.
type RuleAction ¶
type RuleAction struct { // Method is the URI of the rpc method that was called. Method string // PerformedAt is the time at which the action was attempted. PerformedAt time.Time }
RuleAction represents a method call that was performed at a certain time at a certain time.