Adding Shutdown()

This commit is contained in:
Sarah Jamie Lewis 2019-07-17 11:44:08 -07:00
parent 17871cade7
commit 334f728073
2 changed files with 8 additions and 2 deletions

View File

@ -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()
}

View File

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