summaryrefslogtreecommitdiff
path: root/bitmask/events.go
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2018-06-04 13:23:35 +0200
committerRuben Pollan <meskio@sindominio.net>2018-06-04 20:59:09 +0200
commitde9eb2148f9d1af3a0e78b2567f862269df7517f (patch)
treee504f38b29ac86e0871a7a515f5da796684c8a2b /bitmask/events.go
parent8c3ba3a2d6a3db9d277c9d6b7532d125b39e1676 (diff)
[feat] use http to communicate with the core
Instead of using zmq.
Diffstat (limited to 'bitmask/events.go')
-rw-r--r--bitmask/events.go64
1 files changed, 12 insertions, 52 deletions
diff --git a/bitmask/events.go b/bitmask/events.go
index f8b3725..e97804c 100644
--- a/bitmask/events.go
+++ b/bitmask/events.go
@@ -16,63 +16,27 @@
package bitmask
import (
- "io/ioutil"
"log"
- "path/filepath"
- "strings"
-
- "github.com/pebbe/zmq4"
+ "net/http"
)
const (
- eventsEndpoint = "tcp://127.0.0.1:9001"
- statusEvent = "VPN_STATUS_CHANGED"
+ statusEvent = "VPN_STATUS_CHANGED"
)
-func initEvents() (*zmq4.Socket, error) {
- socket, err := zmq4.NewSocket(zmq4.SUB)
- if err != nil {
- return nil, err
- }
-
- if hasCurve() {
- err = initCurve(socket)
- if err != nil {
- return nil, err
- }
- }
-
- err = socket.Connect(eventsEndpoint)
- if err != nil {
- return nil, err
- }
-
- err = socket.SetSubscribe(statusEvent)
- return socket, err
-}
-
-func initCurve(socket *zmq4.Socket) error {
- serverKeyData, err := ioutil.ReadFile(getServerKeyPath())
- if err != nil {
- return err
- }
-
- pubkey, seckey, err := zmq4.NewCurveKeypair()
- if err != nil {
- return err
- }
-
- serverkey := strings.Split(string(serverKeyData), "\"")[1]
- return socket.ClientAuthCurve(serverkey, pubkey, seckey)
-}
-
func (b *Bitmask) eventsHandler() {
+ b.send("events", "register", statusEvent)
+ client := &http.Client{
+ Timeout: 0,
+ }
for {
- msg, err := b.eventsoc.RecvMessage(0)
- if err != nil {
- break
+ resJSON, err := send(b.apiToken, client, "events", "poll")
+ res, ok := resJSON.([]interface{})
+ if err != nil || !ok || len(res) < 1 {
+ continue
}
- if msg[0][:len(statusEvent)] != statusEvent {
+ event, ok := res[0].(string)
+ if !ok || event != statusEvent {
continue
}
@@ -84,7 +48,3 @@ func (b *Bitmask) eventsHandler() {
b.statusCh <- status
}
}
-
-func getServerKeyPath() string {
- return filepath.Join(ConfigPath, "events", "zmq_certificates", "public_keys", "server.key")
-}