Documentation
¶
Index ¶
- Constants
- Variables
- func AddrFromSlice(b []byte) (netip.Addr, bool)
- func IsPublic(addr netip.Addr) bool
- func Lookup(hostname string) (netip.Addr, error)
- func ParseAddr(s string) (netip.Addr, error)
- func ParseAddrPort(s string) (netip.AddrPort, error)
- type ClaimedEndpoint
- type ClaimedIPPort
- type DynamicIPPort
- type Endpoint
- func NewHostnameEndpoint(hostname string, port uint16) (Endpoint, error)
- func NewIPEndpoint(addr netip.AddrPort) Endpoint
- func NewRNSEndpoint(destination [RNSDestinationLen]byte) Endpoint
- func NewRNSEndpointFromBytes(dest []byte) (Endpoint, error)
- func NewRNSEndpointFromHex(hexStr string) (Endpoint, error)
- func ParseEndpoint(s string) (Endpoint, error)
- type EndpointType
- type IPDesc
- type IPPort
Constants ¶
const ( ByteLen = 1 ShortLen = 2 IntLen = 4 LongLen = 8 )
Byte/word lengths for the wire formats this package emits.
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 ¶
var ( ErrInvalidEndpoint = errors.New("invalid endpoint") ErrEmptyHostname = errors.New("empty hostname") ErrInvalidPort = errors.New("invalid port") ErrInvalidDestination = errors.New("invalid RNS destination") )
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 ¶
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 Lookup ¶
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.
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 ¶
NewHostnameEndpoint creates an endpoint from a hostname and port.
func NewIPEndpoint ¶
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 ¶
NewRNSEndpointFromBytes creates an RNS endpoint from a byte slice.
func NewRNSEndpointFromHex ¶
NewRNSEndpointFromHex creates an RNS endpoint from a hex string.
func ParseEndpoint ¶
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 ¶
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 ¶
DestinationHex returns the RNS destination as a lowercase hex string.
func (Endpoint) IsHostname ¶
IsHostname returns true if this is a hostname-based endpoint.
type EndpointType ¶
type EndpointType uint8
EndpointType indicates whether an endpoint is IP-based or hostname-based.