Return a list of ports for /gateway endpoints #30
There is more work to be done. Currently, the registry holds a list of
gatways. In the current implementation, gateway is defined as
gateway+port. So each gateway has multiple entries in the gateways
map of the registry
Currently, the api endpoint /gateways
returns a single port of the gateway
> curl -s 'localhost:8443/api/5/gateways?port=53' | jq '.[0]'
{
"experimental": false,
"healthy": true,
"host": "vpn10-mtl.riseup.net",
"ip_addr": "199.58.83.11",
"ip6_addr": "",
"load": 0,
"location": "montreal",
"overloaded": false,
"port": 53, <------
"transport": "udp",
"type": "openvpn"
}
As we discussed in #30, we want to return a list of ports. Also the order of the ports are important. The client should use the first one. This is how we can do some load balancing of the gateway. With the current changes, we now get a list of ports:
> curl -s 'localhost:8443/api/5/gateways?port=53' | jq '.[0]'
{
"experimental": false,
"healthy": true,
"host": "vpn05-par.riseup.net",
"ip_addr": "195.154.106.118",
"ip6_addr": "",
"load": 0,
"location": "paris",
"overloaded": false,
"ports": [
53 <-------------
],
"transport": "udp",
"type": "openvpn"
}
Now, in the first step, we just want to change the data model/api design (return a list of ints instead of a single one).
TODO: We need to implement the ordering of the ports (together with handling the load at all). Also, currently only a single port (in a list) is returned. This is caused by the design of the code.
The registry (the global variable that has all the api endpoints) holds a map of gateways (dict[location] = gateway). But the way it is currently implementend, a gateway is more like a gateway-port-combination. So if we print all gateways, then we will get:
&{false true vpn19-ams.riseup.net 163.172.211.109 0 amsterdam false 1194 tcp openvpn}
&{false true vpn19-ams.riseup.net 163.172.211.109 0 amsterdam false 53 udp openvpn}
&{false true vpn19-ams.riseup.net 163.172.211.109 0 amsterdam false 80 udp openvpn}
&{false true vpn19-ams.riseup.net 163.172.211.109 0 amsterdam false 1194 udp openvpn}
&{false true vpn20-par.riseup.net 51.159.198.167 0 paris false 53 tcp openvpn}
&{false true vpn20-par.riseup.net 51.159.198.167 0 paris false 80 tcp openvpn}
So there is a gateway vpn19-ams.riseup.net with IP 163.172.211.109 which supports 1194, 53, 80. But in the printed list of the code, there are three gateways:
- vpn19-ams.riseup.net 163.172.211.109 1194
- vpn19-ams.riseup.net 163.172.211.109 53
If we ask the api to filter for port 53, the filtering works, but as each port is handled independent of the others, a list with only one port is returned. This needs to be addressed in the future. Sorting the ports also requires a proper test environment.
I think we can merge this. Then we can update the swagger stuff. We can keep the issue open until it's fully done.