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