Search documentation of macula

# macula_relay_discovery (macula v4.4.9)

View Source

Relay Discovery — geographic-aware relay selection.

Maintains a ranked list of relay identities sorted by distance from the node's own location. Updated via three mechanisms:

1. Bootstrap: HTTP GET /topology from seed relays on startup 2. Real-time: _mesh.relay.up/down events via pubsub subscription 3. Periodic: Reconciliation poll every 5 minutes

Nodes connect to the nearest available relay. On failover, the next nearest is selected instantly from the cached ranked list.

Usage: {ok, Pid} = macula_relay_discovery:start_link(Opts). {ok, Url} = macula_relay_discovery:nearest(). {ok, Url} = macula_relay_discovery:nearest_except(FailedHostname). Relays = macula_relay_discovery:ranked_relays().

# Summary

## Functions

build_topology_url(Seed)
extract_hostname(Url)
handle_call(_, From, State)
handle_cast(_, State)
handle_info(_, State)
haversine_km(Lat1, Lng1, Lat2, Lng2)
init(Opts)
lookup(Hostname)
mark_offline(Hostname)
nearest()
nearest_except(FailedHostname)
ranked_relays()
relay_count()
relay_status(_)
start_link(Opts)
terminate(_, State)
to_float(V)
update_rtt(Hostname, RttMs)

# Functions

# build_topology_url(Seed)

# extract_hostname(Url)

# handle_call(_, From, State)

# handle_cast(_, State)

# handle_info(_, State)

# haversine_km(Lat1, Lng1, Lat2, Lng2)

# init(Opts)

# lookup(Hostname)

    -spec lookup(binary()) -> {ok, map()} | {error, not_found}.

# mark_offline(Hostname)

# nearest()

    -spec nearest() -> {ok, binary()} | {error, no_relays}.

# nearest_except(FailedHostname)

    -spec nearest_except(binary()) -> {ok, binary()} | {error, no_relays}.

# ranked_relays()

    -spec ranked_relays() ->
                           [#{hostname := binary(),
                              url := binary(),
                              distance_km := float(),
                              status := atom(),
                              lat := float(),
                              lng := float(),
                              rtt_ms := non_neg_integer() | undefined}].

# relay_count()

# relay_status(_)

# start_link(Opts)

# terminate(_, State)

# to_float(V)

# update_rtt(Hostname, RttMs)