Documentation ¶
Index ¶
Constants ¶
const ( DefaultUDPPort = "6363" DefaultWebSocketPort = "443" )
Default ports.
Variables ¶
var IPFamilies = []IPFamily{IPv4, IPv6}
IPFamilies is a list of known IPFamily values.
var TransportIPFamilies = func() (list []TransportIPFamily) { for _, tr := range TransportTypes { for _, af := range IPFamilies { list = append(list, TransportIPFamily{tr, af}) } } return list }()
TransportTypes is a list of known TransportIPFamily values.
var TransportTypes = []TransportType{ TransportUDP, TransportWebSocket, TransportH3, }
TransportTypes is a list of known TransportType values.
Functions ¶
func MakeLegacyConnectString ¶
func MakeLegacyConnectString(tr TransportType, connect string) string
MakeLegacyConnectString converts a connect string to legacy syntax.
Types ¶
type LonLat ¶
type LonLat [2]float64
LonLat is a tuple of longitude,latitude in GeoJSON format. https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1
type Query ¶
type Query struct { Count int Transport TransportType IPv4 bool IPv6 bool Position LonLat Network string }
Query represents an API query.
func ParseQueries ¶
ParseQueries constructs a list of Query from URL query string.
func (Query) Execute ¶
func (q Query) Execute(avail []RouterAvail) (res []RouterAvail)
Execute executes a query.
type QueryResponse ¶
type QueryResponse struct { Updated int64 `json:"updated"` // last update time, milliseconds since epoch Routers []QueryResponseRouter `json:"routers"` }
QueryResponse represents an API response.
type QueryResponseRouter ¶
type QueryResponseRouter struct { Transport TransportType `json:"transport"` Connect string `json:"connect"` Prefix string `json:"prefix,omitempty"` }
QueryResponseRouter is part of QueryResponse.
type Router ¶
type Router interface { ID() string Position() LonLat // Prefix returns ping server prefix, excluding "/ping" suffix. // Return empty string if pingserver is unavailable. Prefix() string // ConnectString returns a connection string for the given transport. // - UDP: host:port. // - WebSocket: URI. // - HTTP3: URI. // Return empty string if transport or IP family is not supported. ConnectString(tf TransportIPFamily) string // Neighbor returns a map of neighbor ID and link cost. Neighbors() map[string]int }
Router provides information about a router.
type RouterAvail ¶
type RouterAvail struct { Router Available map[TransportIPFamily]bool }
RouterAvail contains router availability information.
func (RouterAvail) CountAvail ¶
func (r RouterAvail) CountAvail() (n int)
CountAvail returns number of available TransportIPFamily combinations.
func (RouterAvail) MarshalJSON ¶
func (r RouterAvail) MarshalJSON() (j []byte, e error)
MarshalJSON implements json.Marshaler interface.
type TransportIPFamily ¶
type TransportIPFamily struct { Transport TransportType `json:"transport"` Family IPFamily `json:"family"` }
TransportIPFamily is a combination of TransportType and IPFamily.
type TransportType ¶
type TransportType string
TransportType represents a type of transport.
const ( TransportUDP TransportType = "udp" TransportWebSocket TransportType = "wss" TransportH3 TransportType = "http3" )
TransportType values.