Nodes returns a list of nodes to use for the tunnel. It will pick a random node from each region. If a customNode is provided, it will be returned as the only node with ID 9999.
(customTunnelHost string)
| 48 | // If a customNode is provided, it will be returned as the only node with ID |
| 49 | // 9999. |
| 50 | func Nodes(customTunnelHost string) ([]Node, error) { |
| 51 | nodes := []Node{} |
| 52 | |
| 53 | if customTunnelHost != "" { |
| 54 | return []Node{ |
| 55 | { |
| 56 | ID: 9999, |
| 57 | RegionID: 9999, |
| 58 | HostnameHTTPS: customTunnelHost, |
| 59 | }, |
| 60 | }, nil |
| 61 | } |
| 62 | |
| 63 | for _, region := range Regions { |
| 64 | // Pick a random node from each region. |
| 65 | i, err := cryptorand.Intn(len(region.Nodes)) |
| 66 | if err != nil { |
| 67 | return []Node{}, err |
| 68 | } |
| 69 | nodes = append(nodes, region.Nodes[i]) |
| 70 | } |
| 71 | |
| 72 | return nodes, nil |
| 73 | } |
| 74 | |
| 75 | // FindClosestNode pings each node and returns the one with the lowest latency. |
| 76 | func FindClosestNode(nodes []Node) (Node, error) { |
no test coverage detected