github.com/decred/dcrlnd@v0.7.6/watchtower/wtclient/interface.go (about)

     1  package wtclient
     2  
     3  import (
     4  	"net"
     5  
     6  	"github.com/decred/dcrd/dcrec/secp256k1/v4"
     7  	"github.com/decred/dcrlnd/keychain"
     8  	"github.com/decred/dcrlnd/lnwire"
     9  	"github.com/decred/dcrlnd/tor"
    10  	"github.com/decred/dcrlnd/watchtower/blob"
    11  	"github.com/decred/dcrlnd/watchtower/wtdb"
    12  	"github.com/decred/dcrlnd/watchtower/wtserver"
    13  )
    14  
    15  // DB abstracts the required database operations required by the watchtower
    16  // client.
    17  type DB interface {
    18  	// CreateTower initialize an address record used to communicate with a
    19  	// watchtower. Each Tower is assigned a unique ID, that is used to
    20  	// amortize storage costs of the public key when used by multiple
    21  	// sessions. If the tower already exists, the address is appended to the
    22  	// list of all addresses used to that tower previously and its
    23  	// corresponding sessions are marked as active.
    24  	CreateTower(*lnwire.NetAddress) (*wtdb.Tower, error)
    25  
    26  	// RemoveTower modifies a tower's record within the database. If an
    27  	// address is provided, then _only_ the address record should be removed
    28  	// from the tower's persisted state. Otherwise, we'll attempt to mark
    29  	// the tower as inactive by marking all of its sessions inactive. If any
    30  	// of its sessions has unacked updates, then ErrTowerUnackedUpdates is
    31  	// returned. If the tower doesn't have any sessions at all, it'll be
    32  	// completely removed from the database.
    33  	//
    34  	// NOTE: An error is not returned if the tower doesn't exist.
    35  	RemoveTower(*secp256k1.PublicKey, net.Addr) error
    36  
    37  	// LoadTower retrieves a tower by its public key.
    38  	LoadTower(*secp256k1.PublicKey) (*wtdb.Tower, error)
    39  
    40  	// LoadTowerByID retrieves a tower by its tower ID.
    41  	LoadTowerByID(wtdb.TowerID) (*wtdb.Tower, error)
    42  
    43  	// ListTowers retrieves the list of towers available within the
    44  	// database.
    45  	ListTowers() ([]*wtdb.Tower, error)
    46  
    47  	// NextSessionKeyIndex reserves a new session key derivation index for a
    48  	// particular tower id and blob type. The index is reserved for that
    49  	// (tower, blob type) pair until CreateClientSession is invoked for that
    50  	// tower and index, at which point a new index for that tower can be
    51  	// reserved. Multiple calls to this method before CreateClientSession is
    52  	// invoked should return the same index.
    53  	NextSessionKeyIndex(wtdb.TowerID, blob.Type) (uint32, error)
    54  
    55  	// CreateClientSession saves a newly negotiated client session to the
    56  	// client's database. This enables the session to be used across
    57  	// restarts.
    58  	CreateClientSession(*wtdb.ClientSession) error
    59  
    60  	// ListClientSessions returns all sessions that have not yet been
    61  	// exhausted. This is used on startup to find any sessions which may
    62  	// still be able to accept state updates. An optional tower ID can be
    63  	// used to filter out any client sessions in the response that do not
    64  	// correspond to this tower.
    65  	ListClientSessions(*wtdb.TowerID) (map[wtdb.SessionID]*wtdb.ClientSession, error)
    66  
    67  	// FetchChanSummaries loads a mapping from all registered channels to
    68  	// their channel summaries.
    69  	FetchChanSummaries() (wtdb.ChannelSummaries, error)
    70  
    71  	// RegisterChannel registers a channel for use within the client
    72  	// database. For now, all that is stored in the channel summary is the
    73  	// sweep pkscript that we'd like any tower sweeps to pay into. In the
    74  	// future, this will be extended to contain more info to allow the
    75  	// client efficiently request historical states to be backed up under
    76  	// the client's active policy.
    77  	RegisterChannel(lnwire.ChannelID, []byte) error
    78  
    79  	// MarkBackupIneligible records that the state identified by the
    80  	// (channel id, commit height) tuple was ineligible for being backed up
    81  	// under the current policy. This state can be retried later under a
    82  	// different policy.
    83  	MarkBackupIneligible(chanID lnwire.ChannelID, commitHeight uint64) error
    84  
    85  	// CommitUpdate writes the next state update for a particular
    86  	// session, so that we can be sure to resend it after a restart if it
    87  	// hasn't been ACK'd by the tower. The sequence number of the update
    88  	// should be exactly one greater than the existing entry, and less that
    89  	// or equal to the session's MaxUpdates.
    90  	CommitUpdate(id *wtdb.SessionID,
    91  		update *wtdb.CommittedUpdate) (uint16, error)
    92  
    93  	// AckUpdate records an acknowledgment from the watchtower that the
    94  	// update identified by seqNum was received and saved. The returned
    95  	// lastApplied will be recorded.
    96  	AckUpdate(id *wtdb.SessionID, seqNum, lastApplied uint16) error
    97  }
    98  
    99  // AuthDialer connects to a remote node using an authenticated transport, such as
   100  // brontide. The dialer argument is used to specify a resolver, which allows
   101  // this method to be used over Tor or clear net connections.
   102  type AuthDialer func(localKey keychain.SingleKeyECDH,
   103  	netAddr *lnwire.NetAddress,
   104  	dialer tor.DialFunc) (wtserver.Peer, error)
   105  
   106  // ECDHKeyRing abstracts the ability to derive shared ECDH keys given a
   107  // description of the derivation path of a private key.
   108  type ECDHKeyRing interface {
   109  	keychain.ECDHRing
   110  
   111  	// DeriveKey attempts to derive an arbitrary key specified by the
   112  	// passed KeyLocator. This may be used in several recovery scenarios,
   113  	// or when manually rotating something like our current default node
   114  	// key.
   115  	DeriveKey(keyLoc keychain.KeyLocator) (keychain.KeyDescriptor, error)
   116  }