Merge missing bugfixes... #31
|
@ -23,6 +23,26 @@ type BaseOnionService struct {
|
|||
lock sync.Mutex
|
||||
}
|
||||
|
||||
// Metrics provides a report of useful information about the status of the service e.g. the number of active
|
||||
// connections
|
||||
func (s *BaseOnionService) Metrics() tapir.ServiceMetrics {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
count := 0
|
||||
s.connections.Range(func(key, value interface{}) bool {
|
||||
connection := value.(tapir.Connection)
|
||||
if !connection.IsClosed() {
|
||||
count++
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
return tapir.ServiceMetrics{
|
||||
ConnectionCount: count,
|
||||
}
|
||||
}
|
||||
|
||||
// Init initializes a BaseOnionService with a given private key and identity
|
||||
// The private key is needed to initialize the Onion listen socket, ideally we could just pass an Identity in here.
|
||||
func (s *BaseOnionService) Init(acn connectivity.ACN, sk ed25519.PrivateKey, id *primitives.Identity) {
|
||||
|
|
|
@ -12,12 +12,18 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
// ServiceMetrics outlines higher level information about the service e.g. counts of connections
|
||||
type ServiceMetrics struct {
|
||||
ConnectionCount int
|
||||
}
|
||||
|
||||
// Service defines the interface for a Tapir Service
|
||||
type Service interface {
|
||||
Init(acn connectivity.ACN, privateKey ed25519.PrivateKey, identity *primitives.Identity)
|
||||
Connect(hostname string, application Application) (bool, error)
|
||||
Listen(application Application) error
|
||||
GetConnection(connectionID string) (Connection, error)
|
||||
Metrics() ServiceMetrics
|
||||
Broadcast(message []byte, capability Capability) error
|
||||
WaitForCapabilityOrClose(connectionID string, capability Capability) (Connection, error)
|
||||
Shutdown()
|
||||
|
|
Loading…
Reference in New Issue