-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathinterface.go
66 lines (52 loc) · 2.04 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)
}