refactor: separate NetworkOverlay from Overlay

...since connections only need to know about the latter.
This commit is contained in:
Matthias Radestock committed 2015-11-09 15:47:07 +00:00
1 parent d78f6614cc
commit 18f8e29af8
6 files changed
+25 -21

No files matched your search

+1 -1
View File
@@ -150,7 +150,7 @@ func main() {
} }
config.ProtocolMinVersion = byte(protocolMinVersion) config.ProtocolMinVersion = byte(protocolMinVersion)
var fastDPOverlay weave.Overlay var fastDPOverlay weave.NetworkOverlay
if datapathName != "" { if datapathName != "" {
// A datapath name implies that "Bridge" and "Overlay" // A datapath name implies that "Bridge" and "Overlay"
// packet handling use fast datapath, although other // packet handling use fast datapath, although other
+1 -1
View File
@@ -297,7 +297,7 @@ type fastDatapathOverlay struct {
*FastDatapath *FastDatapath
} }
func (fastdp *FastDatapath) Overlay() Overlay { func (fastdp *FastDatapath) Overlay() NetworkOverlay {
return fastDatapathOverlay{fastdp} return fastDatapathOverlay{fastdp}
} }
+12 -8
View File
@@ -4,15 +4,22 @@ import (
"net" "net"
) )
// Interface to overlay network packet handling
type Overlay interface { type Overlay interface {
// Start consuming forwarded packets. // Enhance a features map with overlay-related features
StartConsumingPackets(*Peer, *Peers, OverlayConsumer) error AddFeaturesTo(map[string]string)
// Prepare on overlay connection. The connection should remain // Prepare on overlay connection. The connection should remain
// passive until it has been Confirm()ed. // passive until it has been Confirm()ed.
PrepareConnection(OverlayConnectionParams) (OverlayConnection, error) PrepareConnection(OverlayConnectionParams) (OverlayConnection, error)
// Obtain diagnostic information specific to the overlay
Diagnostics() interface{}
}
// Interface to overlay network packet handling
type NetworkOverlay interface {
Overlay
// The routes have changed, so any cached information should // The routes have changed, so any cached information should
// be discarded. // be discarded.
InvalidateRoutes() InvalidateRoutes()
@@ -20,11 +27,8 @@ type Overlay interface {
// A mapping of a short id to a peer has changed // A mapping of a short id to a peer has changed
InvalidateShortIDs() InvalidateShortIDs()
// Enhance a features map with overlay-related features // Start consuming forwarded packets.
AddFeaturesTo(map[string]string) StartConsumingPackets(*Peer, *Peers, OverlayConsumer) error
// Obtain diagnostic information specific to the overlay
Diagnostics() interface{}
} }
type OverlayConnectionParams struct { type OverlayConnectionParams struct {
+7 -7
View File
@@ -13,16 +13,16 @@ import (
// uses the best one that seems to be working. // uses the best one that seems to be working.
type OverlaySwitch struct { type OverlaySwitch struct {
overlays map[string]Overlay overlays map[string]NetworkOverlay
overlayNames []string overlayNames []string
compatOverlay Overlay compatOverlay NetworkOverlay
} }
func NewOverlaySwitch() *OverlaySwitch { func NewOverlaySwitch() *OverlaySwitch {
return &OverlaySwitch{overlays: make(map[string]Overlay)} return &OverlaySwitch{overlays: make(map[string]NetworkOverlay)}
} }
func (osw *OverlaySwitch) Add(name string, overlay Overlay) { func (osw *OverlaySwitch) Add(name string, overlay NetworkOverlay) {
// check for repeated names // check for repeated names
if _, present := osw.overlays[name]; present { if _, present := osw.overlays[name]; present {
log.Fatal("OverlaySwitch: repeated overlay name") log.Fatal("OverlaySwitch: repeated overlay name")
@@ -32,7 +32,7 @@ func (osw *OverlaySwitch) Add(name string, overlay Overlay) {
osw.overlayNames = append(osw.overlayNames, name) osw.overlayNames = append(osw.overlayNames, name)
} }
func (osw *OverlaySwitch) SetCompatOverlay(overlay Overlay) { func (osw *OverlaySwitch) SetCompatOverlay(overlay NetworkOverlay) {
osw.compatOverlay = overlay osw.compatOverlay = overlay
} }
@@ -70,7 +70,7 @@ func (osw *OverlaySwitch) StartConsumingPackets(localPeer *Peer, peers *Peers, c
} }
type namedOverlay struct { type namedOverlay struct {
Overlay NetworkOverlay
name string name string
} }
@@ -82,7 +82,7 @@ func (osw *OverlaySwitch) commonOverlays(params OverlayConnectionParams) ([]name
peerOverlays = strings.Split(overlaysFeature, " ") peerOverlays = strings.Split(overlaysFeature, " ")
} }
common := make(map[string]Overlay) common := make(map[string]NetworkOverlay)
for _, name := range peerOverlays { for _, name := range peerOverlays {
if overlay := osw.overlays[name]; overlay != nil { if overlay := osw.overlays[name]; overlay != nil {
common[name] = overlay common[name] = overlay
+3 -3
View File
@@ -70,7 +70,7 @@ type Router struct {
acceptLimiter *TokenBucket acceptLimiter *TokenBucket
} }
func NewRouter(config Config, name PeerName, nickName string, overlay Overlay) *Router { func NewRouter(config Config, name PeerName, nickName string, overlay NetworkOverlay) *Router {
router := &Router{Config: config, gossipChannels: make(GossipChannels)} router := &Router{Config: config, gossipChannels: make(GossipChannels)}
if router.Bridge == nil { if router.Bridge == nil {
@@ -108,7 +108,7 @@ func NewRouter(config Config, name PeerName, nickName string, overlay Overlay) *
func (router *Router) Start() { func (router *Router) Start() {
log.Println("Sniffing traffic on", router.Bridge) log.Println("Sniffing traffic on", router.Bridge)
checkFatal(router.Bridge.StartConsumingPackets(router.handleCapturedPacket)) checkFatal(router.Bridge.StartConsumingPackets(router.handleCapturedPacket))
checkFatal(router.Overlay.StartConsumingPackets(router.Ourself.Peer, router.Peers, router.handleForwardedPacket)) checkFatal(router.Overlay.(NetworkOverlay).StartConsumingPackets(router.Ourself.Peer, router.Peers, router.handleForwardedPacket))
router.listenTCP(router.Port) router.listenTCP(router.Port)
} }
@@ -218,7 +218,7 @@ func (router *Router) handleForwardedPacket(key ForwardPacketKey) FlowOp {
// We need to clear out any flows destined to the MAC // We need to clear out any flows destined to the MAC
// that forward to the old peer. // that forward to the old peer.
router.Overlay.InvalidateRoutes() router.Overlay.(NetworkOverlay).InvalidateRoutes()
} }
router.PacketLogging.LogForwardPacket("Injecting", key) router.PacketLogging.LogForwardPacket("Injecting", key)
+1 -1
View File
@@ -71,7 +71,7 @@ type SleeveOverlay struct {
forwarders map[PeerName]*sleeveForwarder forwarders map[PeerName]*sleeveForwarder
} }
func NewSleeveOverlay(localPort int) Overlay { func NewSleeveOverlay(localPort int) NetworkOverlay {
return &SleeveOverlay{localPort: localPort} return &SleeveOverlay{localPort: localPort}
} }