Browse Source

Merge branch 'tor-status' of dan/cwtch into master

detports
Sarah Jamie Lewis 1 year ago
parent
commit
007c72c43c
2 changed files with 32 additions and 0 deletions
  1. 7
    0
      app/app.go
  2. 25
    0
      connectivity/tor/tormanager.go

+ 7
- 0
app/app.go View File

@@ -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 {

+ 25
- 0
connectivity/tor/tormanager.go View File

@@ -141,3 +141,28 @@ func (tm *Manager) TestConnection() error {
}
return errors.New(proxyStatusMessage(proxyStatus))
}

// 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 nil, err
}
defer c.Close()
c.Request("AUTHENTICATE \"\"")
resp, err := c.Request("GETINFO status/bootstrap-phase")
if err != nil {
return nil, err
}

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
}

Loading…
Cancel
Save