diff --git a/networks/tor/BaseOnionService.go b/networks/tor/BaseOnionService.go index ca27249..7f262cd 100644 --- a/networks/tor/BaseOnionService.go +++ b/networks/tor/BaseOnionService.go @@ -20,6 +20,7 @@ type BaseOnionService struct { id *primitives.Identity privateKey ed25519.PrivateKey ls connectivity.ListenService + lock sync.Mutex } // Init initializes a BaseOnionService with a given private key and identity @@ -116,9 +117,12 @@ func (s *BaseOnionService) getNewConnectionID() string { func (s *BaseOnionService) Listen(app tapir.Application) error { // accepts a new connection // spins off to a connection struct + s.lock.Lock() ls, err := s.acn.Listen(s.privateKey, 9878) s.ls = ls log.Debugf("Starting a service on %v ", ls.AddressFull()) + s.lock.Unlock() + if err == nil { for { conn, err := s.ls.Accept() @@ -138,6 +142,8 @@ func (s *BaseOnionService) Listen(app tapir.Application) error { // Shutdown closes the service and ensures that any connections are closed. func (s *BaseOnionService) Shutdown() { + s.lock.Lock() + defer s.lock.Unlock() s.ls.Close() s.connections.Range(func(key, value interface{}) bool { connection := value.(tapir.Connection) diff --git a/testing/tests.sh b/testing/tests.sh index cbb303d..6c1234d 100755 --- a/testing/tests.sh +++ b/testing/tests.sh @@ -4,12 +4,18 @@ set -e pwd go test -race ${1} -coverprofile=applications.cover.out -v ./applications go test -race ${1} -coverprofile=applications.tokenboard.cover.out -v ./applications/tokenboard -go test -race ${1} -coverprofile=persistence.cover.out -v ./persistence +# persistence is broken in WSL +if grep -q -v Microsoft /proc/version; then + go test -race ${1} -coverprofile=persistence.cover.out -v ./persistence +fi go test -race ${1} -coverprofile=primitives.cover.out -v ./primitives go test -race ${1} -coverprofile=primitives.auditable.cover.out -v ./primitives/auditable go test -race ${1} -coverprofile=primitives.core.cover.out -v ./primitives/core -go test -race ${1} -coverprofile=primitives.privacypass.cover.out -v ./primitives/privacypass -go test -bench "BenchmarkAuditableStore" -benchtime 1000x primitives/auditable/*.go +# persistence is broken in WSL +if grep -q -v Microsoft /proc/version; then + go test -race ${1} -coverprofile=primitives.privacypass.cover.out -v ./primitives/privacypass + go test -bench "BenchmarkAuditableStore" -benchtime 1000x primitives/auditable/*.go +fi echo "mode: set" > coverage.out && cat *.cover.out | grep -v mode: | sort -r | \ awk '{if($1 != last) {print $0;last=$1}}' >> coverage.out rm -rf *.cover.out