diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2020-09-02 21:38:13 +0200 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2021-05-04 14:58:39 +0200 |
commit | 335bb742b957370bbf40ae77a661559805ab307f (patch) | |
tree | 3d8b9a8023b1bcca2b531bf57b1fd846916f4a8e /pkg/vpn/bonafide | |
parent | 68f566cf7fddbe9e5eb08c4c07a76375148b682b (diff) |
[feat] expose gateway selection in webapi
Diffstat (limited to 'pkg/vpn/bonafide')
-rw-r--r-- | pkg/vpn/bonafide/bonafide.go | 17 | ||||
-rw-r--r-- | pkg/vpn/bonafide/gateways.go | 8 |
2 files changed, 25 insertions, 0 deletions
diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go index 22e3051..8b60641 100644 --- a/pkg/vpn/bonafide/bonafide.go +++ b/pkg/vpn/bonafide/bonafide.go @@ -197,6 +197,8 @@ func (b *Bonafide) maybeInitializeEIP() error { return nil } +// GetGateways filters by transport, and will return the maximum number defined +// in bonafide.maxGateways, or the maximum by default (3). func (b *Bonafide) GetGateways(transport string) ([]Gateway, error) { err := b.maybeInitializeEIP() if err != nil { @@ -211,6 +213,17 @@ func (b *Bonafide) GetGateways(transport string) ([]Gateway, error) { return gws, err } +// GetAllGateways only filters gateways by transport. +// TODO could pass "any" instead? +func (b *Bonafide) GetAllGateways(transport string) ([]Gateway, error) { + err := b.maybeInitializeEIP() + if err != nil { + return nil, err + } + gws, err := b.gateways.getAll(transport, b.tzOffsetHours) + return gws, err +} + func (b *Bonafide) SetManualGateway(label string) { b.gateways.setUserChoice(label) } @@ -219,6 +232,10 @@ func (b *Bonafide) SetAutomaticGateway() { b.gateways.setAutomaticChoice() } +func (b *Bonafide) GetGatewayByIP(ip string) (Gateway, error) { + return b.gateways.getGatewayByIP(ip) +} + /* TODO this still needs to be called periodically */ func (b *Bonafide) fetchGatewayRanking() error { /* FIXME in float deployments, geolocation is served on gemyip.domain/json, with a LE certificate, but in riseup is served behind the api certificate. diff --git a/pkg/vpn/bonafide/gateways.go b/pkg/vpn/bonafide/gateways.go index 6084985..d973530 100644 --- a/pkg/vpn/bonafide/gateways.go +++ b/pkg/vpn/bonafide/gateways.go @@ -142,6 +142,14 @@ func (p *gatewayPool) getBest(transport string, tz, max int) ([]Gateway, error) } } +func (p *gatewayPool) getAll(transport string, tz int) ([]Gateway, error) { + if len(p.ranked) != 0 { + return p.getGatewaysByServiceRank(transport, 999) + } else { + return p.getGatewaysByTimezone(transport, tz, 999) + } +} + func (p *gatewayPool) getGatewaysByServiceRank(transport string, max int) ([]Gateway, error) { gws := make([]Gateway, 0) for _, host := range p.ranked { |