watchtower/server/interface: adds Server, Peer and DB
This commit is contained in:
parent
a3e1bb15c5
commit
48643a1747
66
watchtower/server/interface.go
Normal file
66
watchtower/server/interface.go
Normal file
@ -0,0 +1,66 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user