From 9a62468915bd9dd0a5abce6257500fd55cc8dc93 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 5 Oct 2018 14:43:04 -0700 Subject: [PATCH 1/2] tm status work --- connectivity/tor/tormanager.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/connectivity/tor/tormanager.go b/connectivity/tor/tormanager.go index 3f4f4f8..0adc37c 100644 --- a/connectivity/tor/tormanager.go +++ b/connectivity/tor/tormanager.go @@ -28,6 +28,16 @@ func NewTorManager(socksPort int, controlPort int, torPath string, torrc string) torManager.socksPort = socksPort torManager.controlPort = controlPort + fmt.Println("NewTorManager") + go func() { + fmt.Printf("Monitor\n") + for { + time.Sleep(1 * time.Second) + resp, err := torManager.GetStatus() + fmt.Println(resp, err) + } + }() + err := torManager.TestConnection() if err == nil { @@ -141,3 +151,18 @@ func (tm *Manager) TestConnection() error { } return errors.New(proxyStatusMessage(proxyStatus)) } + +func (tm *Manager) GetStatus() ([]string, error) { + controlAddress := fmt.Sprintf("127.0.0.1:%d", tm.controlPort) + c, err := bulb.Dial("tcp4", controlAddress) + if err != nil { + return []string{}, err + } + defer c.Close() + c.Request("AUTHENTICATE \"\"") + resp, err := c.Request("GETINFO status/bootstrap-phase") + if err != nil { + return []string{}, err + } + return resp.RawLines, nil +} From 4544535ad5dcdb489014e5392ecac4e4398546fb Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Fri, 5 Oct 2018 16:27:57 -0700 Subject: [PATCH 2/2] expose tor control port bootstrap info --- app/app.go | 7 +++++++ connectivity/tor/tormanager.go | 28 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/app.go b/app/app.go index f366891..fa74d51 100644 --- a/app/app.go +++ b/app/app.go @@ -31,6 +31,8 @@ type Application interface { GetPeer(onion string) peer.CwtchPeer ListPeers() map[string]string + GetTorStatus() (map[string]string, error) + Shutdown() } @@ -166,6 +168,11 @@ func (app *application) GetPeer(onion string) peer.CwtchPeer { return nil } +// GetTorStatus returns tor control port bootstrap-phase status info in a map +func (app *application) GetTorStatus() (map[string]string, error) { + return app.torManager.GetStatus() +} + // Shutdown shutsdown all peers of an app and then the tormanager func (app *application) Shutdown() { for _, peer := range app.peers { diff --git a/connectivity/tor/tormanager.go b/connectivity/tor/tormanager.go index 0adc37c..ee27fa9 100644 --- a/connectivity/tor/tormanager.go +++ b/connectivity/tor/tormanager.go @@ -28,16 +28,6 @@ func NewTorManager(socksPort int, controlPort int, torPath string, torrc string) torManager.socksPort = socksPort torManager.controlPort = controlPort - fmt.Println("NewTorManager") - go func() { - fmt.Printf("Monitor\n") - for { - time.Sleep(1 * time.Second) - resp, err := torManager.GetStatus() - fmt.Println(resp, err) - } - }() - err := torManager.TestConnection() if err == nil { @@ -152,17 +142,27 @@ func (tm *Manager) TestConnection() error { return errors.New(proxyStatusMessage(proxyStatus)) } -func (tm *Manager) GetStatus() ([]string, error) { +// GetStatus returns tor control port bootstrap-phase status info in a map +func (tm *Manager) GetStatus() (map[string]string, error) { controlAddress := fmt.Sprintf("127.0.0.1:%d", tm.controlPort) c, err := bulb.Dial("tcp4", controlAddress) if err != nil { - return []string{}, err + return nil, err } defer c.Close() c.Request("AUTHENTICATE \"\"") resp, err := c.Request("GETINFO status/bootstrap-phase") if err != nil { - return []string{}, err + return nil, err } - return resp.RawLines, nil + + lines := strings.SplitN(resp.RawLines[0], " ", 5) + var resps = make(map[string]string) + for _, l := range lines { + kv := strings.Split(l, "=") + if len(kv) == 2 { + resps[kv[0]] = kv[1] + } + } + return resps, nil }