From 2124a55d4a3d0ca00f8eab8f86c292ba1e7ccccf Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Wed, 26 Aug 2020 00:35:01 +0200 Subject: [feat] store gateway we connect to firs step on an usable gateway selector --- pkg/vpn/main.go | 3 ++- pkg/vpn/status.go | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'pkg/vpn') diff --git a/pkg/vpn/main.go b/pkg/vpn/main.go index de8e61f..9ddd9fd 100644 --- a/pkg/vpn/main.go +++ b/pkg/vpn/main.go @@ -29,6 +29,7 @@ import ( // Bitmask holds the bitmask client data type Bitmask struct { tempdir string + onGateway string statusCh chan string managementClient *openvpn.MgmtClient bonafide *bonafide.Bonafide @@ -49,7 +50,7 @@ func Init() (*Bitmask, error) { if err != nil { return nil, err } - b := Bitmask{tempdir, statusCh, nil, bonafide, launch, "", nil} + b := Bitmask{tempdir, "", statusCh, nil, bonafide, launch, "", nil} /* TODO -- we still want to do this, since it resets the fw/vpn if running diff --git a/pkg/vpn/status.go b/pkg/vpn/status.go index a4d7ada..cc2fb62 100644 --- a/pkg/vpn/status.go +++ b/pkg/vpn/status.go @@ -18,6 +18,7 @@ package vpn import ( "fmt" "log" + "strings" "github.com/apparentlymart/go-openvpn-mgmt/openvpn" ) @@ -66,10 +67,14 @@ func (b *Bitmask) eventHandler(eventCh <-chan openvpn.Event) { if !ok { continue } - status, ok := statusNames[stateEvent.NewState()] + statusName := stateEvent.NewState() + status, ok := statusNames[statusName] if ok { b.statusCh <- status } + if statusName == "CONNECTED" { + b.onGateway = strings.Split(stateEvent.String(), ": ")[1] + } } b.statusCh <- Off } -- cgit v1.2.3