Merge pull request 'store bootsrap version, make available; fix tor version parsing for double digit versions' (#33) from verStatus into master
Reviewed-on: #33
This commit is contained in:
commit
98b15bd105
|
@ -76,6 +76,7 @@ type torProvider struct {
|
||||||
isClosed bool
|
isClosed bool
|
||||||
dataDir string
|
dataDir string
|
||||||
version string
|
version string
|
||||||
|
bootProgress int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ols *onionListenService) AddressFull() string {
|
func (ols *onionListenService) AddressFull() string {
|
||||||
|
@ -205,6 +206,7 @@ func (tp *torProvider) GetBootstrapStatus() (int, string) {
|
||||||
status = statusMatches[1]
|
status = statusMatches[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tp.bootProgress = progress
|
||||||
return progress, status
|
return progress, status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,12 +300,12 @@ func (tp *torProvider) Restart() {
|
||||||
log.Debugf("launching restart...")
|
log.Debugf("launching restart...")
|
||||||
|
|
||||||
tp.lock.Lock()
|
tp.lock.Lock()
|
||||||
defer tp.lock.Unlock()
|
|
||||||
log.Debugf("checking last restart time")
|
log.Debugf("checking last restart time")
|
||||||
if time.Since(tp.lastRestartTime) < restartCooldown {
|
if time.Since(tp.lastRestartTime) < restartCooldown {
|
||||||
|
tp.lock.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
tp.lock.Unlock()
|
||||||
go tp.restart()
|
go tp.restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,6 +348,10 @@ func (tp *torProvider) Open(hostname string) (net.Conn, string, error) {
|
||||||
tp.lock.Unlock()
|
tp.lock.Unlock()
|
||||||
return nil, hostname, errors.New("tor is offline")
|
return nil, hostname, errors.New("tor is offline")
|
||||||
}
|
}
|
||||||
|
if tp.bootProgress != 100 {
|
||||||
|
tp.lock.Unlock()
|
||||||
|
return nil, hostname, fmt.Errorf("tor not online, bootstrap progress only %v", tp.bootProgress)
|
||||||
|
}
|
||||||
tp.lock.Unlock()
|
tp.lock.Unlock()
|
||||||
|
|
||||||
resolvedHostname := hostname
|
resolvedHostname := hostname
|
||||||
|
@ -353,14 +359,24 @@ func (tp *torProvider) Open(hostname string) (net.Conn, string, error) {
|
||||||
addrParts := strings.Split(hostname, ":")
|
addrParts := strings.Split(hostname, ":")
|
||||||
resolvedHostname = addrParts[1]
|
resolvedHostname = addrParts[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := tp.dialer.Dial("tcp", resolvedHostname+".onion:9878")
|
conn, err := tp.dialer.Dial("tcp", resolvedHostname+".onion:9878")
|
||||||
return conn, resolvedHostname, err
|
return conn, resolvedHostname, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *torProvider) Close() {
|
func (tp *torProvider) Close() {
|
||||||
|
closing := false
|
||||||
tp.lock.Lock()
|
tp.lock.Lock()
|
||||||
defer tp.lock.Unlock()
|
defer tp.lock.Unlock()
|
||||||
|
if !tp.isClosed {
|
||||||
|
// Break out of any background checks and close
|
||||||
|
// the underlying tor connection
|
||||||
|
tp.isClosed = true
|
||||||
|
tp.breakChan <- true
|
||||||
|
// wiggle lock to make sure if monitorRestart is waiting for the lock, it gets it, and finished that branch and gets the channel request to exit
|
||||||
|
tp.lock.Unlock()
|
||||||
|
tp.lock.Lock()
|
||||||
|
closing = true
|
||||||
|
}
|
||||||
|
|
||||||
// Unregister Child Listeners
|
// Unregister Child Listeners
|
||||||
for addr, child := range tp.childListeners {
|
for addr, child := range tp.childListeners {
|
||||||
|
@ -370,11 +386,7 @@ func (tp *torProvider) Close() {
|
||||||
|
|
||||||
log.Debugf("shutting down acn threads..(is already closed: %v)", tp.isClosed)
|
log.Debugf("shutting down acn threads..(is already closed: %v)", tp.isClosed)
|
||||||
|
|
||||||
if !tp.isClosed {
|
if closing {
|
||||||
// Break out of any background checks and close
|
|
||||||
// the underlying tor connection
|
|
||||||
tp.isClosed = true
|
|
||||||
tp.breakChan <- true
|
|
||||||
if tp.t != nil {
|
if tp.t != nil {
|
||||||
tp.t.Close()
|
tp.t.Close()
|
||||||
tp.t = nil
|
tp.t = nil
|
||||||
|
@ -465,7 +477,7 @@ func startTor(appDirectory string, bundledTorPath string, dataDir string, contro
|
||||||
|
|
||||||
os.MkdirAll(torDir, 0700)
|
os.MkdirAll(torDir, 0700)
|
||||||
|
|
||||||
tp := &torProvider{authenticator: authenticator, controlPort: controlPort, appDirectory: appDirectory, bundeledTorPath: bundledTorPath, childListeners: make(map[string]*onionListenService), breakChan: make(chan bool, 1), statusCallback: nil, versionCallback: nil, lastRestartTime: time.Now().Add(-restartCooldown)}
|
tp := &torProvider{authenticator: authenticator, controlPort: controlPort, appDirectory: appDirectory, bundeledTorPath: bundledTorPath, childListeners: make(map[string]*onionListenService), breakChan: make(chan bool, 1), statusCallback: nil, versionCallback: nil, lastRestartTime: time.Now().Add(-restartCooldown), bootProgress: -1}
|
||||||
|
|
||||||
log.Debugf("checking if there is a running system tor")
|
log.Debugf("checking if there is a running system tor")
|
||||||
if version, err := tp.checkVersion(); err == nil {
|
if version, err := tp.checkVersion(); err == nil {
|
||||||
|
@ -542,7 +554,6 @@ func (tp *torProvider) monitorRestart() {
|
||||||
prog, status := tp.GetBootstrapStatus()
|
prog, status := tp.GetBootstrapStatus()
|
||||||
|
|
||||||
if prog == torDown && tp.t != nil {
|
if prog == torDown && tp.t != nil {
|
||||||
log.Warnf("monitorRestart calling tp.restart() with prog:%v\n", prog)
|
|
||||||
tp.restart()
|
tp.restart()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -618,7 +629,7 @@ func checkCmdlineTorVersion(torCmd string) (string, bool) {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
re := regexp.MustCompile(`[0-1]\.[0-9]\.[0-9]\.[0-9]`)
|
re := regexp.MustCompile(`[0-1]+\.[0-9]+\.[0-9]+\.[0-9]+`)
|
||||||
sysTorVersion := re.Find(outb.Bytes())
|
sysTorVersion := re.Find(outb.Bytes())
|
||||||
log.Infof("tor version: %v", string(sysTorVersion))
|
log.Infof("tor version: %v", string(sysTorVersion))
|
||||||
return string(sysTorVersion), minTorVersionReqs(string(sysTorVersion))
|
return string(sysTorVersion), minTorVersionReqs(string(sysTorVersion))
|
||||||
|
|
Loading…
Reference in New Issue