Deal in subnets, not ranges, when requesting address allocation

This commit is contained in:
Bryan Boreham committed 2016-03-02 17:21:51 -08:00
1 parent b76e2a87cf
commit 73f1a04d5f
4 files changed
+16 -16

No files matched your search

+6 -6
View File
@@ -14,7 +14,7 @@ type allocateResult struct {
type allocate struct {
resultChan chan<- allocateResult
ident string
r address.Range // Range we are trying to allocate within
r address.CIDR // Subnet we are trying to allocate within
hasBeenCancelled func() bool
}
@@ -25,21 +25,21 @@ func (g *allocate) Try(alloc *Allocator) bool {
return true
}
if addrs := alloc.ownedInRange(g.ident, g.r); len(addrs) > 0 {
if addrs := alloc.ownedInRange(g.ident, g.r.Range()); len(addrs) > 0 {
// If we had heard that this container died, resurrect it
delete(alloc.dead, g.ident) // delete is no-op if key not in map
g.resultChan <- allocateResult{addrs[0].Addr, nil}
return true
}
if !alloc.universe.Overlaps(g.r) {
if !alloc.universe.Overlaps(g.r.Range()) {
g.resultChan <- allocateResult{err: fmt.Errorf("range %s out of bounds: %s", g.r, alloc.universe)}
return true
}
alloc.establishRing()
if ok, addr := alloc.space.Allocate(g.r); ok {
if ok, addr := alloc.space.Allocate(g.r.HostRange()); ok {
// If caller hasn't supplied a unique ID, file it under the IP address
// which lets the caller then release the address using DELETE /ip/address
if g.ident == "_" {
@@ -52,9 +52,9 @@ func (g *allocate) Try(alloc *Allocator) bool {
}
// out of space
donors := alloc.ring.ChoosePeersToAskForSpace(g.r.Start, g.r.End)
donors := alloc.ring.ChoosePeersToAskForSpace(g.r.Addr, g.r.Range().End)
for _, donor := range donors {
if err := alloc.sendSpaceRequest(donor, g.r); err != nil {
if err := alloc.sendSpaceRequest(donor, g.r.Range()); err != nil {
alloc.debugln("Problem asking peer", donor, "for space:", err)
} else {
alloc.debugln("Decided to ask peer", donor, "for space in range", g.r)