Merge pull request #2299 from weaveworks/issues/fix-offset-abuse
Change the type of entry.Free to address.Count
This commit is contained in:
commit
b16de0c71e
3 files changed
+12
-13
No files matched your search
+2
-3
@@ -14,8 +14,7 @@ type entry struct {
|
|||||||
Token address.Address // The start of this range
|
Token address.Address // The start of this range
|
||||||
Peer mesh.PeerName // Who owns this range
|
Peer mesh.PeerName // Who owns this range
|
||||||
Version uint32 // Version of this range
|
Version uint32 // Version of this range
|
||||||
Free address.Offset // Number of free IPs in this range
|
Free address.Count // Number of free IPs in this range
|
||||||
// Note: Free should perhaps be an address.Count, but we can't change the wire protocol
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *entry) Equal(e2 *entry) bool {
|
func (e *entry) Equal(e2 *entry) bool {
|
||||||
@@ -23,7 +22,7 @@ func (e *entry) Equal(e2 *entry) bool {
|
|||||||
e.Version == e2.Version
|
e.Version == e2.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *entry) update(peername mesh.PeerName, free address.Offset) {
|
func (e *entry) update(peername mesh.PeerName, free address.Count) {
|
||||||
e.Peer = peername
|
e.Peer = peername
|
||||||
e.Version++
|
e.Version++
|
||||||
e.Free = free
|
e.Free = free
|
||||||
|
|||||||
+9
-9
@@ -109,12 +109,12 @@ func (r *Ring) Range() address.Range {
|
|||||||
|
|
||||||
// Returns the distance between two tokens on this ring, dealing
|
// Returns the distance between two tokens on this ring, dealing
|
||||||
// with ranges which cross the origin
|
// with ranges which cross the origin
|
||||||
func (r *Ring) distance(start, end address.Address) address.Offset {
|
func (r *Ring) distance(start, end address.Address) address.Count {
|
||||||
if end > start {
|
if end > start {
|
||||||
return address.Offset(end - start)
|
return address.Count(end - start)
|
||||||
}
|
}
|
||||||
|
|
||||||
return address.Offset((r.End - start) + (end - r.Start))
|
return address.Count((r.End - start) + (end - r.Start))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GrantRangeToHost modifies the ring such that range [start, end)
|
// GrantRangeToHost modifies the ring such that range [start, end)
|
||||||
@@ -375,12 +375,12 @@ func (r *Ring) ClaimForPeers(peers []mesh.PeerName) {
|
|||||||
defer r.updateExportedVariables()
|
defer r.updateExportedVariables()
|
||||||
|
|
||||||
totalSize := r.distance(r.Start, r.End)
|
totalSize := r.distance(r.Start, r.End)
|
||||||
share := totalSize/address.Offset(len(peers)) + 1
|
share := totalSize/address.Count(len(peers)) + 1
|
||||||
remainder := totalSize % address.Offset(len(peers))
|
remainder := totalSize % address.Count(len(peers))
|
||||||
pos := r.Start
|
pos := r.Start
|
||||||
|
|
||||||
for i, peer := range peers {
|
for i, peer := range peers {
|
||||||
if address.Offset(i) == remainder {
|
if address.Count(i) == remainder {
|
||||||
share--
|
share--
|
||||||
if share == 0 {
|
if share == 0 {
|
||||||
break
|
break
|
||||||
@@ -450,11 +450,11 @@ func (r *Ring) ReportFree(freespace map[address.Address]address.Count) {
|
|||||||
maxSize := r.distance(entry.Token, next.Token)
|
maxSize := r.distance(entry.Token, next.Token)
|
||||||
common.Assert(free <= address.Count(maxSize))
|
common.Assert(free <= address.Count(maxSize))
|
||||||
|
|
||||||
if address.Count(entries[i].Free) == free {
|
if entries[i].Free == free {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
entries[i].Free = address.Offset(free)
|
entries[i].Free = free
|
||||||
entries[i].Version++
|
entries[i].Version++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -473,7 +473,7 @@ func (ws weightedPeers) Swap(i, j int) { ws[i], ws[j] = ws[j], ws[i] }
|
|||||||
// ChoosePeersToAskForSpace returns all peers we can ask for space in
|
// ChoosePeersToAskForSpace returns all peers we can ask for space in
|
||||||
// the range [start, end), in weighted-random order. Assumes start<end.
|
// the range [start, end), in weighted-random order. Assumes start<end.
|
||||||
func (r *Ring) ChoosePeersToAskForSpace(start, end address.Address) []mesh.PeerName {
|
func (r *Ring) ChoosePeersToAskForSpace(start, end address.Address) []mesh.PeerName {
|
||||||
totalSpacePerPeer := make(map[mesh.PeerName]address.Offset)
|
totalSpacePerPeer := make(map[mesh.PeerName]address.Count)
|
||||||
|
|
||||||
// iterate through tokens
|
// iterate through tokens
|
||||||
for i, entry := range r.Entries {
|
for i, entry := range r.Entries {
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ func Length(a, b Address) Count {
|
|||||||
return Count(a - b)
|
return Count(a - b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Min(a, b Offset) Offset {
|
func Min(a, b Count) Count {
|
||||||
if a > b {
|
if a > b {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user