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

     1  package wtserver
     2  
     3  import (
     4  	"io"
     5  	"net"
     6  	"time"
     7  
     8  	"github.com/decred/dcrd/dcrec/secp256k1/v4"
     9  	"github.com/decred/dcrlnd/watchtower/wtdb"
    10  )
    11  
    12  // Interface represents a simple, listen-only service that accepts watchtower
    13  // clients, and provides responses to their requests.
    14  type Interface interface {
    15  	// InboundPeerConnected accepts a new watchtower client, and handles any
    16  	// requests sent by the peer.
    17  	InboundPeerConnected(Peer)
    18  
    19  	// Start sets up the watchtower server.
    20  	Start() error
    21  
    22  	// Stop cleans up the watchtower's current connections and resources.
    23  	Stop() error
    24  }
    25  
    26  // Peer is the primary interface used to abstract watchtower clients.
    27  type Peer interface {
    28  	io.WriteCloser
    29  
    30  	// ReadNextMessage pulls the next framed message from the client.
    31  	ReadNextMessage() ([]byte, error)
    32  
    33  	// SetWriteDeadline specifies the time by which the client must have
    34  	// read a message sent by the server. In practice, the connection is
    35  	// buffered, so the client must read enough from the connection to
    36  	// support the server adding another reply.
    37  	SetWriteDeadline(time.Time) error
    38  
    39  	// SetReadDeadline specifies the time by which the client must send
    40  	// another message.
    41  	SetReadDeadline(time.Time) error
    42  
    43  	// RemotePub returns the client's public key.
    44  	RemotePub() *secp256k1.PublicKey
    45  
    46  	// RemoteAddr returns the client's network address.
    47  	RemoteAddr() net.Addr
    48  }
    49  
    50  // DB provides the server access to session creation and retrieval, as well as
    51  // persisting state updates sent by clients.
    52  type DB interface {
    53  	// InsertSessionInfo saves a newly agreed-upon session from a client.
    54  	// This method should fail if a session with the same session id already
    55  	// exists.
    56  	InsertSessionInfo(*wtdb.SessionInfo) error
    57  
    58  	// GetSessionInfo retrieves the SessionInfo associated with the session
    59  	// id, if it exists.
    60  	GetSessionInfo(*wtdb.SessionID) (*wtdb.SessionInfo, error)
    61  
    62  	// InsertStateUpdate persists a state update sent by a client, and
    63  	// validates the update against the current SessionInfo stored under the
    64  	// update's session id..
    65  	InsertStateUpdate(*wtdb.SessionStateUpdate) (uint16, error)
    66  
    67  	// DeleteSession removes all data associated with a particular session
    68  	// id from the tower's database.
    69  	DeleteSession(wtdb.SessionID) error
    70  }