introduce '-nodiscovery' option to disable automatic peer discovery

Closes #847.
This commit is contained in:
Matthias Radestock committed 2015-06-05 15:13:48 +01:00
1 parent 5f5c0079d3
commit 8f85a07ecc
7 files changed
+40 -19

No files matched your search

+3
View File
@@ -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)
+6 -2
View File
@@ -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)
}
+10 -9
View File
@@ -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) {
+9 -7
View File
@@ -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)
+5
View File
@@ -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`.
### <a name="container-mobility"></a>Container mobility
Containers can be moved between hosts without requiring any
+5
View File
@@ -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
+2 -1
View File
@@ -25,7 +25,8 @@ CIDR_REGEXP="$IP_REGEXP/[0-9]{1,2}"
usage() {
echo "Usage:"
echo "weave setup"
echo "weave launch [-password <password>] [-nickname <nickname>] [-iprange <cidr>] <peer> ..."
echo "weave launch [-password <password>] [-nickname <nickname>] [-nodiscovery]"
echo " [-iprange <cidr>] <peer> ..."
echo "weave launch-dns <cidr>"
echo "weave launch-proxy [-H <docker_endpoint>] [--with-dns] [--with-ipam]"
echo "weave connect [--replace] [<peer> ...]"