Add Lock to ReplaceACN. Minor Drone fixups
continuous-integration/drone/push Build is pending Details
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Sarah Jamie Lewis 2022-01-11 15:17:54 -08:00
parent 13045e3d98
commit 5d4cf85d26
3 changed files with 7 additions and 2 deletions

View File

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

1
.gitignore vendored
View File

@ -4,5 +4,4 @@ tor/tor/
vendor/
*.cover.out
tmp/
testing/tor/torrc
testing/tor/*

View File

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