diff --git a/networks/tor/BaseOnionService.go b/networks/tor/BaseOnionService.go index feaf56a..43667dc 100644 --- a/networks/tor/BaseOnionService.go +++ b/networks/tor/BaseOnionService.go @@ -21,6 +21,7 @@ type BaseOnionService struct { privateKey ed25519.PrivateKey ls connectivity.ListenService lock sync.Mutex + port int } // Metrics provides a report of useful information about the status of the service e.g. the number of active @@ -51,6 +52,12 @@ func (s *BaseOnionService) Init(acn connectivity.ACN, sk ed25519.PrivateKey, id s.acn = acn s.id = id s.privateKey = sk + s.port = 9878 +} + +// SetPort configures the port that the service uses. +func (s *BaseOnionService) SetPort(port int) { + s.port = port } // WaitForCapabilityOrClose blocks until the connection has the given capability or the underlying connection is closed @@ -146,7 +153,7 @@ 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) + ls, err := s.acn.Listen(s.privateKey, s.port) s.ls = ls log.Debugf("Starting a service on %v ", ls.AddressFull()) s.lock.Unlock() @@ -172,7 +179,9 @@ func (s *BaseOnionService) Listen(app tapir.Application) error { func (s *BaseOnionService) Shutdown() { s.lock.Lock() defer s.lock.Unlock() - s.ls.Close() + if s.ls != nil { + s.ls.Close() + } s.connections.Range(func(key, value interface{}) bool { connection := value.(tapir.Connection) connection.Close() diff --git a/scratch/main.go b/scratch/main.go new file mode 100644 index 0000000..e69de29