From 5c5eb2c339f15283094576cba0f8b1083b451c82 Mon Sep 17 00:00:00 2001 From: Cecylia Bocovich Date: Mon, 30 Oct 2023 12:37:56 -0400 Subject: [PATCH] Modify EventOnProxyStats to include summary data --- common/event/interface.go | 10 ++++++++-- proxy/lib/pt_event_logger.go | 13 +++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/common/event/interface.go b/common/event/interface.go index d54e9d3..c01b462 100644 --- a/common/event/interface.go +++ b/common/event/interface.go @@ -2,6 +2,7 @@ package event import ( "fmt" + "time" "github.com/pion/webrtc/v3" "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/safelog" @@ -78,11 +79,16 @@ func (e EventOnProxyConnectionOver) String() string { type EventOnProxyStats struct { SnowflakeEvent - StatString string + ConnectionCount int + InboundBytes, OutboundBytes int64 + InboundUnit, OutboundUnit string + SummaryInterval time.Duration } func (e EventOnProxyStats) String() string { - return e.StatString + statString := fmt.Sprintf("In the last %v, there were %v completed connections. Traffic Relayed ↓ %v %v, ↑ %v %v.", + e.SummaryInterval.String(), e.ConnectionCount, e.InboundBytes, e.InboundUnit, e.OutboundBytes, e.OutboundUnit) + return statString } type EventOnCurrentNATTypeDetermined struct { diff --git a/proxy/lib/pt_event_logger.go b/proxy/lib/pt_event_logger.go index 83ee62e..3d9a770 100644 --- a/proxy/lib/pt_event_logger.go +++ b/proxy/lib/pt_event_logger.go @@ -1,7 +1,6 @@ package snowflake_proxy import ( - "fmt" "io" "log" "time" @@ -47,11 +46,13 @@ func (p *periodicProxyStats) OnNewSnowflakeEvent(e event.SnowflakeEvent) { func (p *periodicProxyStats) logTick() error { inboundSum, outboundSum := p.bytesLogger.GetStat() - inbound, inboundUnit := formatTraffic(inboundSum) - outbound, outboundUnit := formatTraffic(outboundSum) - statString := fmt.Sprintf("In the last %v, there were %v completed connections. Traffic Relayed ↓ %v %v, ↑ %v %v.", - p.logPeriod.String(), p.connectionCount, inbound, inboundUnit, outbound, outboundUnit) - p.dispatcher.OnNewSnowflakeEvent(&event.EventOnProxyStats{StatString: statString}) + e := &event.EventOnProxyStats{ + SummaryInterval: p.logPeriod, + ConnectionCount: p.connectionCount, + } + e.InboundBytes, e.InboundUnit = formatTraffic(inboundSum) + e.OutboundBytes, e.OutboundUnit = formatTraffic(outboundSum) + p.dispatcher.OnNewSnowflakeEvent(e) p.connectionCount = 0 return nil }