refactor: split overlay.go to extract network overlay stuff
This commit is contained in:
1 parent
7cc0052451
commit
daad190188
2 files changed
+46
-45
No files matched your search
@@ -0,0 +1,46 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
// Interface to overlay network packet handling
|
||||||
|
type NetworkOverlay interface {
|
||||||
|
Overlay
|
||||||
|
|
||||||
|
// The routes have changed, so any cached information should
|
||||||
|
// be discarded.
|
||||||
|
InvalidateRoutes()
|
||||||
|
|
||||||
|
// A mapping of a short id to a peer has changed
|
||||||
|
InvalidateShortIDs()
|
||||||
|
|
||||||
|
// Start consuming forwarded packets.
|
||||||
|
StartConsumingPackets(*Peer, *Peers, OverlayConsumer) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// When a consumer is called, the decoder will already have been used
|
||||||
|
// to decode the frame.
|
||||||
|
type OverlayConsumer func(ForwardPacketKey) FlowOp
|
||||||
|
|
||||||
|
// All of the machinery to forward packets to a particular peer
|
||||||
|
type OverlayForwarder interface {
|
||||||
|
OverlayConnection
|
||||||
|
// Forward a packet across the connection. May be called as soon
|
||||||
|
// as the overlay connection is created, in particular before
|
||||||
|
// Confirm(). The return value nil means the key could not be
|
||||||
|
// handled by this forwarder.
|
||||||
|
Forward(ForwardPacketKey) FlowOp
|
||||||
|
}
|
||||||
|
|
||||||
|
type NullNetworkOverlay struct{ NullOverlay }
|
||||||
|
|
||||||
|
func (NullNetworkOverlay) InvalidateRoutes() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (NullNetworkOverlay) InvalidateShortIDs() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (NullNetworkOverlay) StartConsumingPackets(*Peer, *Peers, OverlayConsumer) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (NullNetworkOverlay) Forward(ForwardPacketKey) FlowOp {
|
||||||
|
return DiscardingFlowOp{}
|
||||||
|
}
|
||||||
@@ -16,21 +16,6 @@ type Overlay interface {
|
|||||||
Diagnostics() interface{}
|
Diagnostics() interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface to overlay network packet handling
|
|
||||||
type NetworkOverlay interface {
|
|
||||||
Overlay
|
|
||||||
|
|
||||||
// The routes have changed, so any cached information should
|
|
||||||
// be discarded.
|
|
||||||
InvalidateRoutes()
|
|
||||||
|
|
||||||
// A mapping of a short id to a peer has changed
|
|
||||||
InvalidateShortIDs()
|
|
||||||
|
|
||||||
// Start consuming forwarded packets.
|
|
||||||
StartConsumingPackets(*Peer, *Peers, OverlayConsumer) error
|
|
||||||
}
|
|
||||||
|
|
||||||
type OverlayConnectionParams struct {
|
type OverlayConnectionParams struct {
|
||||||
RemotePeer *Peer
|
RemotePeer *Peer
|
||||||
|
|
||||||
@@ -62,10 +47,6 @@ type OverlayConnectionParams struct {
|
|||||||
Features map[string]string
|
Features map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a consumer is called, the decoder will already have been used
|
|
||||||
// to decode the frame.
|
|
||||||
type OverlayConsumer func(ForwardPacketKey) FlowOp
|
|
||||||
|
|
||||||
// All of the machinery to manage overlay connectivity to a particular
|
// All of the machinery to manage overlay connectivity to a particular
|
||||||
// peer
|
// peer
|
||||||
type OverlayConnection interface {
|
type OverlayConnection interface {
|
||||||
@@ -95,16 +76,6 @@ type OverlayConnection interface {
|
|||||||
DisplayName() string
|
DisplayName() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// All of the machinery to forward packets to a particular peer
|
|
||||||
type OverlayForwarder interface {
|
|
||||||
OverlayConnection
|
|
||||||
// Forward a packet across the connection. May be called as soon
|
|
||||||
// as the overlay connection is created, in particular before
|
|
||||||
// Confirm(). The return value nil means the key could not be
|
|
||||||
// handled by this forwarder.
|
|
||||||
Forward(ForwardPacketKey) FlowOp
|
|
||||||
}
|
|
||||||
|
|
||||||
type NullOverlay struct{}
|
type NullOverlay struct{}
|
||||||
|
|
||||||
func (NullOverlay) AddFeaturesTo(map[string]string) {
|
func (NullOverlay) AddFeaturesTo(map[string]string) {
|
||||||
@@ -137,19 +108,3 @@ func (NullOverlay) ControlMessage(byte, []byte) {
|
|||||||
func (NullOverlay) DisplayName() string {
|
func (NullOverlay) DisplayName() string {
|
||||||
return "null"
|
return "null"
|
||||||
}
|
}
|
||||||
|
|
||||||
type NullNetworkOverlay struct{ NullOverlay }
|
|
||||||
|
|
||||||
func (NullNetworkOverlay) InvalidateRoutes() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (NullNetworkOverlay) InvalidateShortIDs() {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (NullNetworkOverlay) StartConsumingPackets(*Peer, *Peers, OverlayConsumer) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (NullNetworkOverlay) Forward(ForwardPacketKey) FlowOp {
|
|
||||||
return DiscardingFlowOp{}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user