Adding Shutdown()
This commit is contained in:
parent
17871cade7
commit
334f728073
|
@ -19,6 +19,7 @@ type BaseOnionService struct {
|
||||||
acn connectivity.ACN
|
acn connectivity.ACN
|
||||||
id identity.Identity
|
id identity.Identity
|
||||||
privateKey ed25519.PrivateKey
|
privateKey ed25519.PrivateKey
|
||||||
|
ls connectivity.ListenService
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes a BaseOnionService with a given private key and identity
|
// 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
|
// accepts a new connection
|
||||||
// spins off to a connection struct
|
// spins off to a connection struct
|
||||||
ls, err := s.acn.Listen(s.privateKey, 9878)
|
ls, err := s.acn.Listen(s.privateKey, 9878)
|
||||||
|
s.ls = ls
|
||||||
log.Debugf("Starting a service on %v ", ls.AddressFull())
|
log.Debugf("Starting a service on %v ", ls.AddressFull())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for {
|
for {
|
||||||
conn, err := ls.Accept()
|
conn, err := s.ls.Accept()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tempHostname := s.getNewConnectionID()
|
tempHostname := s.getNewConnectionID()
|
||||||
log.Debugf("Accepted connection from %v", tempHostname)
|
log.Debugf("Accepted connection from %v", tempHostname)
|
||||||
s.connections.Store(tempHostname, tapir.NewConnection(s.id, tempHostname, false, conn, app.NewInstance()))
|
s.connections.Store(tempHostname, tapir.NewConnection(s.id, tempHostname, false, conn, app.NewInstance()))
|
||||||
} else {
|
} else {
|
||||||
ls.Close()
|
|
||||||
log.Debugf("Error accepting connection %v", err)
|
log.Debugf("Error accepting connection %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -134,3 +135,7 @@ func (s *BaseOnionService) Listen(app tapir.Application) error {
|
||||||
log.Debugf("Error listening to connection %v", err)
|
log.Debugf("Error listening to connection %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *BaseOnionService) Shutdown() {
|
||||||
|
s.ls.Close()
|
||||||
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ type Service interface {
|
||||||
Listen(application Application) error
|
Listen(application Application) error
|
||||||
GetConnection(connectionID string) (*Connection, error)
|
GetConnection(connectionID string) (*Connection, error)
|
||||||
WaitForCapabilityOrClose(connectionID string, capability string) (*Connection, error)
|
WaitForCapabilityOrClose(connectionID string, capability string) (*Connection, error)
|
||||||
|
Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connection defines a Tapir Connection
|
// Connection defines a Tapir Connection
|
||||||
|
|
Loading…
Reference in New Issue