diff --git a/pkg/zones/rings.go b/pkg/zones/rings.go index dd65028..1eb36e8 100644 --- a/pkg/zones/rings.go +++ b/pkg/zones/rings.go @@ -7,6 +7,36 @@ const ( MaxZoneID = 0xf // MaxNodeID indicates the highest Machine ID allowed within a Zone MaxNodeID = 0xff - 1 + // RingsCount indicates how many wireguard rings we have + RingsCount = 2 +) + +// RingAddressEncoder provides encoder/decoder access for a particular +// Wireguard ring +type RingAddressEncoder struct { + ID int + Encode func(zoneID, nodeID int) (netip.Addr, bool) + Decode func(addr netip.Addr) (zoneID, nodeID int, ok bool) +} + +var ( + // RingZero is a wg0 address encoder/decoder + RingZero = RingAddressEncoder{ + ID: 0, + Decode: ParseRingZeroAddress, + Encode: RingZeroAddress, + } + // RingOne is a wg1 address encoder/decoder + RingOne = RingAddressEncoder{ + ID: 1, + Decode: ParseRingOneAddress, + Encode: RingOneAddress, + } + // Rings provides indexed access to the ring address encoders + Rings = [RingsCount]RingAddressEncoder{ + RingZero, + RingOne, + } ) // ValidZoneID checks if the given zoneID is a valid 4 bit zone number.