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