extract our peer name creation

This commit is contained in:
Matthias Radestock committed 2016-01-13 16:23:00 +00:00
1 parent b4682bbc8c
commit 6261ce0865
1 file changed
+20 -18
+20 -18
View File
@@ -133,17 +133,10 @@ func main() {
overlay, bridge := createOverlay(datapathName, ifaceName, config.Port, bufSzMB) overlay, bridge := createOverlay(datapathName, ifaceName, config.Port, bufSzMB)
networkConfig.Bridge = bridge networkConfig.Bridge = bridge
if routerName == "" { name := peerName(routerName, bridge.Interface())
iface := bridge.Interface()
if iface == nil {
Log.Fatal("Either an interface must be specified with --datapath or --iface, or a name with --name")
}
routerName = iface.HardwareAddr.String()
}
name, err := mesh.PeerNameFromUserInput(routerName)
checkFatal(err)
if nickName == "" { if nickName == "" {
var err error
nickName, err = os.Hostname() nickName, err = os.Hostname()
checkFatal(err) checkFatal(err)
} }
@@ -173,9 +166,7 @@ func main() {
networkConfig.PacketLogging = nopPacketLogging{} networkConfig.PacketLogging = nopPacketLogging{}
} }
if config.TrustedSubnets, err = parseTrustedSubnets(trustedSubnetStr); err != nil { config.TrustedSubnets = parseTrustedSubnets(trustedSubnetStr)
Log.Fatal("Unable to parse trusted subnets: ", err)
}
router := weave.NewNetworkRouter(config, networkConfig, name, nickName, overlay) router := weave.NewNetworkRouter(config, networkConfig, name, nickName, overlay)
Log.Println("Our name is", router.Ourself) Log.Println("Our name is", router.Ourself)
@@ -192,7 +183,7 @@ func main() {
} }
observeContainers := func(o docker.ContainerObserver) { observeContainers := func(o docker.ContainerObserver) {
if dockerCli != nil { if dockerCli != nil {
if err = dockerCli.AddObserver(o); err != nil { if err := dockerCli.AddObserver(o); err != nil {
Log.Fatal("Unable to start watcher", err) Log.Fatal("Unable to start watcher", err)
} }
} }
@@ -380,22 +371,33 @@ func determineQuorum(initPeerCountFlag int, peers []string) uint {
return quorum return quorum
} }
func parseTrustedSubnets(trustedSubnetStr string) ([]*net.IPNet, error) { func peerName(routerName string, iface *net.Interface) mesh.PeerName {
trustedSubnets := []*net.IPNet{} if routerName == "" {
if iface == nil {
Log.Fatal("Either an interface must be specified with --datapath or --iface, or a name with --name")
}
routerName = iface.HardwareAddr.String()
}
name, err := mesh.PeerNameFromUserInput(routerName)
checkFatal(err)
return name
}
func parseTrustedSubnets(trustedSubnetStr string) []*net.IPNet {
trustedSubnets := []*net.IPNet{}
if trustedSubnetStr == "" { if trustedSubnetStr == "" {
return trustedSubnets, nil return trustedSubnets
} }
for _, subnetStr := range strings.Split(trustedSubnetStr, ",") { for _, subnetStr := range strings.Split(trustedSubnetStr, ",") {
_, subnet, err := net.ParseCIDR(subnetStr) _, subnet, err := net.ParseCIDR(subnetStr)
if err != nil { if err != nil {
return nil, err Log.Fatal("Unable to parse trusted subnets: ", err)
} }
trustedSubnets = append(trustedSubnets, subnet) trustedSubnets = append(trustedSubnets, subnet)
} }
return trustedSubnets, nil return trustedSubnets
} }
func listenAndServeHTTP(httpAddr string, muxRouter *mux.Router) { func listenAndServeHTTP(httpAddr string, muxRouter *mux.Router) {