/ peer / interfaces.go
interfaces.go
 1  package peer
 2  
 3  import (
 4  	"net"
 5  	"time"
 6  
 7  	"github.com/lightningnetwork/lnd/htlcswitch"
 8  	"github.com/lightningnetwork/lnd/lnwallet"
 9  	"github.com/lightningnetwork/lnd/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  // MessageConn is an interface implemented by anything that delivers
38  // an lnwire.Message using a net.Conn interface.
39  type MessageConn interface {
40  	// RemoteAddr returns the remote address on the other end of the connection.
41  	RemoteAddr() net.Addr
42  
43  	// LocalAddr returns the local address on our end of the connection.
44  	LocalAddr() net.Addr
45  
46  	// Read reads bytes from the connection.
47  	Read([]byte) (int, error)
48  
49  	// Write writes bytes to the connection.
50  	Write([]byte) (int, error)
51  
52  	// SetDeadline sets the deadline for the connection.
53  	SetDeadline(time.Time) error
54  
55  	// SetReadDeadline sets the read deadline.
56  	SetReadDeadline(time.Time) error
57  
58  	// SetWriteDeadline sets the write deadline.
59  	SetWriteDeadline(time.Time) error
60  
61  	// Close closes the connection.
62  	Close() error
63  
64  	// Flush attempts a flush.
65  	Flush() (int, error)
66  
67  	// WriteMessage writes the message.
68  	WriteMessage([]byte) error
69  
70  	// ReadNextHeader reads the next header.
71  	ReadNextHeader() (uint32, error)
72  
73  	// ReadNextBody reads the next body.
74  	ReadNextBody([]byte) ([]byte, error)
75  }