summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2021-09-24 20:58:30 +0200
committerkali kaneko (leap communications) <kali@leap.se>2021-11-23 21:51:08 +0100
commit0efd19b935452a7b0b5561f9cba56b01ba7c627f (patch)
treef7ca08f78a76d64b0be83eef789ed6a935ca31d1
parentbe36ce80cac534afda4393fc6bd904d489b63361 (diff)
[feat] persist obfs4 & udp prefs
-rw-r--r--gui/backend.go5
-rw-r--r--gui/components/Preferences.qml13
-rw-r--r--gui/handlers.cpp5
-rw-r--r--gui/handlers.h1
-rw-r--r--pkg/backend/actions.go7
-rw-r--r--pkg/backend/api.go16
-rw-r--r--pkg/backend/init.go4
-rw-r--r--pkg/backend/status.go2
-rw-r--r--pkg/config/gui.go34
9 files changed, 67 insertions, 20 deletions
diff --git a/gui/backend.go b/gui/backend.go
index bc056b9..5c07cda 100644
--- a/gui/backend.go
+++ b/gui/backend.go
@@ -53,6 +53,11 @@ func GetTransport() *C.char {
return (*C.char)(backend.GetTransport())
}
+//export SetUDP
+func SetUDP(udp bool) {
+ backend.SetUDP(udp)
+}
+
//export Quit
func Quit() {
backend.Quit()
diff --git a/gui/components/Preferences.qml b/gui/components/Preferences.qml
index 5c708a3..3620471 100644
--- a/gui/components/Preferences.qml
+++ b/gui/components/Preferences.qml
@@ -67,6 +67,9 @@ ThemedPage {
text: qsTr("UDP")
enabled: false
checked: false
+ onClicked: {
+ doUseUDP(checked)
+ }
}
}
@@ -131,6 +134,16 @@ ThemedPage {
}
}
+ function doUseUDP(value) {
+ if (value == true) {
+ console.debug("use udp")
+ backend.setUDP(true)
+ } else {
+ console.debug("use tcp")
+ backend.setUDP(false)
+ }
+ }
+
Component.onCompleted: {
if (ctx && ctx.transport == "obfs4") {
useBridgesCheckBox.checked = true
diff --git a/gui/handlers.cpp b/gui/handlers.cpp
index 29fecf1..b1d060b 100644
--- a/gui/handlers.cpp
+++ b/gui/handlers.cpp
@@ -57,6 +57,11 @@ void Backend::setTransport(QString transport)
SetTransport(toGoStr(transport));
}
+void Backend::setUDP(bool udp)
+{
+ SetUDP(udp);
+}
+
QString Backend::getTransport()
{
return QString(GetTransport());
diff --git a/gui/handlers.h b/gui/handlers.h
index a3812c5..55dd32d 100644
--- a/gui/handlers.h
+++ b/gui/handlers.h
@@ -39,6 +39,7 @@ public slots:
void useLocation(QString username);
void useAutomaticGateway();
void setTransport(QString transport);
+ void setUDP(bool udp);
QString getTransport();
void login(QString username, QString password);
void resetError(QString errlabel);
diff --git a/pkg/backend/actions.go b/pkg/backend/actions.go
index 9e0941b..805c5ad 100644
--- a/pkg/backend/actions.go
+++ b/pkg/backend/actions.go
@@ -23,10 +23,3 @@ func stopVPN() {
func getGateway() string {
return ctx.bm.GetCurrentGateway()
}
-
-func setTransport(t string) {
- err := ctx.bm.SetTransport(t)
- if err != nil {
- log.Println(err)
- }
-}
diff --git a/pkg/backend/api.go b/pkg/backend/api.go
index 96f3072..51fa377 100644
--- a/pkg/backend/api.go
+++ b/pkg/backend/api.go
@@ -80,7 +80,21 @@ func UseAutomaticGateway() {
}
func SetTransport(label string) {
- ctx.bm.SetTransport(label)
+ err := ctx.bm.SetTransport(label)
+ if err != nil {
+ log.Println(err)
+ }
+ if label == "obfs4" {
+ ctx.cfg.SetUseObfs4(true)
+ } else {
+ ctx.cfg.SetUseObfs4(false)
+ }
+ go trigger(OnStatusChanged)
+}
+
+func SetUDP(udp bool) {
+ log.Println("DEBUG setting UDP")
+ ctx.cfg.SetUseUDP(udp)
go trigger(OnStatusChanged)
}
diff --git a/pkg/backend/init.go b/pkg/backend/init.go
index fcde725..70a3582 100644
--- a/pkg/backend/init.go
+++ b/pkg/backend/init.go
@@ -103,13 +103,13 @@ func setConfigOpts(opts *InitOpts, conf *config.Config) {
conf.Obfs4 = opts.Obfs4
}
if opts.DisableAutostart {
- conf.DisableAustostart = opts.DisableAutostart
+ conf.DisableAutostart = opts.DisableAutostart
}
}
func initializeAutostart(conf *config.Config) bitmask.Autostart {
autostart := bitmask.NewAutostart(config.ApplicationName, "")
- if conf.SkipLaunch || conf.DisableAustostart {
+ if conf.SkipLaunch || conf.DisableAutostart {
autostart.Disable()
autostart = &bitmask.DummyAutostart{}
}
diff --git a/pkg/backend/status.go b/pkg/backend/status.go
index c5f79d1..79b70ff 100644
--- a/pkg/backend/status.go
+++ b/pkg/backend/status.go
@@ -51,6 +51,7 @@ type connectionCtx struct {
CurrentCountry string `json:"currentCountry"`
BestLocation string `json:"bestLocation"`
Transport string `json:"transport"`
+ UseUDP bool `json:"udp"`
ManualLocation bool `json:"manualLocation"`
IsReady bool `json:"isReady"`
bm bitmask.Bitmask
@@ -69,6 +70,7 @@ func (c *connectionCtx) toJson() ([]byte, error) {
c.CurrentCountry = c.bm.GetCurrentCountry()
c.BestLocation = c.bm.GetBestLocation(transport)
c.Transport = transport
+ c.UseUDP = c.cfg.UDP // TODO initialize bitmask too
c.ManualLocation = c.bm.IsManualLocation()
}
defer statusMutex.Unlock()
diff --git a/pkg/config/gui.go b/pkg/config/gui.go
index f5ae7a2..6004d20 100644
--- a/pkg/config/gui.go
+++ b/pkg/config/gui.go
@@ -36,16 +36,18 @@ var (
// Config holds the configuration of the systray
type Config struct {
file struct {
- LastReminded time.Time
- Donated time.Time
- Obfs4 bool
- UserStoppedVPN bool
- DisableAustostart bool
+ LastReminded time.Time
+ Donated time.Time
+ Obfs4 bool
+ UserStoppedVPN bool
+ DisableAutostart bool
+ UDP bool
}
- Obfs4 bool
- DisableAustostart bool
- StartVPN bool
- SkipLaunch bool
+ SkipLaunch bool
+ Obfs4 bool
+ DisableAutostart bool
+ StartVPN bool
+ UDP bool
}
// ParseConfig reads the configuration from the configuration file
@@ -62,7 +64,7 @@ func ParseConfig() *Config {
}
conf.Obfs4 = conf.file.Obfs4
- conf.DisableAustostart = conf.file.DisableAustostart
+ conf.DisableAutostart = conf.file.DisableAutostart
conf.StartVPN = !conf.file.UserStoppedVPN
return &conf
}
@@ -90,6 +92,18 @@ func (c *Config) SetDonated() error {
return c.save()
}
+func (c *Config) SetUseObfs4(val bool) error {
+ c.Obfs4 = val
+ c.file.Obfs4 = val
+ return c.save()
+}
+
+func (c *Config) SetUseUDP(val bool) error {
+ c.UDP = val
+ c.file.UDP = val
+ return c.save()
+}
+
func (c *Config) save() error {
f, err := os.Create(configPath)
if err != nil {