summaryrefslogtreecommitdiff
path: root/pkg/backend/bitmask.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2020-06-12 20:00:13 +0200
committerkali kaneko (leap communications) <kali@leap.se>2020-06-12 20:03:03 +0200
commit0ac0afaaf312a02af01d1c307ecf9b5915f40b0d (patch)
treeb2d0b9a776c47c5c2cac90595a9721730e59a519 /pkg/backend/bitmask.go
parent1038fa83b820bbdaa9bcf37118cf23b0e48a86c5 (diff)
[refactor] reorganize backend in its own module
Signed-off-by: kali kaneko (leap communications) <kali@leap.se>
Diffstat (limited to 'pkg/backend/bitmask.go')
-rw-r--r--pkg/backend/bitmask.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/pkg/backend/bitmask.go b/pkg/backend/bitmask.go
new file mode 100644
index 0000000..07d27ea
--- /dev/null
+++ b/pkg/backend/bitmask.go
@@ -0,0 +1,52 @@
+package backend
+
+import (
+ "log"
+ "os"
+
+ "0xacab.org/leap/bitmask-vpn/pkg/bitmask"
+)
+
+func initializeBitmask() {
+ if ctx == nil {
+ log.Println("error: cannot initialize bitmask, ctx is nil")
+ os.Exit(1)
+ }
+ bitmask.InitializeLogger()
+
+ b, err := bitmask.InitializeBitmask()
+ if err != nil {
+ log.Println("error: cannot initialize bitmask")
+ }
+ ctx.bm = b
+}
+
+func startVPN() {
+ err := ctx.bm.StartVPN(ctx.Provider)
+ if err != nil {
+ log.Println(err)
+ os.Exit(1)
+ }
+}
+
+func stopVPN() {
+ err := ctx.bm.StopVPN()
+ if err != nil {
+ log.Println(err)
+ }
+}
+
+// initializeContext initializes an empty connStatus and assigns it to the
+// global ctx holder. This is expected to be called only once, so the public
+// api uses the sync.Once primitive to call this.
+func initializeContext(provider, appName string) {
+ var st status = off
+ ctx = &connectionCtx{
+ AppName: appName,
+ Provider: provider,
+ Donate: false,
+ Status: st,
+ }
+ go trigger(OnStatusChanged)
+ initializeBitmask()
+}