Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPeerAlreadyConnected signals that a peer with the same session id // is already active within the server. ErrPeerAlreadyConnected = errors.New("peer already connected") // ErrServerExiting signals that a request could not be processed // because the server has been requested to shut down. ErrServerExiting = errors.New("server shutting down") )
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
Types ¶
type Config ¶
type Config struct { // DB provides persistent access to the server's sessions and for // storing state updates. DB DB // NodePrivKey is private key to be used in accepting new brontide // connections. NodePrivKey *btcec.PrivateKey // Listeners specifies which address to which clients may connect. Listeners []net.Listener // ReadTimeout specifies how long a client may go without sending a // message. ReadTimeout time.Duration // WriteTimeout specifies how long a client may go without reading a // message from the other end, if the connection has stopped buffering // the server's replies. WriteTimeout time.Duration // NewAddress is used to generate reward addresses, where a cut of // successfully sent funds can be received. NewAddress func() (btcutil.Address, error) // ChainHash identifies the network that the server is watching. ChainHash chainhash.Hash // NoAckUpdates causes the server to not acknowledge state updates, this // should only be used for testing. NoAckUpdates bool }
Config abstracts the primary components and dependencies of the server.
type DB ¶
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 }
DB provides the server access to session creation and retrieval, as well as persisting state updates sent by clients.
type Interface ¶
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 }
Interface represents a simple, listen-only service that accepts watchtower clients, and provides responses to their requests.
type Peer ¶
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 }
Peer is the primary interface used to abstract watchtower clients.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server houses the state required to handle watchtower peers. It's primary job is to accept incoming connections, and dispatch processing of the client message streams.
func New ¶
New creates a new server to handle watchtower clients. The server will accept clients connecting to the listener addresses, and allows them to open sessions and send state updates.
func (*Server) InboundPeerConnected ¶
InboundPeerConnected accepts a server.Peer, and handles the request submitted by the client. This method serves also as a public endpoint for locally registering new clients with the server.