Add Lock to ReplaceACN. Minor Drone fixups
This commit is contained in:
parent
13045e3d98
commit
5d4cf85d26
|
@ -14,7 +14,6 @@ pipeline:
|
|||
- wget https://git.openprivacy.ca/openprivacy/buildfiles/raw/master/tor/tor -P tmp/
|
||||
- chmod a+x tmp/tor
|
||||
- go mod download
|
||||
- go get -u
|
||||
quality:
|
||||
when:
|
||||
repo: openprivacy/connectivity
|
||||
|
|
|
@ -4,5 +4,4 @@ tor/tor/
|
|||
vendor/
|
||||
*.cover.out
|
||||
tmp/
|
||||
testing/tor/torrc
|
||||
testing/tor/*
|
|
@ -2,6 +2,7 @@ package connectivity
|
|||
|
||||
import (
|
||||
"net"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ProxyACN because there is rarely a problem that can't be solved by another layer of indirection.
|
||||
|
@ -11,6 +12,10 @@ import (
|
|||
// ProxyACN - a wrapper around an ACN that allows safe replacement of a running ACN that is transparent to callers.
|
||||
type ProxyACN struct {
|
||||
acn ACN
|
||||
|
||||
// All operations on the underlying acn are assumed to be thread safe, however changing the actual
|
||||
// acn in ReplaceACN will lock to force an ordering of Close and Callback
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func NewProxyACN(acn ACN) ProxyACN {
|
||||
|
@ -21,6 +26,8 @@ func NewProxyACN(acn ACN) ProxyACN {
|
|||
|
||||
// ReplaceACN closes down the current ACN and replaces it with a new ACN.
|
||||
func (p *ProxyACN) ReplaceACN(acn ACN) {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
p.acn.Close()
|
||||
acn.SetStatusCallback(p.acn.Callback())
|
||||
p.acn = acn
|
||||
|
|
Loading…
Reference in New Issue