wtmock

package
v0.13.1-beta Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockConn

func NewMockConn(localPk, remotePk *btcec.PublicKey,
	localAddr, remoteAddr net.Addr,
	bufferSize int) (*MockPeer, *MockPeer)

NewMockConn establishes a bidirectional connection between two MockPeers.

Types

type ClientDB

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

ClientDB is a mock, in-memory database or testing the watchtower client behavior.

func NewClientDB

func NewClientDB() *ClientDB

NewClientDB initializes a new mock ClientDB.

func (*ClientDB) AckUpdate

func (m *ClientDB) AckUpdate(id *wtdb.SessionID, seqNum, lastApplied uint16) error

AckUpdate persists an acknowledgment for a given (session, seqnum) pair. This removes the update from the set of committed updates, and validates the lastApplied value returned from the tower.

func (*ClientDB) CommitUpdate

func (m *ClientDB) CommitUpdate(id *wtdb.SessionID,
	update *wtdb.CommittedUpdate) (uint16, error)

CommitUpdate persists the CommittedUpdate provided in the slot for (session, seqNum). This allows the client to retransmit this update on startup.

func (*ClientDB) CreateClientSession

func (m *ClientDB) CreateClientSession(session *wtdb.ClientSession) error

CreateClientSession records a newly negotiated client session in the set of active sessions. The session can be identified by its SessionID.

func (*ClientDB) CreateTower

func (m *ClientDB) CreateTower(lnAddr *lnwire.NetAddress) (*wtdb.Tower, error)

CreateTower initialize an address record used to communicate with a watchtower. Each Tower is assigned a unique ID, that is used to amortize storage costs of the public key when used by multiple sessions. If the tower already exists, the address is appended to the list of all addresses used to that tower previously and its corresponding sessions are marked as active.

func (*ClientDB) FetchChanSummaries

func (m *ClientDB) FetchChanSummaries() (wtdb.ChannelSummaries, error)

FetchChanSummaries loads a mapping from all registered channels to their channel summaries.

func (*ClientDB) ListClientSessions

func (m *ClientDB) ListClientSessions(
	tower *wtdb.TowerID) (map[wtdb.SessionID]*wtdb.ClientSession, error)

ListClientSessions returns the set of all client sessions known to the db. An optional tower ID can be used to filter out any client sessions in the response that do not correspond to this tower.

func (*ClientDB) ListTowers

func (m *ClientDB) ListTowers() ([]*wtdb.Tower, error)

ListTowers retrieves the list of towers available within the database.

func (*ClientDB) LoadTower

func (m *ClientDB) LoadTower(pubKey *btcec.PublicKey) (*wtdb.Tower, error)

LoadTower retrieves a tower by its public key.

func (*ClientDB) LoadTowerByID

func (m *ClientDB) LoadTowerByID(towerID wtdb.TowerID) (*wtdb.Tower, error)

LoadTowerByID retrieves a tower by its tower ID.

func (*ClientDB) MarkBackupIneligible

func (m *ClientDB) MarkBackupIneligible(chanID lnwire.ChannelID, commitHeight uint64) error

MarkBackupIneligible records that particular commit height is ineligible for backup. This allows the client to track which updates it should not attempt to retry after startup.

func (*ClientDB) NextSessionKeyIndex

func (m *ClientDB) NextSessionKeyIndex(towerID wtdb.TowerID,
	blobType blob.Type) (uint32, error)

NextSessionKeyIndex reserves a new session key derivation index for a particular tower id. The index is reserved for that tower until CreateClientSession is invoked for that tower and index, at which point a new index for that tower can be reserved. Multiple calls to this method before CreateClientSession is invoked should return the same index.

func (*ClientDB) RegisterChannel

func (m *ClientDB) RegisterChannel(chanID lnwire.ChannelID,
	sweepPkScript []byte) error

RegisterChannel registers a channel for use within the client database. For now, all that is stored in the channel summary is the sweep pkscript that we'd like any tower sweeps to pay into. In the future, this will be extended to contain more info to allow the client efficiently request historical states to be backed up under the client's active policy.

func (*ClientDB) RemoveTower

func (m *ClientDB) RemoveTower(pubKey *btcec.PublicKey, addr net.Addr) error

RemoveTower modifies a tower's record within the database. If an address is provided, then _only_ the address record should be removed from the tower's persisted state. Otherwise, we'll attempt to mark the tower as inactive by marking all of its sessions inactive. If any of its sessions has unacked updates, then ErrTowerUnackedUpdates is returned. If the tower doesn't have any sessions at all, it'll be completely removed from the database.

NOTE: An error is not returned if the tower doesn't exist.

type MockPeer

type MockPeer struct {
	IncomingMsgs chan []byte
	OutgoingMsgs chan []byte

	RemoteQuit chan struct{}
	Quit       chan struct{}
	// contains filtered or unexported fields
}

MockPeer emulates a single endpoint of brontide transport.

func NewMockPeer

func NewMockPeer(lpk, rpk *btcec.PublicKey, addr net.Addr,
	bufferSize int) *MockPeer

NewMockPeer returns a fresh MockPeer.

func (*MockPeer) Close

func (p *MockPeer) Close() error

Close tearsdown the connection, and fails any pending reads or writes.

func (*MockPeer) LocalAddr

func (p *MockPeer) LocalAddr() net.Addr

LocalAddr returns the local net address of the peer.

func (*MockPeer) Read

func (p *MockPeer) Read(dst []byte) (int, error)

Read is not implemented.

func (*MockPeer) ReadNextMessage

func (p *MockPeer) ReadNextMessage() ([]byte, error)

ReadNextMessage returns the raw bytes of the next full message read from the remote peer. The read will fail if either party closes the connection or the read deadline expires.

func (*MockPeer) RemoteAddr

func (p *MockPeer) RemoteAddr() net.Addr

RemoteAddr returns the net address of the remote peer.

func (*MockPeer) RemotePub

func (p *MockPeer) RemotePub() *btcec.PublicKey

RemotePub returns the public key of the remote peer.

func (*MockPeer) SetDeadline

func (p *MockPeer) SetDeadline(t time.Time) error

SetDeadline is not implemented.

func (*MockPeer) SetReadDeadline

func (p *MockPeer) SetReadDeadline(t time.Time) error

SetReadDeadline initializes a timer that will cause any pending reads to fail at time t. If t is zero, the deadline is infinite.

func (*MockPeer) SetWriteDeadline

func (p *MockPeer) SetWriteDeadline(t time.Time) error

SetWriteDeadline initializes a timer that will cause any pending writes to fail at time t. If t is zero, the deadline is infinite.

func (*MockPeer) Write

func (p *MockPeer) Write(b []byte) (n int, err error)

Write sends the raw bytes as the next full message read to the remote peer. The write will fail if either party closes the connection or the write deadline expires. The passed bytes slice is copied before sending, thus the bytes may be reused once the method returns.

type MockSigner

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

MockSigner is an input.Signer that allows one to add arbitrary private keys and sign messages by passing the assigned keychain.KeyLocator.

func NewMockSigner

func NewMockSigner() *MockSigner

NewMockSigner returns a fresh MockSigner.

func (*MockSigner) AddPrivKey

func (s *MockSigner) AddPrivKey(privKey *btcec.PrivateKey) keychain.KeyLocator

AddPrivKey records the passed privKey in the MockSigner's registry of keys it can sign with in the future. A unique key locator is returned, allowing the caller to sign with this key when presented via an input.SignDescriptor.

func (*MockSigner) ComputeInputScript

func (s *MockSigner) ComputeInputScript(tx *wire.MsgTx,
	signDesc *input.SignDescriptor) (*input.Script, error)

ComputeInputScript is not implemented.

func (*MockSigner) SignOutputRaw

func (s *MockSigner) SignOutputRaw(tx *wire.MsgTx,
	signDesc *input.SignDescriptor) (input.Signature, error)

SignOutputRaw signs an input on the passed transaction using the input index in the sign descriptor. The returned signature is the raw DER-encoded signature without the signhash flag.

type SecretKeyRing

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

SecretKeyRing is a mock, in-memory implementation for deriving private keys.

func NewSecretKeyRing

func NewSecretKeyRing() *SecretKeyRing

NewSecretKeyRing creates a new mock SecretKeyRing.

func (*SecretKeyRing) DeriveKey

func (m *SecretKeyRing) DeriveKey(
	keyLoc keychain.KeyLocator) (keychain.KeyDescriptor, error)

DeriveKey attempts to derive an arbitrary key specified by the passed KeyLocator. This may be used in several recovery scenarios, or when manually rotating something like our current default node key.

NOTE: This is part of the wtclient.ECDHKeyRing interface.

func (*SecretKeyRing) ECDH

func (m *SecretKeyRing) ECDH(keyDesc keychain.KeyDescriptor,
	pub *btcec.PublicKey) ([32]byte, error)

ECDH performs a scalar multiplication (ECDH-like operation) between the target key descriptor and remote public key. The output returned will be the sha256 of the resulting shared point serialized in compressed format. If k is our private key, and P is the public key, we perform the following operation:

sx := k*P
s := sha256(sx.SerializeCompressed())

NOTE: This is part of the wtclient.ECDHKeyRing interface.

type TowerDB

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

TowerDB is a mock, in-memory implementation of a watchtower.DB.

func NewTowerDB

func NewTowerDB() *TowerDB

NewTowerDB initializes a fresh mock TowerDB.

func (*TowerDB) DeleteSession

func (db *TowerDB) DeleteSession(target wtdb.SessionID) error

DeleteSession removes all data associated with a particular session id from the tower's database.

func (*TowerDB) GetLookoutTip

func (db *TowerDB) GetLookoutTip() (*chainntnfs.BlockEpoch, error)

GetLookoutTip retrieves the current lookout tip block epoch from the tower database.

func (*TowerDB) GetSessionInfo

func (db *TowerDB) GetSessionInfo(id *wtdb.SessionID) (*wtdb.SessionInfo, error)

GetSessionInfo retrieves the session for the passed session id. An error is returned if the session could not be found.

func (*TowerDB) InsertSessionInfo

func (db *TowerDB) InsertSessionInfo(info *wtdb.SessionInfo) error

InsertSessionInfo records a negotiated session in the tower database. An error is returned if the session already exists.

func (*TowerDB) InsertStateUpdate

func (db *TowerDB) InsertStateUpdate(update *wtdb.SessionStateUpdate) (uint16, error)

InsertStateUpdate stores an update sent by the client after validating that the update is well-formed in the context of other updates sent for the same session. This include verifying that the sequence number is incremented properly and the last applied values echoed by the client are sane.

func (*TowerDB) QueryMatches

func (db *TowerDB) QueryMatches(
	breachHints []blob.BreachHint) ([]wtdb.Match, error)

QueryMatches searches against all known state updates for any that match the passed breachHints. More than one Match will be returned for a given hint if they exist in the database.

func (*TowerDB) SetLookoutTip

func (db *TowerDB) SetLookoutTip(epoch *chainntnfs.BlockEpoch) error

SetLookoutTip stores the provided epoch as the latest lookout tip epoch in the tower database.

Jump to

Keyboard shortcuts

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