From 8f85a07ecc853869473029b7706c6f7bd7ff413c Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 5 Jun 2015 11:44:52 +0100 Subject: [PATCH] introduce '-nodiscovery' option to disable automatic peer discovery Closes #847. --- prog/weaver/main.go | 3 +++ router/connection_maker.go | 8 ++++++-- router/json.go | 19 ++++++++++--------- router/router.go | 16 +++++++++------- site/features.md | 5 +++++ site/troubleshooting.md | 5 +++++ weave | 3 ++- 7 files changed, 40 insertions(+), 19 deletions(-) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index 68a5133f..e59b4202 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -48,6 +48,7 @@ func main() { pktdebug bool prof string bufSzMB int + noDiscovery bool httpAddr string iprangeCIDR string peerCount int @@ -66,6 +67,7 @@ func main() { flag.BoolVar(&pktdebug, "pktdebug", false, "enable per-packet debug logging") flag.StringVar(&prof, "profile", "", "enable profiling and write profiles to given path") flag.IntVar(&config.ConnLimit, "connlimit", 30, "connection limit (0 for unlimited)") + flag.BoolVar(&noDiscovery, "nodiscovery", false, "disable peer discovery") flag.IntVar(&bufSzMB, "bufsz", 8, "capture buffer size in MB") flag.StringVar(&httpAddr, "httpaddr", fmt.Sprintf(":%d", weave.HTTPPort), "address to bind HTTP interface to (disabled if blank, absolute path indicates unix domain socket)") flag.StringVar(&iprangeCIDR, "iprange", "", "IP address range to allocate within, in CIDR notation") @@ -129,6 +131,7 @@ func main() { config.BufSz = bufSzMB * 1024 * 1024 config.LogFrame = logFrameFunc(pktdebug) + config.PeerDiscovery = !noDiscovery router := weave.NewRouter(config, name, nickName) log.Println("Our name is", router.Ourself) diff --git a/router/connection_maker.go b/router/connection_maker.go index db62b876..57a93a06 100644 --- a/router/connection_maker.go +++ b/router/connection_maker.go @@ -20,6 +20,7 @@ type ConnectionMaker struct { ourself *LocalPeer peers *Peers port int + discovery bool targets map[string]*Target directPeers peerAddrs actionChan chan<- ConnectionMakerAction @@ -35,11 +36,12 @@ type Target struct { type ConnectionMakerAction func() bool -func NewConnectionMaker(ourself *LocalPeer, peers *Peers, port int) *ConnectionMaker { +func NewConnectionMaker(ourself *LocalPeer, peers *Peers, port int, discovery bool) *ConnectionMaker { return &ConnectionMaker{ ourself: ourself, peers: peers, port: port, + discovery: discovery, directPeers: peerAddrs{}, targets: make(map[string]*Target)} } @@ -217,7 +219,9 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections() time.Duration { // Add targets for peers that someone else is connected to, but we // aren't - cm.addPeerTargets(ourConnectedPeers, addTarget) + if cm.discovery { + cm.addPeerTargets(ourConnectedPeers, addTarget) + } return cm.connectToTargets(validTarget, directTarget) } diff --git a/router/json.go b/router/json.go index 24eef73f..fd988067 100644 --- a/router/json.go +++ b/router/json.go @@ -8,16 +8,17 @@ import ( func (router *Router) StatusJSON(version string) ([]byte, error) { return json.Marshal(struct { - Version string - Encryption bool - Name string - NickName string - Interface string - Macs *MacCache - Peers *Peers - Routes *Routes + Version string + Encryption bool + PeerDiscovery bool + Name string + NickName string + Interface string + Macs *MacCache + Peers *Peers + Routes *Routes ConnectionMakerStatus - }{version, router.UsingPassword(), router.Ourself.Name.String(), router.Ourself.NickName, fmt.Sprintf("%v", router.Iface), router.Macs, router.Peers, router.Routes, router.ConnectionMaker.Status()}) + }{version, router.UsingPassword(), router.PeerDiscovery, router.Ourself.Name.String(), router.Ourself.NickName, fmt.Sprintf("%v", router.Iface), router.Macs, router.Peers, router.Routes, router.ConnectionMaker.Status()}) } func (cache *MacCache) MarshalJSON() ([]byte, error) { diff --git a/router/router.go b/router/router.go index afe80ad2..c0805d14 100644 --- a/router/router.go +++ b/router/router.go @@ -29,12 +29,13 @@ const ( type LogFrameFunc func(string, []byte, *layers.Ethernet) type Config struct { - Port int - Iface *net.Interface - Password []byte - ConnLimit int - BufSz int - LogFrame LogFrameFunc + Port int + Iface *net.Interface + Password []byte + ConnLimit int + PeerDiscovery bool + BufSz int + LogFrame LogFrameFunc } type Router struct { @@ -76,7 +77,7 @@ func NewRouter(config Config, name PeerName, nickName string) *Router { router.Peers = NewPeers(router.Ourself, onPeerGC) router.Peers.FetchWithDefault(router.Ourself.Peer) router.Routes = NewRoutes(router.Ourself, router.Peers) - router.ConnectionMaker = NewConnectionMaker(router.Ourself, router.Peers, router.Port) + router.ConnectionMaker = NewConnectionMaker(router.Ourself, router.Peers, router.Port, router.PeerDiscovery) router.TopologyGossip = router.NewGossip("topology", router) return router } @@ -116,6 +117,7 @@ func (router *Router) Status() string { var buf bytes.Buffer fmt.Fprintln(&buf, "Our name is", router.Ourself) fmt.Fprintln(&buf, "Encryption", OnOff(router.UsingPassword())) + fmt.Fprintln(&buf, "Peer discovery", OnOff(router.PeerDiscovery)) fmt.Fprintln(&buf, "Sniffing traffic on", router.Iface) fmt.Fprintf(&buf, "MACs:\n%s", router.Macs) fmt.Fprintf(&buf, "Peers:\n%s", router.Peers) diff --git a/site/features.md b/site/features.md index 6a56209a..2d5b49f5 100644 --- a/site/features.md +++ b/site/features.md @@ -377,6 +377,11 @@ and the new hosts will be added, when one runs host# weave connect --replace $NEW_HOST1 $NEW_HOST2 +For complete control over the peer topology, automatic discovery can +be disabled with the `-nodiscovery` option to `weave launch`. In this +mode, weave will only connect to the addresses specified at launch +time and with `weave connect`. + ### Container mobility Containers can be moved between hosts without requiring any diff --git a/site/troubleshooting.md b/site/troubleshooting.md index 28e3e66d..4d5de954 100644 --- a/site/troubleshooting.md +++ b/site/troubleshooting.md @@ -63,6 +63,7 @@ This produces output like: weave router 0.7.0 Our name is 7a:f4:56:87:76:3b(weave01) Encryption off +Peer discovery on Sniffing traffic on &{39 65535 ethwe ae:e3:07:9c:8c:d4 up|broadcast|multicast} MACs: ba:8c:b9:dc:e1:c9 -> 7a:f4:56:87:76:3b(weave01) (2014-10-23 16:39:19.482338935 +0000 UTC) @@ -104,6 +105,10 @@ The 'Encryption' line indicates whether [encryption](features.html#security) is in use for communication between peers. +The 'Peer discovery' line indicates whether +[automatic peer discovery](features.html#dynamic-topologies) is +enabled (which is the default). + The 'MACs' section lists all MAC addresses known to this router. These identify containers in the weave network, as well as points for [host network integration](features.html#host-network-integration). For diff --git a/weave b/weave index 3933c2d3..bedc738d 100755 --- a/weave +++ b/weave @@ -25,7 +25,8 @@ CIDR_REGEXP="$IP_REGEXP/[0-9]{1,2}" usage() { echo "Usage:" echo "weave setup" - echo "weave launch [-password ] [-nickname ] [-iprange ] ..." + echo "weave launch [-password ] [-nickname ] [-nodiscovery]" + echo " [-iprange ] ..." echo "weave launch-dns " echo "weave launch-proxy [-H ] [--with-dns] [--with-ipam]" echo "weave connect [--replace] [ ...]"