summaryrefslogtreecommitdiff
path: root/bitmask/events.go
blob: 3fed26a36bb8e10ca726f5ae77d9d9846f4d4115 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package bitmask

import (
	"github.com/pebbe/zmq4"
)

const (
	eventsEndpoint = "tcp://127.0.0.1:9001"
	//serverKeyPath  = "/home/user/.config/leap/events/zmq_certificates/public_keys/server.key" // FIXME
)

func initEvents() (*zmq4.Socket, error) {
	socket, err := zmq4.NewSocket(zmq4.SUB)
	if err != nil {
		return nil, err
	}

	if zmq4.HasCurve() {
		// TODO
	}

	err = socket.Connect(eventsEndpoint)
	if err != nil {
		return nil, err
	}
	return socket, nil
}

func (b *Bitmask) fetchStatus() {
	// TODO: this should be a subscription to the event
	for {
		time.Sleep(time.Second)
		status, err := b.GetStatus()
		if err != nil {
			log.Printf("Error receiving status: %v", err)
			continue
		}
		b.statusCh <- status
	}
}