use Space.NumFreeAddresses for calculating transferred ip count
...rather than Space.NumFreeAddressesInRange; we don't care about the universe. Alternatively we could make Space.AddRanges return the count. But AddRanges doesn't know whether the ranges overlap with existing free space - that is only guaranteed by the context - so would have to do much the same before/after calculation. Another alternative would be to add the range sizes in AdminTakeoverRanges. But that is more code and less clear.
This commit is contained in:
1 parent
62d823850c
commit
9f10b21c9c
3 files changed
+10
-12
No files matched your search
+2
-2
@@ -403,9 +403,9 @@ func (alloc *Allocator) AdminTakeoverRanges(peerNameOrNickname string) address.C
|
||||
return
|
||||
}
|
||||
|
||||
before := alloc.space.NumFreeAddressesInRange(alloc.universe)
|
||||
before := alloc.space.NumFreeAddresses()
|
||||
alloc.space.AddRanges(newRanges)
|
||||
after := alloc.space.NumFreeAddressesInRange(alloc.universe)
|
||||
after := alloc.space.NumFreeAddresses()
|
||||
|
||||
alloc.gossip.GossipBroadcast(alloc.Gossip())
|
||||
|
||||
|
||||
@@ -88,6 +88,14 @@ func (s *Space) Claim(addr address.Address) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Space) NumFreeAddresses() address.Count {
|
||||
res := address.Count(0)
|
||||
for i := 0; i < len(s.free); i += 2 {
|
||||
res += address.Length(s.free[i+1], s.free[i])
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (s *Space) NumFreeAddressesInRange(r address.Range) address.Count {
|
||||
res := address.Count(0)
|
||||
s.walkFree(r, func(chunk address.Range) bool {
|
||||
|
||||
@@ -19,16 +19,6 @@ func ip(s string) address.Address {
|
||||
return addr
|
||||
}
|
||||
|
||||
// Helper function to avoid 'NumFreeAddressesInRange(start, end)'
|
||||
// dozens of times in tests
|
||||
func (s *Space) NumFreeAddresses() address.Count {
|
||||
res := address.Count(0)
|
||||
for i := 0; i < len(s.free); i += 2 {
|
||||
res += address.Length(s.free[i+1], s.free[i])
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func TestLowlevel(t *testing.T) {
|
||||
a := []address.Address{}
|
||||
a = add(a, 100, 200)
|
||||
|
||||
Reference in new issue
Block a user