gossip

package
v1.0.227 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EndpointMappingV   uint8
	EndpointTombstoneV uint8
	NATEntryV          uint8
	VIPHeartbeatV      uint8
	SubnetRouteV       uint8
)

Schema hashes — computed at init() from each struct's field names + types. When a field is added, removed, or changes type, the hash changes automatically. Receivers compare hashes to detect version mismatches and apply defensive merge logic during rolling upgrades.

Old peers that predate this field will produce V=0 (the JSON field is omitted and Go defaults the uint8 to zero on unmarshal).

Functions

func Encode

func Encode(msg any) ([]byte, error)

Encode serialises msg into a JSON-encoded Envelope ready for the wire. V is auto-stamped on the payload struct before marshaling. Returns an error if the type is not handled by stampVersion, preventing new gossip structs from silently sending unversioned messages.

Types

type EndpointMapping

type EndpointMapping struct {
	V           uint8    `json:"v,omitempty"` // auto-computed structural hash; 0 = pre-versioning legacy
	GravityVIP  string   `json:"gravity_vip"`
	HadronVIP   string   `json:"hadron_vip"`
	ContainerID string   `json:"container_id"`
	MachineID   string   `json:"machine_id"`
	ProjectID   string   `json:"project_id"`
	DNSNames    []string `json:"dns_names"`
	Timestamp   int64    `json:"timestamp"`
	SNIHostname string   `json:"sni_hostname,omitempty"` // d-hash for deployments, sandbox hostname for sandboxes
}

EndpointMapping describes the mapping between a container and its network endpoints within the Gravity mesh.

VERSIONING: The V field is a structural hash computed at init() from the field names and types of this struct. Any change to the struct layout (adding, removing, or retyping a field) automatically changes V. Receivers use V to detect schema mismatches during rolling upgrades and apply defensive merge logic to avoid silent data loss. Old peers that predate versioning will send V=0.

type EndpointTombstone

type EndpointTombstone struct {
	V           uint8  `json:"v,omitempty"` // auto-computed structural hash; 0 = pre-versioning legacy
	ContainerID string `json:"container_id"`
	MachineID   string `json:"machine_id"`
	Timestamp   int64  `json:"timestamp"`
}

EndpointTombstone marks an endpoint as removed so peers can clean up stale mappings.

VERSIONING: V is auto-computed. See EndpointMapping for details.

type Envelope

type Envelope struct {
	Type    MessageType     `json:"type"`
	Payload json.RawMessage `json:"payload"`
}

Envelope is the wire format for gossip messages. It wraps a MessageType together with a JSON-encoded payload so receivers can demux without knowing the concrete type up front. Schema versioning is per-struct (each payload carries its own V field), not per-envelope.

type MessageType

type MessageType uint8

MessageType identifies the kind of gossip message on the wire.

const (
	// MsgEndpointMapping carries a new or updated endpoint mapping.
	MsgEndpointMapping MessageType = iota + 1
	// MsgEndpointTombstone signals removal of an endpoint.
	MsgEndpointTombstone
	// MsgNATEntry carries a NAT translation entry.
	MsgNATEntry
	// MsgVIPHeartbeat carries a VIP ownership heartbeat.
	MsgVIPHeartbeat
	// MsgSubnetRoute carries a subnet ownership announcement.
	MsgSubnetRoute
)

func Decode

func Decode(data []byte) (MessageType, any, error)

Decode deserialises a JSON-encoded Envelope and returns the MessageType together with the concrete Go value. The returned value is a pointer to the decoded struct (e.g. *EndpointMapping).

func (MessageType) String

func (m MessageType) String() string

String returns a human-readable name for the message type.

type NATEntry

type NATEntry struct {
	V           uint8  `json:"v,omitempty"` // auto-computed structural hash; 0 = pre-versioning legacy
	Key         string `json:"key"`
	OriginalDst string `json:"original_dst"`
	OriginalSrc string `json:"original_src"`
	SrcPort     uint16 `json:"src_port"`
	DstPort     uint16 `json:"dst_port"`
	Timestamp   int64  `json:"timestamp"`
}

NATEntry represents a single NAT translation entry used to route packets between Gravity instances.

VERSIONING: V is auto-computed. See EndpointMapping for details.

type SubnetRoute added in v1.0.210

type SubnetRoute struct {
	V         uint8  `json:"v,omitempty"` // auto-computed structural hash; 0 = pre-versioning legacy
	Subnet    string `json:"subnet"`      // /64 prefix, e.g. "fd15:d710:02:05:a1b2::/64"
	MachineID string `json:"machine_id"`  // Machine that owns this subnet
	IonID     string `json:"ion_id"`      // Memberlist address of the ion that owns this subnet
	Timestamp int64  `json:"timestamp"`   // Unix timestamp
	Action    string `json:"action"`      // "add" or "remove"
}

SubnetRoute advertises ownership of a /64 subnet by a machine connected to this ion instance. Used to build cross-ion forwarding tables.

VERSIONING: V is auto-computed. See EndpointMapping for details.

type VIPHeartbeat

type VIPHeartbeat struct {
	V            uint8             `json:"v,omitempty"` // auto-computed structural hash; 0 = pre-versioning legacy
	VIP          string            `json:"vip"`
	Owners       map[string]int64  `json:"owners"`
	Timestamp    int64             `json:"timestamp"`
	NewNATs      []NATEntry        `json:"new_nats,omitempty"`
	NewEndpoints []EndpointMapping `json:"new_endpoints,omitempty"`
}

VIPHeartbeat advertises ownership and recent changes for a VIP.

VERSIONING: V is auto-computed. See EndpointMapping for details.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL