Documentation
¶
Overview ¶
Package vip provides deterministic virtual IP generation for Gravity.
Instead of using a per-machine atomic counter (which requires coordination), this package hashes a connection's 5-tuple plus container ID to produce a deterministic IPv6 address within a /96 subnet. Any Gravity instance given the same inputs will compute the same VIP, enabling zero-coordination failover.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateDeterministicIPV6 ¶
func GenerateDeterministicIPV6(machineID string, srcIP net.IP, srcPort uint16, dstIP net.IP, dstPort uint16, subnet net.IPNet) (net.IP, error)
GenerateDeterministicIPV6 produces a deterministic IPv6 address within the given /96 subnet by hashing the provided connection parameters.
The function hashes machineID, srcIP, srcPort, dstIP, and dstPort using SHA-256, extracts a 32-bit host identifier from the hash, and embeds it into the last 32 bits of the subnet address.
Parameters:
- machineID: unique identifier for the Hadron machine (NOT the container/deployment ID). Using the machine ID ensures that the same deployment scaled across multiple Hadrons produces different unique IPs for the same flow, preventing NAT collisions.
- srcIP: source IP address of the connection
- srcPort: source port of the connection
- dstIP: destination IP address of the connection
- dstPort: destination port of the connection
- subnet: a /96 IPv6 subnet to place the address in
Returns the generated IPv6 address, or an error if the subnet is not /96.
func GenerateDeterministicIPV6WithCollisionCheck ¶ added in v1.0.190
func GenerateDeterministicIPV6WithCollisionCheck( machineID string, srcIP net.IP, srcPort uint16, dstIP net.IP, dstPort uint16, subnet net.IPNet, isCollision func(ip net.IP) bool, ) (net.IP, error)
GenerateDeterministicIPV6WithCollisionCheck generates a unique IP and verifies it doesn't collide with an existing allocation via the isCollision callback. isCollision receives each candidate IP and should return true if that IP is already in use by a different flow. On collision the function rehashes with an incrementing salt, up to 8 attempts, before returning an error.
Types ¶
This section is empty.