Documentation
¶
Overview ¶
Package exitnode implements the exit-node ping dance run before registering with the server: request the candidate exit nodes, ping each one over HTTP, and report the results so the server can pick the best one. It is shared between newt and olm, which both register the same way.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExitNode ¶
type ExitNode struct {
ID int `json:"exitNodeId"`
Name string `json:"exitNodeName"`
Endpoint string `json:"endpoint"`
Weight float64 `json:"weight"`
WasPreviouslyConnected bool `json:"wasPreviouslyConnected"`
}
ExitNode is a candidate exit node offered by the server for ping selection.
type ExitNodeData ¶
type ExitNodeData struct {
ExitNodes []ExitNode `json:"exitNodes"`
ChainId string `json:"chainId"`
}
ExitNodeData is the payload the server sends in response to a "*/ping/request" message.
type ExitNodePingResult ¶
type ExitNodePingResult struct {
ExitNodeID int `json:"exitNodeId"`
LatencyMs int64 `json:"latencyMs"`
Weight float64 `json:"weight"`
Error string `json:"error,omitempty"`
Name string `json:"exitNodeName"`
Endpoint string `json:"endpoint"`
WasPreviouslyConnected bool `json:"wasPreviouslyConnected"`
}
ExitNodePingResult is the measured latency (or error) for one exit node, sent back to the server in the "*/wg/register" message's pingResults field.
func PingExitNodes ¶
func PingExitNodes(exitNodes []ExitNode, preferEndpoint string, alreadyConnected bool) []ExitNodePingResult
PingExitNodes pings the given exit nodes over HTTP and returns a per-node ExitNodePingResult suitable for inclusion in a wg/register message's pingResults field, so the server can select the best exit node.
If there's only one exit node, or preferEndpoint names one of them, the matching node is returned immediately with LatencyMs 0 and no pinging is done. Otherwise every node is pinged pingAttempts times over HTTP GET <endpoint>/ping and the average latency of successful attempts is used.
When alreadyConnected is true, a node flagged WasPreviouslyConnected is excluded from the results as long as at least one other healthy node is available, biasing reconnects toward switching away from a possibly degraded node.