diff --git a/networks/tor/BaseOnionService.go b/networks/tor/BaseOnionService.go index d8c6cc4..c408571 100644 --- a/networks/tor/BaseOnionService.go +++ b/networks/tor/BaseOnionService.go @@ -19,6 +19,7 @@ type BaseOnionService struct { acn connectivity.ACN id identity.Identity privateKey ed25519.PrivateKey + ls connectivity.ListenService } // Init initializes a BaseOnionService with a given private key and identity @@ -116,16 +117,16 @@ func (s *BaseOnionService) Listen(app tapir.Application) error { // accepts a new connection // spins off to a connection struct ls, err := s.acn.Listen(s.privateKey, 9878) + s.ls = ls log.Debugf("Starting a service on %v ", ls.AddressFull()) if err == nil { for { - conn, err := ls.Accept() + conn, err := s.ls.Accept() if err == nil { tempHostname := s.getNewConnectionID() log.Debugf("Accepted connection from %v", tempHostname) s.connections.Store(tempHostname, tapir.NewConnection(s.id, tempHostname, false, conn, app.NewInstance())) } else { - ls.Close() log.Debugf("Error accepting connection %v", err) return err } @@ -134,3 +135,7 @@ func (s *BaseOnionService) Listen(app tapir.Application) error { log.Debugf("Error listening to connection %v", err) return err } + +func (s *BaseOnionService) Shutdown() { + s.ls.Close() +} diff --git a/service.go b/service.go index 112f3f9..3443f0a 100644 --- a/service.go +++ b/service.go @@ -20,6 +20,7 @@ type Service interface { Listen(application Application) error GetConnection(connectionID string) (*Connection, error) WaitForCapabilityOrClose(connectionID string, capability string) (*Connection, error) + Shutdown() } // Connection defines a Tapir Connection