rings: DecodeRingZeroAddress() and DecodeRingOneAddress()
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -111,6 +111,20 @@ func RingZeroAddress(region RegionID, zone ZoneID, node NodeID) (addr netip.Addr
|
||||
return addr, err
|
||||
}
|
||||
|
||||
// DecodeRingZeroAddress attempts to extract region, zone and node identifiers
|
||||
// from a given ring 0 address.
|
||||
//
|
||||
// revive:disable:function-result-limit
|
||||
func DecodeRingZeroAddress(addr netip.Addr) (RegionID, ZoneID, NodeID, bool) {
|
||||
// revive:enable:function-result-limit
|
||||
k, r, z, n := DecodeAddress(addr)
|
||||
if k == RingZero {
|
||||
return r, z, NodeID(n), true
|
||||
}
|
||||
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
|
||||
// RingOnePrefix represents a (virtual) local network of a zone.
|
||||
//
|
||||
// Ring 1 is `10.(region_id).(zone_id << 4).(node_id)/20` network
|
||||
@@ -148,6 +162,20 @@ func RingOneAddress(region RegionID, zone ZoneID, node NodeID) (addr netip.Addr,
|
||||
return addr, err
|
||||
}
|
||||
|
||||
// DecodeRingOneAddress attempts to extract region, zone and node identifiers
|
||||
// from a given ring 1 address.
|
||||
//
|
||||
// revive:disable:function-result-limit
|
||||
func DecodeRingOneAddress(addr netip.Addr) (RegionID, ZoneID, NodeID, bool) {
|
||||
// revive:enable:function-result-limit
|
||||
k, r, z, n := DecodeAddress(addr)
|
||||
if k == RingOne {
|
||||
return r, z, NodeID(n), r != 0 && z != 0
|
||||
}
|
||||
|
||||
return 0, 0, 0, false
|
||||
}
|
||||
|
||||
// RingTwoPrefix represents the services of a cluster
|
||||
//
|
||||
// Ring 2 subnets are of the form `10.(region_id).0.0/20`,
|
||||
|
||||
Reference in New Issue
Block a user