lnd/watchtower/wtserver/interface.go
Oliver Gugger 7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00

71 lines
2.2 KiB
Go

package wtserver
import (
"io"
"net"
"time"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/watchtower/wtdb"
)
// Interface represents a simple, listen-only service that accepts watchtower
// clients, and provides responses to their requests.
type Interface interface {
// InboundPeerConnected accepts a new watchtower client, and handles any
// requests sent by the peer.
InboundPeerConnected(Peer)
// Start sets up the watchtower server.
Start() error
// Stop cleans up the watchtower's current connections and resources.
Stop() error
}
// Peer is the primary interface used to abstract watchtower clients.
type Peer interface {
io.WriteCloser
// ReadNextMessage pulls the next framed message from the client.
ReadNextMessage() ([]byte, error)
// SetWriteDeadline specifies the time by which the client must have
// read a message sent by the server. In practice, the connection is
// buffered, so the client must read enough from the connection to
// support the server adding another reply.
SetWriteDeadline(time.Time) error
// SetReadDeadline specifies the time by which the client must send
// another message.
SetReadDeadline(time.Time) error
// RemotePub returns the client's public key.
RemotePub() *btcec.PublicKey
// RemoteAddr returns the client's network address.
RemoteAddr() net.Addr
}
// DB provides the server access to session creation and retrieval, as well as
// persisting state updates sent by clients.
type DB interface {
// InsertSessionInfo saves a newly agreed-upon session from a client.
// This method should fail if a session with the same session id already
// exists.
InsertSessionInfo(*wtdb.SessionInfo) error
// GetSessionInfo retrieves the SessionInfo associated with the session
// id, if it exists.
GetSessionInfo(*wtdb.SessionID) (*wtdb.SessionInfo, error)
// InsertStateUpdate persists a state update sent by a client, and
// validates the update against the current SessionInfo stored under the
// update's session id..
InsertStateUpdate(*wtdb.SessionStateUpdate) (uint16, error)
// DeleteSession removes all data associated with a particular session
// id from the tower's database.
DeleteSession(wtdb.SessionID) error
}