Get x Callbacks #32
7
acn.go
7
acn.go
|
@ -38,9 +38,14 @@ type ACN interface {
|
||||||
WaitTillBootstrapped() error
|
WaitTillBootstrapped() error
|
||||||
// Sets the callback function to be called when ACN status changes
|
// Sets the callback function to be called when ACN status changes
|
||||||
SetStatusCallback(callback func(int, string))
|
SetStatusCallback(callback func(int, string))
|
||||||
|
|
||||||
|
GetStatusCallback() func(int, string)
|
||||||
|
|
||||||
// Sets the callback function to be called when ACN reboots to emit the version
|
// Sets the callback function to be called when ACN reboots to emit the version
|
||||||
SetVersionCallback(callback func(string))
|
SetVersionCallback(callback func(string))
|
||||||
|
|
||||||
|
GetVersionCallback() func(string)
|
||||||
|
|
||||||
// Restarts the underlying connection
|
// Restarts the underlying connection
|
||||||
Restart()
|
Restart()
|
||||||
|
|
||||||
|
@ -57,8 +62,6 @@ type ACN interface {
|
||||||
// GetVersion returns a string of what the ACN returns when asked for a version
|
// GetVersion returns a string of what the ACN returns when asked for a version
|
||||||
GetVersion() string
|
GetVersion() string
|
||||||
|
|
||||||
Callback() func(int, string)
|
|
||||||
|
|
||||||
GetInfo(onion string) (map[string]string, error)
|
GetInfo(onion string) (map[string]string, error)
|
||||||
|
|
||||||
Close()
|
Close()
|
||||||
|
|
|
@ -15,10 +15,14 @@ type ErrorACN struct {
|
||||||
versionCallbackCache func(string)
|
versionCallbackCache func(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrorACN) Callback() func(int, string) {
|
func (e ErrorACN) GetStatusCallback() func(int, string) {
|
||||||
return e.statusCallbackCache
|
return e.statusCallbackCache
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e ErrorACN) GetVersionCallback() func(string) {
|
||||||
|
return e.versionCallbackCache
|
||||||
|
}
|
||||||
|
|
||||||
func (e *ErrorACN) GetInfo(addr string) (map[string]string, error) {
|
func (e *ErrorACN) GetInfo(addr string) (map[string]string, error) {
|
||||||
return nil, errors.New(acnError)
|
return nil, errors.New(acnError)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,14 @@ func NewLocalACN() ACN {
|
||||||
return &localProvider{}
|
return &localProvider{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (lp *localProvider) Callback() func(int, string) {
|
func (lp *localProvider) GetStatusCallback() func(int, string) {
|
||||||
return func(int, string) {}
|
return func(int, string) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (lp *localProvider) GetVersionCallback() func(string) {
|
||||||
|
return func(string) {}
|
||||||
|
}
|
||||||
|
|
||||||
func (ls *localListenService) AddressFull() string {
|
func (ls *localListenService) AddressFull() string {
|
||||||
return ls.l.Addr().String()
|
return ls.l.Addr().String()
|
||||||
}
|
}
|
||||||
|
|
11
proxy_acn.go
11
proxy_acn.go
|
@ -29,7 +29,8 @@ func (p *ProxyACN) ReplaceACN(acn ACN) {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
p.acn.Close()
|
p.acn.Close()
|
||||||
acn.SetStatusCallback(p.acn.Callback())
|
acn.SetStatusCallback(p.acn.GetStatusCallback())
|
||||||
|
acn.SetVersionCallback(p.acn.GetVersionCallback())
|
||||||
p.acn = acn
|
p.acn = acn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +78,10 @@ func (p *ProxyACN) Close() {
|
||||||
p.acn.Close()
|
p.acn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProxyACN) Callback() func(int, string) {
|
func (p *ProxyACN) GetStatusCallback() func(int, string) {
|
||||||
return p.acn.Callback()
|
return p.acn.GetStatusCallback()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProxyACN) GetVersionCallback() func(string) {
|
||||||
|
return p.acn.GetVersionCallback()
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,12 +394,18 @@ func (tp *torProvider) SetVersionCallback(callback func(string)) {
|
||||||
tp.versionCallback = callback
|
tp.versionCallback = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tp *torProvider) Callback() func(int, string) {
|
func (tp *torProvider) GetStatusCallback() func(int, string) {
|
||||||
tp.lock.Lock()
|
tp.lock.Lock()
|
||||||
defer tp.lock.Unlock()
|
defer tp.lock.Unlock()
|
||||||
return tp.statusCallback
|
return tp.statusCallback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tp *torProvider) GetVersionCallback() func(string) {
|
||||||
|
tp.lock.Lock()
|
||||||
|
defer tp.lock.Unlock()
|
||||||
|
return tp.versionCallback
|
||||||
|
}
|
||||||
|
|
||||||
func (tp *torProvider) callStatusCallback(prog int, status string) {
|
func (tp *torProvider) callStatusCallback(prog int, status string) {
|
||||||
tp.lock.Lock()
|
tp.lock.Lock()
|
||||||
defer tp.lock.Unlock()
|
defer tp.lock.Unlock()
|
||||||
|
|
|
@ -103,7 +103,7 @@ func TestTorProvider(t *testing.T) {
|
||||||
|
|
||||||
acn.Close()
|
acn.Close()
|
||||||
|
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 10)
|
||||||
|
|
||||||
goRoutineEnd := runtime.NumGoroutine()
|
goRoutineEnd := runtime.NumGoroutine()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue