diff options
author | kali kaneko (leap communications) <kali@leap.se> | 2021-11-25 13:45:54 +0100 |
---|---|---|
committer | kali kaneko (leap communications) <kali@leap.se> | 2021-11-29 18:14:05 +0100 |
commit | b7b19b7195366dbacc4078b5b7a3fc6a3ad7889b (patch) | |
tree | 2b97e0167d507ddd9c1b5b0d5f0d3efbc4e6829c /pkg | |
parent | a81bf938fe2b9409d1fa0175cc5f20635bb16127 (diff) |
[feat] expose snowflake in preferences
it will be disabled if Tor not present, for now
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/backend/api.go | 9 | ||||
-rw-r--r-- | pkg/backend/status.go | 7 | ||||
-rw-r--r-- | pkg/bitmask/bitmask.go | 1 | ||||
-rw-r--r-- | pkg/config/gui.go | 10 | ||||
-rw-r--r-- | pkg/snowflake/tor.go | 15 | ||||
-rw-r--r-- | pkg/vpn/main.go | 8 |
6 files changed, 47 insertions, 3 deletions
diff --git a/pkg/backend/api.go b/pkg/backend/api.go index d7dcbb3..6d5ceee 100644 --- a/pkg/backend/api.go +++ b/pkg/backend/api.go @@ -94,12 +94,19 @@ func SetTransport(label string) { } func SetUDP(udp bool) { - log.Println("DEBUG setting UDP") + log.Printf("DEBUG udp:%v\n", udp) ctx.cfg.SetUseUDP(udp) ctx.bm.UseUDP(udp) go trigger(OnStatusChanged) } +func SetSnowflake(snowflake bool) { + log.Printf("DEBUG snowflake:%v\n", snowflake) + ctx.cfg.SetUseSnowflake(snowflake) + ctx.bm.UseSnowflake(snowflake) + go trigger(OnStatusChanged) +} + func GetTransport() *C.char { return C.CString(ctx.bm.GetTransport()) } diff --git a/pkg/backend/status.go b/pkg/backend/status.go index 2ed5cfd..de6364f 100644 --- a/pkg/backend/status.go +++ b/pkg/backend/status.go @@ -8,6 +8,7 @@ import ( "0xacab.org/leap/bitmask-vpn/pkg/bitmask" "0xacab.org/leap/bitmask-vpn/pkg/config" + "0xacab.org/leap/bitmask-vpn/pkg/snowflake" ) const ( @@ -57,6 +58,8 @@ type connectionCtx struct { IsReady bool `json:"isReady"` CanUpgrade bool `json:"canUpgrade"` Motd string `json:"motd"` + HasTor bool `json:"hasTor"` + UseSnowflake bool `json:"snowflake"` bm bitmask.Bitmask autostart bitmask.Autostart cfg *config.Config @@ -73,11 +76,13 @@ 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.UseUDP = c.cfg.UDP // TODO initialize bitmask param? c.OffersUDP = c.bm.OffersUDP() + c.UseSnowflake = c.cfg.Snowflake // TODO initialize bitmask param? c.ManualLocation = c.bm.IsManualLocation() c.CanUpgrade = c.bm.CanUpgrade() c.Motd = c.bm.GetMotd() + c.HasTor = snowflake.HasTor() } defer statusMutex.Unlock() b, err := json.Marshal(c) diff --git a/pkg/bitmask/bitmask.go b/pkg/bitmask/bitmask.go index 80b502e..0c2a344 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 + UseSnowflake(bool) error OffersUDP() bool GetCurrentGateway() string GetCurrentLocation() string diff --git a/pkg/config/gui.go b/pkg/config/gui.go index 6004d20..1d23018 100644 --- a/pkg/config/gui.go +++ b/pkg/config/gui.go @@ -42,12 +42,14 @@ type Config struct { UserStoppedVPN bool DisableAutostart bool UDP bool + Snowflake bool } SkipLaunch bool Obfs4 bool DisableAutostart bool StartVPN bool UDP bool + Snowflake bool } // ParseConfig reads the configuration from the configuration file @@ -66,6 +68,8 @@ func ParseConfig() *Config { conf.Obfs4 = conf.file.Obfs4 conf.DisableAutostart = conf.file.DisableAutostart conf.StartVPN = !conf.file.UserStoppedVPN + conf.UDP = conf.file.UDP + conf.Snowflake = conf.file.Snowflake return &conf } @@ -104,6 +108,12 @@ func (c *Config) SetUseUDP(val bool) error { return c.save() } +func (c *Config) SetUseSnowflake(val bool) error { + c.Snowflake = val + c.file.Snowflake = val + return c.save() +} + func (c *Config) save() error { f, err := os.Create(configPath) if err != nil { diff --git a/pkg/snowflake/tor.go b/pkg/snowflake/tor.go new file mode 100644 index 0000000..4f4c4e4 --- /dev/null +++ b/pkg/snowflake/tor.go @@ -0,0 +1,15 @@ +package snowflake + +import ( + "errors" + "os" +) + +func exists(path string) bool { + _, err := os.Stat(path) + return !errors.Is(err, os.ErrNotExist) +} + +func HasTor() bool { + return exists("/usr/sbin/tor") +} diff --git a/pkg/vpn/main.go b/pkg/vpn/main.go index 176c86f..da6caf1 100644 --- a/pkg/vpn/main.go +++ b/pkg/vpn/main.go @@ -43,6 +43,7 @@ type Bitmask struct { certPemPath string openvpnArgs []string udp bool + snowflake bool offersUdp bool failed bool canUpgrade bool @@ -68,7 +69,7 @@ func Init() (*Bitmask, error) { bonafide.Gateway{}, bonafide.Gateway{}, statusCh, nil, bf, launch, "", nil, "", []string{}, - false, false, 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. @@ -151,6 +152,11 @@ func (b *Bitmask) UseUDP(udp bool) error { return nil } +func (b *Bitmask) UseSnowflake(s bool) error { + b.snowflake = s + return nil +} + func (b *Bitmask) OffersUDP() bool { return b.bonafide.IsUDPAvailable() } |