endpoints

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: BSD-3-Clause Imports: 13 Imported by: 8

Documentation

Index

Constants

View Source
const (
	ByteLen  = 1
	ShortLen = 2
	IntLen   = 4
	LongLen  = 8
)

Byte/word lengths for the wire formats this package emits.

View Source
const (
	EndpointTypeIP       EndpointType = 0
	EndpointTypeHostname EndpointType = 1
	EndpointTypeRNS      EndpointType = 2 // Reticulum Network Stack destination

	// Maximum hostname length per RFC 1035
	MaxHostnameLen = 253

	// RNS destination is a 128-bit truncated hash
	RNSDestinationLen = 16

	// RNS destination string prefix for parsing
	RNSPrefix = "rns://"
)

Variables

View Source
var (
	ErrInvalidEndpoint    = errors.New("invalid endpoint")
	ErrEmptyHostname      = errors.New("empty hostname")
	ErrInvalidPort        = errors.New("invalid port")
	ErrInvalidDestination = errors.New("invalid RNS destination")
)
View Source
var ErrInsufficientLength = errors.New("packer: insufficient length")

ErrInsufficientLength is returned by packer methods when the underlying byte slice can't satisfy the requested read/write.

Functions

func AddrFromSlice

func AddrFromSlice(b []byte) (netip.Addr, bool)

AddrFromSlice returns the IP address from the provided byte slice. If the byte slice represents an IPv4 address in an IPv6 address, the IPv4 address is returned.

func IsPublic

func IsPublic(addr netip.Addr) bool

IsPublic returns true if the provided address is considered to be a public IP.

func Lookup

func Lookup(hostname string) (netip.Addr, error)

Lookup attempts to resolve a hostname to a single IP. If multiple IPs are found, then lookup will attempt to return an IPv4 address, otherwise it will pick any of the IPs.

Note: IPv4 is preferred because `net.Listen` prefers IPv4.

func ParseAddr

func ParseAddr(s string) (netip.Addr, error)

ParseAddr returns the IP address from the provided string. If the string represents an IPv4 address in an IPv6 address, the IPv4 address is returned.

func ParseAddrPort

func ParseAddrPort(s string) (netip.AddrPort, error)

ParseAddrPort returns the IP:port address from the provided string. If the string represents an IPv4 address in an IPv6 address, the IPv4 address is returned.

Types

type ClaimedEndpoint

type ClaimedEndpoint struct {
	// The peer's certificate.
	Cert *staking.Certificate
	// The claimed endpoint (IP or hostname).
	Endpoint Endpoint
	// The time the peer claimed to own this endpoint.
	Timestamp uint64
	// [Cert]'s signature over the endpoint and timestamp.
	Signature []byte
	// NodeID derived from the peer certificate.
	NodeID ids.NodeID
	// GossipID derived from the nodeID and timestamp.
	GossipID ids.ID

	// Legacy: For backward compatibility, if this is an IP endpoint,
	// we also store it in the legacy format.
	LegacyIP *ClaimedIPPort
}

ClaimedEndpoint is a self-contained proof that a peer is claiming ownership of an endpoint at a given time. Extends ClaimedIPPort to support hostnames.

func FromClaimedIPPort

func FromClaimedIPPort(ip *ClaimedIPPort) *ClaimedEndpoint

FromClaimedIPPort creates a ClaimedEndpoint from a legacy ClaimedIPPort.

func NewClaimedEndpoint

func NewClaimedEndpoint(
	cert *staking.Certificate,
	endpoint Endpoint,
	timestamp uint64,
	signature []byte,
) *ClaimedEndpoint

NewClaimedEndpoint creates a new claimed endpoint.

func (*ClaimedEndpoint) Size

func (ce *ClaimedEndpoint) Size() int

Size returns the approximate size of the binary representation.

func (*ClaimedEndpoint) ToClaimedIPPort

func (ce *ClaimedEndpoint) ToClaimedIPPort() *ClaimedIPPort

ToClaimedIPPort converts to legacy format if this is an IP endpoint. Returns nil if this is a hostname endpoint.

type ClaimedIPPort

type ClaimedIPPort struct {
	// The peer's certificate.
	Cert *luxtls.Certificate
	// The peer's claimed IP and port.
	AddrPort netip.AddrPort
	// The time the peer claimed to own this IP and port.
	Timestamp uint64
	// [Cert]'s signature over the IPPort and timestamp.
	// This is used in the networking library to ensure that this IPPort was
	// actually claimed by the peer in question, and not by a malicious peer
	// trying to get us to dial bogus IPPorts.
	Signature []byte
	// NodeID derived from the peer certificate.
	NodeID ids.NodeID
	// GossipID derived from the nodeID and timestamp.
	GossipID ids.ID
}

A self contained proof that a peer is claiming ownership of an IPPort at a given time.

func NewClaimedIPPort

func NewClaimedIPPort(
	cert *luxtls.Certificate,
	ipPort netip.AddrPort,
	timestamp uint64,
	signature []byte,
) *ClaimedIPPort

func (*ClaimedIPPort) Size

func (i *ClaimedIPPort) Size() int

Returns the approximate size of the binary representation of this ClaimedIPPort.

type DynamicIPPort

type DynamicIPPort interface {
	// Returns the IP + port pair.
	IPPort() IPPort
	// Changes the IP.
	SetIP(ip net.IP)
}

An IPPort that can change. Safe for use by multiple goroutines.

func NewDynamicIPPort

func NewDynamicIPPort(ip net.IP, port uint16) DynamicIPPort

type Endpoint

type Endpoint struct {
	// Type indicates whether this is an IP, hostname, or RNS endpoint
	Type EndpointType

	// AddrPort is set when Type == EndpointTypeIP
	AddrPort netip.AddrPort

	// Hostname is set when Type == EndpointTypeHostname
	Hostname string

	// Destination is set when Type == EndpointTypeRNS
	// This is a 128-bit truncated hash of the Reticulum identity
	Destination [RNSDestinationLen]byte

	// Port is set for IP and Hostname endpoints (0 for RNS)
	Port uint16
}

Endpoint represents a network endpoint that can be either: - An IP address and port (traditional, for datacenter validators) - A hostname and port (for nodes behind proxies/tunnels) - An RNS destination (Reticulum Network Stack, for mesh/LoRa/offline-first)

This supports the "laptop validator" use case where a node advertises a hostname (e.g., mynode.example.com:9651) instead of an IP, and the "mesh validator" use case where a node uses Reticulum's medium-agnostic addressing (e.g., rns://a5f72c...).

func NewHostnameEndpoint

func NewHostnameEndpoint(hostname string, port uint16) (Endpoint, error)

NewHostnameEndpoint creates an endpoint from a hostname and port.

func NewIPEndpoint

func NewIPEndpoint(addr netip.AddrPort) Endpoint

NewIPEndpoint creates an endpoint from an IP address and port.

func NewRNSEndpoint

func NewRNSEndpoint(destination [RNSDestinationLen]byte) Endpoint

NewRNSEndpoint creates an endpoint from a Reticulum destination hash. The destination is a 128-bit (16-byte) truncated hash of the RNS identity.

func NewRNSEndpointFromBytes

func NewRNSEndpointFromBytes(dest []byte) (Endpoint, error)

NewRNSEndpointFromBytes creates an RNS endpoint from a byte slice.

func NewRNSEndpointFromHex

func NewRNSEndpointFromHex(hexStr string) (Endpoint, error)

NewRNSEndpointFromHex creates an RNS endpoint from a hex string.

func ParseEndpoint

func ParseEndpoint(s string) (Endpoint, error)

ParseEndpoint parses a string like: - "1.2.3.4:9651" (IP endpoint) - "mynode.example.com:9651" (hostname endpoint) - "rns://a5f72c3d..." (RNS destination, 32 hex chars)

func (Endpoint) Bytes

func (e Endpoint) Bytes() []byte

Bytes returns the canonical byte representation for signing. Format:

  • Type (1 byte)
  • If IP: IPv6 addr (16 bytes) + port (2 bytes)
  • If Hostname: hostname length (2 bytes) + hostname + port (2 bytes)
  • If RNS: destination (16 bytes)

func (Endpoint) DestinationHex

func (e Endpoint) DestinationHex() string

DestinationHex returns the RNS destination as a lowercase hex string.

func (Endpoint) Equal

func (e Endpoint) Equal(other Endpoint) bool

Equal compares two endpoints.

func (Endpoint) Host

func (e Endpoint) Host() string

Host returns the host part (IP, hostname, or RNS destination).

func (Endpoint) IsHostname

func (e Endpoint) IsHostname() bool

IsHostname returns true if this is a hostname-based endpoint.

func (Endpoint) IsIP

func (e Endpoint) IsIP() bool

IsIP returns true if this is an IP-based endpoint.

func (Endpoint) IsRNS

func (e Endpoint) IsRNS() bool

IsRNS returns true if this is an RNS (Reticulum) endpoint.

func (Endpoint) String

func (e Endpoint) String() string

String returns the endpoint as a dial-able string.

type EndpointType

type EndpointType uint8

EndpointType indicates whether an endpoint is IP-based or hostname-based.

type IPDesc

type IPDesc IPPort

func (IPDesc) MarshalJSON

func (ipDesc IPDesc) MarshalJSON() ([]byte, error)

func (IPDesc) String

func (ipDesc IPDesc) String() string

func (*IPDesc) UnmarshalJSON

func (ipDesc *IPDesc) UnmarshalJSON(b []byte) error

type IPPort

type IPPort struct {
	IP   net.IP `json:"ip"`
	Port uint16 `json:"port"`
}

An IP and a port.

func ToIPPort

func ToIPPort(str string) (IPPort, error)

func (IPPort) Equal

func (ipPort IPPort) Equal(other IPPort) bool

func (IPPort) IsZero

func (ipPort IPPort) IsZero() bool

IsZero returns if the IP or port is zeroed out

func (IPPort) String

func (ipPort IPPort) String() string

Jump to

Keyboard shortcuts

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