Skip to content
Snippets Groups Projects
Unverified Commit a81bf938 authored by Kali Kaneko's avatar Kali Kaneko
Browse files

[feat] enable udp only if really announced

parent a234a8ef
No related branches found
No related tags found
No related merge requests found
......@@ -5,10 +5,6 @@ import QtQuick.Controls.Material 2.1
import "../themes/themes.js" as Theme
// TODO
// [ ] disable UDP if provider doesn't support it
// [ ] disable UDP if the platform doesn't support it
ThemedPage {
title: qsTr("Preferences")
......@@ -116,7 +112,7 @@ ThemedPage {
}
Label {
text: qsTr("UDP can make the VPN faster")
text: qsTr("UDP can make the VPN faster, but it might be blocked on certain networks")
width: parent.width
color: "gray"
visible: true
......@@ -124,6 +120,7 @@ ThemedPage {
font.pixelSize: Theme.fontSize - 3
Layout.leftMargin: 10
Layout.rightMargin: 10
Layout.preferredWidth: 240
}
MaterialCheckBox {
......@@ -232,5 +229,8 @@ ThemedPage {
if (ctx && ctx.udp == "true") {
useUDP.checked = true
}
if (ctx && ctx.offersUdp == "false") {
useUDP.enabled = false
}
}
}
# 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...
......@@ -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()
......
......@@ -36,6 +36,7 @@ type Bitmask interface {
GetTransport() string
SetTransport(string) error
UseUDP(bool) error
OffersUDP() bool
GetCurrentGateway() string
GetCurrentLocation() string
GetCurrentCountry() string
......
......@@ -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)
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment