refactor: Introduce IPAM config object
This commit is contained in:
1 parent
2a10182cf6
commit
2eeb754454
3 files changed
+31
-11
No files matched your search
+18
-8
@@ -66,17 +66,27 @@ type Allocator struct {
|
||||
now func() time.Time
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
OurName mesh.PeerName
|
||||
OurUID mesh.PeerUID
|
||||
OurNickname string
|
||||
Universe address.Range
|
||||
Quorum uint
|
||||
Db db.DB
|
||||
IsKnownPeer func(name mesh.PeerName) bool
|
||||
}
|
||||
|
||||
// NewAllocator creates and initialises a new Allocator
|
||||
func NewAllocator(ourName mesh.PeerName, ourUID mesh.PeerUID, ourNickname string, universe address.Range, quorum uint, db db.DB, isKnownPeer func(name mesh.PeerName) bool) *Allocator {
|
||||
func NewAllocator(config Config) *Allocator {
|
||||
return &Allocator{
|
||||
ourName: ourName,
|
||||
universe: universe,
|
||||
ring: ring.New(universe.Start, universe.End, ourName),
|
||||
ourName: config.OurName,
|
||||
universe: config.Universe,
|
||||
ring: ring.New(config.Universe.Start, config.Universe.End, config.OurName),
|
||||
owned: make(map[string][]address.CIDR),
|
||||
db: db,
|
||||
paxos: paxos.NewParticipant(ourName, ourUID, quorum),
|
||||
nicknames: map[mesh.PeerName]string{ourName: ourNickname},
|
||||
isKnownPeer: isKnownPeer,
|
||||
db: config.Db,
|
||||
paxos: paxos.NewParticipant(config.OurName, config.OurUID, config.Quorum),
|
||||
nicknames: map[mesh.PeerName]string{config.OurName: config.OurNickname},
|
||||
isKnownPeer: config.IsKnownPeer,
|
||||
dead: make(map[string]time.Time),
|
||||
now: time.Now,
|
||||
}
|
||||
|
||||
@@ -139,8 +139,10 @@ func makeAllocator(name string, cidrStr string, quorum uint) (*Allocator, addres
|
||||
panic(err)
|
||||
}
|
||||
|
||||
alloc := NewAllocator(peername, mesh.PeerUID(rand.Int63()),
|
||||
"nick-"+name, cidr.Range(), quorum, new(mockDB), func(mesh.PeerName) bool { return true })
|
||||
config := Config{peername, mesh.PeerUID(rand.Int63()),
|
||||
"nick-" + name, cidr.Range(), quorum, new(mockDB), func(mesh.PeerName) bool { return true }}
|
||||
|
||||
alloc := NewAllocator(config)
|
||||
|
||||
return alloc, cidr
|
||||
}
|
||||
|
||||
+9
-1
@@ -366,7 +366,15 @@ func createAllocator(router *mesh.Router, ipRangeStr string, defaultSubnetStr st
|
||||
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, db, isKnownPeer)
|
||||
|
||||
config := ipam.Config{
|
||||
router.Ourself.Peer.Name,
|
||||
router.Ourself.Peer.UID,
|
||||
router.Ourself.Peer.NickName,
|
||||
ipRange.Range(),
|
||||
quorum, db, isKnownPeer}
|
||||
|
||||
allocator := ipam.NewAllocator(config)
|
||||
|
||||
allocator.SetInterfaces(router.NewGossip("IPallocation", allocator))
|
||||
allocator.Start()
|
||||
|
||||
Reference in new issue
Block a user