Involved Source Filesnearest.go Package relay provides the public configuration types for iroh relay servers:
relay URLs grouped into a [Map], per-relay [Config], and the [Mode] selecting
which relays an endpoint uses.
It is the public surface of the Rust crate iroh-relay (the client connection
and wire protocol live in internal packages).
The Go API is not stable before v1 and may change in any v0 release.
Map is a set of relay servers keyed by URL.
The zero Map is empty and ready to use, but is not safe for concurrent
mutation; build it up before sharing. Clone returns a deep copy of the map. Configs returns the relay configs in URL-sorted order. Contains reports whether url is in the map. Get returns the config for url and whether it is present. Insert adds or replaces the config for its URL, returning the previous config
and whether one was present. IsEmpty reports whether the map has no relays. Len returns the number of relays. Nearest probes the relays in m and returns the URL of the lowest-latency
reachable relay. It returns [ErrNoRelays] if the map is empty or no relay
could be reached. If prober is nil, [HTTPConnectProber] is used.
Nearest is the seam a ticket minter (e.g. ccl's transfer layer) calls to pick
a home relay close to the local machine instead of an arbitrary one. PreferNearest returns a Map containing only the lowest-latency reachable relay
in m, using prober (or [HTTPConnectProber] if nil). It is a convenience for
wiring nearest-relay selection into a [Mode]:
m, err := relay.DefaultMap().PreferNearest(ctx, nil)
if err == nil {
mode = relay.ModeCustom(m)
}
On error (empty map or all relays unreachable) it returns the error and a nil
map so the caller can fall back to the full set. Remove deletes the config for url, returning it and whether it was present.(*Map) String() string URLs returns the relay URLs in sorted order.
*Map : expvar.Var
*Map : fmt.Stringer
func DefaultMap() *Map
func MapFromURLs(urls ...netaddr.RelayURL) *Map
func NewMap(configs ...Config) *Map
func StagingMap() *Map
func (*Map).Clone() *Map
func (*Map).PreferNearest(ctx context.Context, prober Prober) (*Map, error)
func Mode.Map() *Map
func ModeCustom(m *Map) Mode
func RankByLatency(ctx context.Context, m *Map, prober Prober) []RelayLatency
func github.com/tmc/go-iroh/internal/netreport.NewClient(relayMap *Map) *netreport.Client
QUICConfig configures relay-based QUIC address discovery. Port is the QUIC port on the relay server.
func NewConfig(url netaddr.RelayURL, quic *QUICConfig) Config
DefaultMap returns the number0 production relay map.
HTTPConnectProber returns a Prober that measures the time to establish a TLS
connection to a relay's HTTPS endpoint. It reflects the real connect cost a
relay client pays, which is dominated by round-trip latency to the relay, and
is cheaper than a full net-report probe.
tlsConfig, if non-nil, overrides the TLS configuration (used in tests to skip
verification against a local relay). A relay URL without an explicit port uses
443.
MapFromURLs builds a Map from relay URLs, each with a default config that
enables QUIC address discovery on [DefaultQUICPort]. net_report only probes
relays whose config has a QUIC section, so a nil default would disable
address discovery for every URL-built map, including [DefaultMap]. A relay
without QAD just fails the probe, which stays latency-only.
ModeCustom uses a custom relay map.
ModeCustomURLs uses a custom relay map built from the given URLs.
ModeDefault uses the number0 production relay servers.
ModeDisabled disables relay servers entirely.
ModeStaging uses the number0 staging relay servers.
NewConfig returns a Config for url with the given optional QUIC config.
NewMap builds a Map from the given relay configs.
RankByLatency probes every relay in m using prober, concurrently, and returns
the results sorted by ascending latency. Reachable relays (Err == nil) sort
before unreachable ones; ties and unreachable relays are ordered
deterministically by relay URL so selection is reproducible.
If prober is nil, [HTTPConnectProber] is used. RankByLatency never returns a
nil slice for a non-empty map: an unreachable relay appears with its Err set.
StagingMap returns the number0 staging relay map.
Package-Level Variables (only one)
ErrNoRelays is returned by [Map.Nearest] when the map has no relays or none
could be reached.
Package-Level Constants (only one)
DefaultQUICPort is the default port for relay QUIC address discovery.
The pages are generated with Goldsv0.8.4. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.