zones: introduce RingAddressEncoder and RingZero/RingOne implementations
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -7,6 +7,36 @@ const (
|
|||||||
MaxZoneID = 0xf
|
MaxZoneID = 0xf
|
||||||
// MaxNodeID indicates the highest Machine ID allowed within a Zone
|
// MaxNodeID indicates the highest Machine ID allowed within a Zone
|
||||||
MaxNodeID = 0xff - 1
|
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.
|
// ValidZoneID checks if the given zoneID is a valid 4 bit zone number.
|
||||||
|
|||||||
Reference in New Issue
Block a user