github.com/decred/dcrlnd@v0.7.6/peer/interfaces.go (about)

     1  package peer
     2  
     3  import (
     4  	"net"
     5  	"time"
     6  
     7  	"github.com/decred/dcrlnd/htlcswitch"
     8  	"github.com/decred/dcrlnd/lnwallet"
     9  	"github.com/decred/dcrlnd/lnwire"
    10  )
    11  
    12  // messageSwitch is an interface that abstracts managing the lifecycle of
    13  // abstract links. This is intended for peer package usage only.
    14  type messageSwitch interface {
    15  	// BestHeight returns the best height known to the messageSwitch.
    16  	BestHeight() uint32
    17  
    18  	// CircuitModifier returns a reference to the messageSwitch's internal
    19  	// CircuitModifier which abstracts the paths payments take and allows
    20  	// modifying them.
    21  	CircuitModifier() htlcswitch.CircuitModifier
    22  
    23  	// RemoveLink removes an abstract link given a ChannelID.
    24  	RemoveLink(cid lnwire.ChannelID)
    25  
    26  	// CreateAndAddLink creates an abstract link in the messageSwitch given
    27  	// a ChannelLinkConfig and raw LightningChannel pointer.
    28  	CreateAndAddLink(cfg htlcswitch.ChannelLinkConfig,
    29  		lnChan *lnwallet.LightningChannel) error
    30  
    31  	// GetLinksByInterface retrieves abstract links (represented by the
    32  	// ChannelUpdateHandler interface) based on the provided public key.
    33  	GetLinksByInterface(pub [33]byte) ([]htlcswitch.ChannelUpdateHandler,
    34  		error)
    35  }
    36  
    37  // LinkUpdater is an interface implemented by most messages in BOLT 2 that are
    38  // allowed to update the channel state.
    39  type LinkUpdater interface {
    40  	// TargetChanID returns the channel id of the link for which this message
    41  	// is intended.
    42  	TargetChanID() lnwire.ChannelID
    43  }
    44  
    45  // MessageConn is an interface implemented by anything that delivers
    46  // an lnwire.Message using a net.Conn interface.
    47  type MessageConn interface {
    48  	// RemoteAddr returns the remote address on the other end of the connection.
    49  	RemoteAddr() net.Addr
    50  
    51  	// LocalAddr returns the local address on our end of the connection.
    52  	LocalAddr() net.Addr
    53  
    54  	// Read reads bytes from the connection.
    55  	Read([]byte) (int, error)
    56  
    57  	// Write writes bytes to the connection.
    58  	Write([]byte) (int, error)
    59  
    60  	// SetDeadline sets the deadline for the connection.
    61  	SetDeadline(time.Time) error
    62  
    63  	// SetReadDeadline sets the read deadline.
    64  	SetReadDeadline(time.Time) error
    65  
    66  	// SetWriteDeadline sets the write deadline.
    67  	SetWriteDeadline(time.Time) error
    68  
    69  	// Close closes the connection.
    70  	Close() error
    71  
    72  	// Flush attempts a flush.
    73  	Flush() (int, error)
    74  
    75  	// WriteMessage writes the message.
    76  	WriteMessage([]byte) error
    77  
    78  	// ReadNextHeader reads the next header.
    79  	ReadNextHeader() (uint32, error)
    80  
    81  	// ReadNextBody reads the next body.
    82  	ReadNextBody([]byte) ([]byte, error)
    83  }