More helpful error message when --ip-alloc-range mismatched
This commit is contained in:
1 parent
f4d6e028d4
commit
1f4b943454
3 files changed
+19
No files matched your search
@@ -613,6 +613,10 @@ func (alloc *Allocator) update(sender router.PeerName, msg []byte) error {
|
|||||||
// shouldn't get updates for a empty Ring. But tolerate
|
// shouldn't get updates for a empty Ring. But tolerate
|
||||||
// them just in case.
|
// them just in case.
|
||||||
if data.Ring != nil {
|
if data.Ring != nil {
|
||||||
|
if data.Ring.Range() != alloc.universe {
|
||||||
|
return fmt.Errorf("Incompatible IP allocation range %s; ours is %s",
|
||||||
|
data.Ring.Range().AsCIDRString(), alloc.universe.AsCIDRString())
|
||||||
|
}
|
||||||
err = alloc.ring.Merge(*data.Ring)
|
err = alloc.ring.Merge(*data.Ring)
|
||||||
if !alloc.ring.Empty() {
|
if !alloc.ring.Empty() {
|
||||||
alloc.pruneNicknames()
|
alloc.pruneNicknames()
|
||||||
|
|||||||
@@ -92,6 +92,10 @@ func New(start, end address.Address, peer router.PeerName) *Ring {
|
|||||||
return ring
|
return ring
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Ring) Range() address.Range {
|
||||||
|
return address.Range{Start: r.Start, End: r.End}
|
||||||
|
}
|
||||||
|
|
||||||
// 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.Offset {
|
||||||
|
|||||||
@@ -23,6 +23,17 @@ func (r Range) String() string { return fmt.Sprintf("[%s-%s)", r.Sta
|
|||||||
func (r Range) Overlaps(or Range) bool { return !(r.Start >= or.End || r.End <= or.Start) }
|
func (r Range) Overlaps(or Range) bool { return !(r.Start >= or.End || r.End <= or.Start) }
|
||||||
func (r Range) Contains(addr Address) bool { return addr >= r.Start && addr < r.End }
|
func (r Range) Contains(addr Address) bool { return addr >= r.Start && addr < r.End }
|
||||||
|
|
||||||
|
func (r Range) AsCIDRString() string {
|
||||||
|
prefixLen := 32
|
||||||
|
for size := r.Size(); size > 1; size = size / 2 {
|
||||||
|
if size%2 != 0 { // Size not a power of two; cannot be expressed as a CIDR.
|
||||||
|
return r.String()
|
||||||
|
}
|
||||||
|
prefixLen--
|
||||||
|
}
|
||||||
|
return CIDR{Start: r.Start, PrefixLen: prefixLen}.String()
|
||||||
|
}
|
||||||
|
|
||||||
type CIDR struct {
|
type CIDR struct {
|
||||||
Start Address
|
Start Address
|
||||||
PrefixLen int
|
PrefixLen int
|
||||||
|
|||||||
Reference in new issue
Block a user