|
|
|
@ -97,6 +97,25 @@ 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
|
|
|
|
|
if addr.IsValid() { |
|
|
|
|
if addr.Is4In6() { |
|
|
|
|
addr = addr.Unmap() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if addr.Is4() { |
|
|
|
|
return unsafeDecodeRingZeroAddress(addr.As4()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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
|
|
|
|
@ -134,6 +153,25 @@ 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
|
|
|
|
|
if addr.IsValid() { |
|
|
|
|
if addr.Is4In6() { |
|
|
|
|
addr = addr.Unmap() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if addr.Is4() { |
|
|
|
|
return unsafeDecodeRingOneAddress(addr.As4()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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`,
|
|
|
|
@ -173,6 +211,20 @@ func unsafeRingZeroAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr
|
|
|
|
|
return AddrFrom4(10, 0, r<<4+z, n) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// revive:disable:function-result-limit
|
|
|
|
|
func unsafeDecodeRingZeroAddress(a4 [4]byte) (RegionID, ZoneID, NodeID, bool) { |
|
|
|
|
// revive:enable:function-result-limit
|
|
|
|
|
if a4[0] == 10 && a4[1] == 0 { |
|
|
|
|
r := a4[2] >> 4 |
|
|
|
|
z := a4[2] & 0x0f |
|
|
|
|
n := a4[3] |
|
|
|
|
|
|
|
|
|
return RegionID(r), ZoneID(z), NodeID(n), true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0, 0, 0, false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func unsafeRingOneAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr { |
|
|
|
|
r := uint(region) |
|
|
|
|
z := uint(zone) |
|
|
|
@ -184,6 +236,23 @@ func unsafeRingOneAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr
|
|
|
|
|
return AddrFrom4(10, r, z<<4+n1, n0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// revive:disable:function-result-limit
|
|
|
|
|
func unsafeDecodeRingOneAddress(a4 [4]byte) (RegionID, ZoneID, NodeID, bool) { |
|
|
|
|
// revive:enable:function-result-limit
|
|
|
|
|
if a4[0] == 10 && (a4[1]>>4) == 0 { |
|
|
|
|
n1 := uint(a4[2] & 0x0f) |
|
|
|
|
n0 := uint(a4[3]) |
|
|
|
|
|
|
|
|
|
r := a4[1] |
|
|
|
|
z := a4[2] >> 4 |
|
|
|
|
n := n1<<8 + n0 |
|
|
|
|
|
|
|
|
|
return RegionID(r), ZoneID(z), NodeID(n), true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 0, 0, 0, false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func unsafeRingTwoAddress(region RegionID, n uint) netip.Addr { |
|
|
|
|
r := uint(region) |
|
|
|
|
|
|
|
|
|