pt_event_metrics.go 761 B

12345678910111213141516171819202122232425262728293031
  1. package snowflake_proxy
  2. import (
  3. "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
  4. )
  5. type EventCollector interface {
  6. TrackInBoundTraffic(value int64)
  7. TrackOutBoundTraffic(value int64)
  8. TrackNewConnection()
  9. }
  10. type EventMetrics struct {
  11. collector EventCollector
  12. }
  13. func NewEventMetrics(collector EventCollector) *EventMetrics {
  14. return &EventMetrics{collector: collector}
  15. }
  16. func (em *EventMetrics) OnNewSnowflakeEvent(e event.SnowflakeEvent) {
  17. switch e.(type) {
  18. case event.EventOnProxyStats:
  19. e := e.(event.EventOnProxyStats)
  20. em.collector.TrackInBoundTraffic(e.InboundBytes)
  21. em.collector.TrackOutBoundTraffic(e.OutboundBytes)
  22. case event.EventOnProxyConnectionOver:
  23. em.collector.TrackNewConnection()
  24. }
  25. }