summaryrefslogtreecommitdiff
path: root/pkg/backend/api.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/api.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/api.go')
-rw-r--r--pkg/backend/api.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/pkg/backend/api.go b/pkg/backend/api.go
new file mode 100644
index 0000000..f924cbd
--- /dev/null
+++ b/pkg/backend/api.go
@@ -0,0 +1,74 @@
+/* All the exported functions live here */
+
+package backend
+
+import (
+ "C"
+ "fmt"
+ "log"
+ "unsafe"
+
+ "0xacab.org/leap/bitmask-vpn/pkg/bitmask"
+ "0xacab.org/leap/bitmask-vpn/pkg/pickle"
+)
+
+func SwitchOn() {
+ go setStatus(starting)
+ go startVPN()
+}
+
+func SwitchOff() {
+ go setStatus(stopping)
+ go stopVPN()
+}
+
+func Unblock() {
+ fmt.Println("unblock... [not implemented]")
+}
+
+func Quit() {
+ if ctx.Status != off {
+ go setStatus(stopping)
+ stopVPN()
+ }
+}
+
+func ToggleDonate() {
+ toggleDonate()
+}
+
+func SubscribeToEvent(event string, f unsafe.Pointer) {
+ subscribe(event, f)
+}
+
+func InitializeBitmaskContext() {
+ pi := bitmask.GetConfiguredProvider()
+
+ initOnce.Do(func() {
+ initializeContext(pi.Provider, pi.AppName)
+ })
+ go ctx.updateStatus()
+
+ /* DEBUG
+ timer := time.NewTimer(time.Second * 3)
+ go func() {
+ <-timer.C
+ fmt.Println("donate timer fired")
+ toggleDonate()
+ }()
+ */
+}
+
+func RefreshContext() *C.char {
+ c, _ := ctx.toJson()
+ return C.CString(string(c))
+}
+
+func InstallHelpers() {
+ pickle.InstallHelpers()
+}
+
+func MockUIInteraction() {
+ log.Println("mocking ui interaction on port 8080. \nTry 'curl localhost:8080/{on|off|failed}' to toggle status.")
+ go mockUI()
+}