model

package
v0.0.0-...-43049ce Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: ISC Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultUDPPort       = "6363"
	DefaultWebSocketPort = "443"
)

Default ports.

Variables

View Source
var IPFamilies = []IPFamily{IPv4, IPv6}

IPFamilies is a list of known IPFamily values.

View Source
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.

TransportTypes is a list of known TransportType values.

Functions

func Distance

func Distance(a, b LonLat) float64

Distance returns geographical distance between two coordinates in kilometers.

func MakeLegacyConnectString

func MakeLegacyConnectString(tr TransportType, connect string) string

MakeLegacyConnectString converts a connect string to legacy syntax.

Types

type IPFamily

type IPFamily int

IPFamily indicates an IP address family.

const (
	IPv4 IPFamily = 4
	IPv6 IPFamily = 6
)

IPFamily values.

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

func ParseQueries(qs string) (list []Query)

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.

Jump to

Keyboard shortcuts

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