func createAllocator(router *weave.NetworkRouter, config ipamConfig, db db.DB, track tracker.LocalRangeTracker, isKnownPeer func(mesh.PeerName) bool) (*ipam.Allocator, address.CIDR) { ipRange, err := ipam.ParseCIDRSubnet(config.IPRangeCIDR) checkFatal(err) defaultSubnet := ipRange if config.IPSubnetCIDR != "" { defaultSubnet, err = ipam.ParseCIDRSubnet(config.IPSubnetCIDR) checkFatal(err) if !ipRange.Range().Overlaps(defaultSubnet.Range()) { Log.Fatalf("IP address allocation default subnet %s does not overlap with allocation range %s", defaultSubnet, ipRange) } } c := ipam.Config{ OurName: router.Ourself.Peer.Name, OurUID: router.Ourself.Peer.UID, OurNickname: router.Ourself.Peer.NickName, Seed: config.SeedPeerNames, Universe: ipRange, IsObserver: config.Observer, Quorum: func() uint { return determineQuorum(config.PeerCount, router) }, Db: db, IsKnownPeer: isKnownPeer, Tracker: track, } allocator := ipam.NewAllocator(c) allocator.SetInterfaces(router.NewGossip("IPallocation", allocator)) allocator.Start() router.Peers.OnGC(func(peer *mesh.Peer) { allocator.PeerGone(peer.Name) }) return allocator, defaultSubnet }
func createAllocator(router *weave.Router, ipRangeStr string, defaultSubnetStr string, quorum uint) (*ipam.Allocator, address.CIDR) { ipRange := parseAndCheckCIDR(ipRangeStr) defaultSubnet := ipRange if defaultSubnetStr != "" { defaultSubnet = parseAndCheckCIDR(defaultSubnetStr) if !ipRange.Range().Overlaps(defaultSubnet.Range()) { Log.Fatalf("Default subnet %s out of bounds: %s", defaultSubnet, ipRange) } } allocator := ipam.NewAllocator(router.Ourself.Peer.Name, router.Ourself.Peer.UID, router.Ourself.Peer.NickName, ipRange.Range(), quorum) allocator.SetInterfaces(router.NewGossip("IPallocation", allocator)) allocator.Start() return allocator, defaultSubnet }
func createAllocator(router *mesh.Router, ipRangeStr string, defaultSubnetStr string, quorum uint, isKnownPeer func(mesh.PeerName) bool) (*ipam.Allocator, address.CIDR) { ipRange := parseAndCheckCIDR(ipRangeStr) defaultSubnet := ipRange if defaultSubnetStr != "" { defaultSubnet = parseAndCheckCIDR(defaultSubnetStr) if !ipRange.Range().Overlaps(defaultSubnet.Range()) { Log.Fatalf("IP address allocation default subnet %s does not overlap with allocation range %s", defaultSubnet, ipRange) } } allocator := ipam.NewAllocator(router.Ourself.Peer.Name, router.Ourself.Peer.UID, router.Ourself.Peer.NickName, ipRange.Range(), quorum, isKnownPeer) allocator.SetInterfaces(router.NewGossip("IPallocation", allocator)) allocator.Start() return allocator, defaultSubnet }