From 11b2ca66e3cfed22d62a3cb48c4485e6a3b548a2 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Wed, 14 Feb 2018 01:28:55 +0100 Subject: [feat] timeout if bitmaskd doesn't respond - Resolves: #7 --- bitmask/main.go | 4 ++++ main.go | 3 ++- notificator.go | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bitmask/main.go b/bitmask/main.go index 4efaae1..185c3a0 100644 --- a/bitmask/main.go +++ b/bitmask/main.go @@ -19,6 +19,7 @@ import ( "encoding/json" "errors" "log" + "time" "github.com/pebbe/zmq4" ) @@ -26,6 +27,7 @@ import ( const ( // On win should be: tcp://127.0.0.1:5001 coreEndpoint = "ipc:///tmp/bitmask.core.sock" + timeout = time.Second * 40 ) // Bitmask holds the bitmask client data @@ -47,6 +49,8 @@ func Init() (*Bitmask, error) { return nil, err } + coresoc.SetRcvtimeo(timeout) + b := Bitmask{coresoc, eventsoc, statusCh} go b.eventsHandler() return &b, nil diff --git a/main.go b/main.go index 82a3a9e..9938359 100644 --- a/main.go +++ b/main.go @@ -49,7 +49,8 @@ func checkAndInstallHelpers(b *bitmask.Bitmask, notify *notificator) { log.Printf("No polkit found") notify.authAgent() } else if err != nil { - log.Fatal(err) + notify.bitmaskNotRunning() + log.Fatal("Is bitmask running? ", err) } if !helpers { diff --git a/notificator.go b/notificator.go index dce1a79..375b883 100644 --- a/notificator.go +++ b/notificator.go @@ -26,6 +26,7 @@ import ( const ( donationText = `The RiseupVPN service is expensive to run. Because we don't want to store personal information about you, there is no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month at https://riseup.net/donate-vpn` missingAuthAgent = `Could not find a polkit authentication agent. Please run one and try again.` + notRunning = `Is bitmaskd running? Start bitmask and try again.` ) type notificator struct { @@ -55,6 +56,10 @@ func (n *notificator) donations() { } } +func (n *notificator) bitmaskNotRunning() { + n.notify.Push("Can't contact bitmask", notRunning, "", notif.UR_CRITICAL) +} + func (n *notificator) authAgent() { n.notify.Push("Missing authentication agent", missingAuthAgent, "", notif.UR_CRITICAL) } -- cgit v1.2.3