Merge missing bugfixes... #31

Merged
dan merged 4 commits from bugfix into master 2021-04-09 21:44:59 +00:00
2 changed files with 11 additions and 2 deletions
Showing only changes of commit 9fba459adc - Show all commits

View File

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

0
scratch/main.go Normal file
View File