wtserver

package
v0.9.2-beta-branch Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

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

	// NoAckCreateSession causes the server to not reply to create session
	// requests, this should only be used for testing.
	NoAckCreateSession bool

	// NoAckUpdates causes the server to not acknowledge state updates, this
	// should only be used for testing.
	NoAckUpdates bool

	// DisableReward causes the server to reject any session creation
	// attempts that request rewards.
	DisableReward 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

func New(cfg *Config) (*Server, error)

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

func (s *Server) InboundPeerConnected(peer Peer)

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.

func (*Server) Start

func (s *Server) Start() error

Start begins listening on the server's listeners.

func (*Server) Stop

func (s *Server) Stop() error

Stop shutdowns down the server's listeners and any active requests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL