Browse Source

Merge pull request 'Add Metrics (Fix: #21)' (#24) from metrics into master

Reviewed-on: https://git.openprivacy.ca/cwtch.im/tapir/pulls/24
pull/26/head
Dan Ballard 2 years ago
parent
commit
fa216a30d7
  1. 20
      networks/tor/BaseOnionService.go
  2. 6
      service.go

20
networks/tor/BaseOnionService.go

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

6
service.go

@ -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…
Cancel
Save