WaitTillBootstrapped can now Error
This commit is contained in:
parent
5d4cf85d26
commit
384d59e9ef
2
acn.go
2
acn.go
|
@ -38,7 +38,7 @@ type ACN interface {
|
|||
// On ACN error state it returns -2
|
||||
GetBootstrapStatus() (int, string)
|
||||
// WaitTillBootstrapped Blocks until underlying network is bootstrapped
|
||||
WaitTillBootstrapped()
|
||||
WaitTillBootstrapped() error
|
||||
// Sets the callback function to be called when ACN status changes
|
||||
SetStatusCallback(callback func(int, string))
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package connectivity
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
@ -19,7 +20,8 @@ func (e ErrorACN) GetBootstrapStatus() (int, string) {
|
|||
return -1, "error initializing tor"
|
||||
}
|
||||
|
||||
func (e ErrorACN) WaitTillBootstrapped() {
|
||||
func (e ErrorACN) WaitTillBootstrapped() error {
|
||||
return errors.New("error initializing tor")
|
||||
}
|
||||
|
||||
func (e *ErrorACN) SetStatusCallback(callback func(int, string)) {
|
||||
|
|
|
@ -56,7 +56,8 @@ func (lp *localProvider) GetVersion() string {
|
|||
}
|
||||
|
||||
// WaitTillBootstrapped Blocks until underlying network is bootstrapped
|
||||
func (lp *localProvider) WaitTillBootstrapped() {
|
||||
func (lp *localProvider) WaitTillBootstrapped() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lp *localProvider) Listen(identity PrivateKey, port int) (ListenService, error) {
|
||||
|
|
|
@ -37,8 +37,8 @@ func (p *ProxyACN) GetBootstrapStatus() (int, string) {
|
|||
return p.acn.GetBootstrapStatus()
|
||||
}
|
||||
|
||||
func (p *ProxyACN) WaitTillBootstrapped() {
|
||||
p.acn.WaitTillBootstrapped()
|
||||
func (p *ProxyACN) WaitTillBootstrapped() error {
|
||||
return p.acn.WaitTillBootstrapped()
|
||||
}
|
||||
|
||||
func (p *ProxyACN) SetStatusCallback(callback func(int, string)) {
|
||||
|
|
|
@ -32,7 +32,11 @@ func TestLaunchTor(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatalf("tor failed to start: %v", err)
|
||||
} else {
|
||||
acn.WaitTillBootstrapped()
|
||||
err := acn.WaitTillBootstrapped()
|
||||
if err != nil {
|
||||
t.Fatalf("error bootstrapping tor %v", err)
|
||||
}
|
||||
|
||||
if pid, err := acn.GetPID(); err == nil {
|
||||
t.Logf("tor pid: %v", pid)
|
||||
} else {
|
||||
|
|
|
@ -72,6 +72,7 @@ type torProvider struct {
|
|||
statusCallback func(int, string)
|
||||
lastRestartTime time.Time
|
||||
authenticator tor.Authenticator
|
||||
isClosed bool
|
||||
}
|
||||
|
||||
func (ols *onionListenService) AddressFull() string {
|
||||
|
@ -157,14 +158,15 @@ func (tp *torProvider) GetVersion() string {
|
|||
}
|
||||
|
||||
// WaitTillBootstrapped Blocks until underlying network is bootstrapped
|
||||
func (tp *torProvider) WaitTillBootstrapped() {
|
||||
for {
|
||||
func (tp *torProvider) WaitTillBootstrapped() error {
|
||||
for !tp.isClosed {
|
||||
progress, _ := tp.GetBootstrapStatus()
|
||||
if progress == 100 {
|
||||
break
|
||||
return nil
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
return errors.New("close called before bootstrap")
|
||||
}
|
||||
|
||||
func (tp *torProvider) Listen(identity connectivity.PrivateKey, port int) (connectivity.ListenService, error) {
|
||||
|
@ -287,9 +289,9 @@ func (tp *torProvider) Close() {
|
|||
for _, child := range tp.childListeners {
|
||||
child.Close()
|
||||
}
|
||||
|
||||
tp.lock.Lock()
|
||||
defer tp.lock.Unlock()
|
||||
tp.isClosed = true
|
||||
tp.breakChan <- true
|
||||
if tp.t != nil {
|
||||
tp.t.Close()
|
||||
|
|
Loading…
Reference in New Issue