diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2021-11-24 20:40:18 +0100 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2021-11-24 21:16:01 +0100 |
commit | a81bf938fe2b9409d1fa0175cc5f20635bb16127 (patch) | |
tree | bb5b86654b687d31fe880a8996674272cf1e4fa8 /pkg | |
parent | a234a8ef5bf8564221f615d0010a810e501905bb (diff) |
[feat] enable udp only if really announced
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/backend/README.md | 10 | ||||
-rw-r--r-- | pkg/backend/status.go | 2 | ||||
-rw-r--r-- | pkg/bitmask/bitmask.go | 1 | ||||
-rw-r--r-- | pkg/vpn/bonafide/eip_service.go | 20 | ||||
-rw-r--r-- | pkg/vpn/main.go | 7 |
5 files changed, 39 insertions, 1 deletions
diff --git a/pkg/backend/README.md b/pkg/backend/README.md new file mode 100644 index 0000000..1adefe8 --- /dev/null +++ b/pkg/backend/README.md @@ -0,0 +1,10 @@ +# how to add new fields to backend api + +1. add to the struct in `status.go` +2. populate it in `toJson()` method. +3. modify the `bitmask` interface in `pkg/bitmask/bitmask.go` (note: this is + a relict from the past, we can probably get rid of since there'll be + a single implementation in the foreseeable future). +4. modify the `bitmask` struct in `pkg/vpn/main.go` +5. modify the bitmask instantiation in `pkg/vpn/main.go:Init` +6. implement functionality... diff --git a/pkg/backend/status.go b/pkg/backend/status.go index f21fddd..2ed5cfd 100644 --- a/pkg/backend/status.go +++ b/pkg/backend/status.go @@ -52,6 +52,7 @@ type connectionCtx struct { BestLocation string `json:"bestLocation"` Transport string `json:"transport"` UseUDP bool `json:"udp"` + OffersUDP bool `json:"offersUdp"` ManualLocation bool `json:"manualLocation"` IsReady bool `json:"isReady"` CanUpgrade bool `json:"canUpgrade"` @@ -73,6 +74,7 @@ func (c *connectionCtx) toJson() ([]byte, error) { c.BestLocation = c.bm.GetBestLocation(transport) c.Transport = transport c.UseUDP = c.cfg.UDP // TODO initialize bitmask too + c.OffersUDP = c.bm.OffersUDP() c.ManualLocation = c.bm.IsManualLocation() c.CanUpgrade = c.bm.CanUpgrade() c.Motd = c.bm.GetMotd() diff --git a/pkg/bitmask/bitmask.go b/pkg/bitmask/bitmask.go index d02487b..80b502e 100644 --- a/pkg/bitmask/bitmask.go +++ b/pkg/bitmask/bitmask.go @@ -36,6 +36,7 @@ type Bitmask interface { GetTransport() string SetTransport(string) error UseUDP(bool) error + OffersUDP() bool GetCurrentGateway() string GetCurrentLocation() string GetCurrentCountry() string diff --git a/pkg/vpn/bonafide/eip_service.go b/pkg/vpn/bonafide/eip_service.go index 28d0479..1b8dc01 100644 --- a/pkg/vpn/bonafide/eip_service.go +++ b/pkg/vpn/bonafide/eip_service.go @@ -76,6 +76,26 @@ func (b *Bonafide) setupAuthentication(i interface{}) { } } +func (b *Bonafide) IsUDPAvailable() bool { + if b.eip == nil { + return false + } + for _, gw := range b.eip.Gateways { + for _, t := range gw.Capabilities.Transport { + if t.Type == "openvpn" { + for _, proto := range t.Protocols { + if proto == "udp" { + return true + } + } + } + + } + + } + return false +} + func (b *Bonafide) fetchEipJSON() error { eip3API := config.APIURL + "3/config/eip-service.json" resp, err := b.client.Post(eip3API, "", nil) diff --git a/pkg/vpn/main.go b/pkg/vpn/main.go index 619a10f..176c86f 100644 --- a/pkg/vpn/main.go +++ b/pkg/vpn/main.go @@ -43,6 +43,7 @@ type Bitmask struct { certPemPath string openvpnArgs []string udp bool + offersUdp bool failed bool canUpgrade bool motd []motd.Message @@ -67,7 +68,7 @@ func Init() (*Bitmask, error) { bonafide.Gateway{}, bonafide.Gateway{}, statusCh, nil, bf, launch, "", nil, "", []string{}, - false, false, false, + false, false, false, false, []motd.Message{}, ""} // FIXME multiprovider: need to pass provider name early on // XXX we want to block on these, but they can timeout if we're blocked. @@ -150,6 +151,10 @@ func (b *Bitmask) UseUDP(udp bool) error { return nil } +func (b *Bitmask) OffersUDP() bool { + return b.bonafide.IsUDPAvailable() +} + func (b *Bitmask) GetMotd() string { bytes, err := json.Marshal(b.motd) if err != nil { |