Proxy stats log only what occurred that time interval

Modify the periodic stats output by standalone snowflake proxies to only
include the data transferred during the time interval being logged. This
is an improvement of previous behaviour that logged the total data
transferred by all proxy connections that were closed within the time
interval being logged..

Closes #40302:
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/issues/40302
This commit is contained in:
Cecylia Bocovich 2023-10-28 16:45:22 -04:00
parent 354cb65432
commit 018bbd6d65
No known key found for this signature in database
GPG key ID: 009DE379FD9B7B90
3 changed files with 16 additions and 28 deletions

View file

@ -416,7 +416,7 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
close(dataChan)
pr, pw := io.Pipe()
conn := newWebRTCConn(pc, dc, pr, sf.EventDispatcher)
conn := newWebRTCConn(pc, dc, pr, sf.bytesLogger)
dc.SetBufferedAmountLowThreshold(bufferedAmountLowThreshold)
@ -446,11 +446,7 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
conn.lock.Lock()
defer conn.lock.Unlock()
log.Printf("Data Channel %s-%d close\n", dc.Label(), dc.ID())
in, out := conn.bytesLogger.GetStat()
conn.eventLogger.OnNewSnowflakeEvent(event.EventOnProxyConnectionOver{
InboundTraffic: in,
OutboundTraffic: out,
})
sf.EventDispatcher.OnNewSnowflakeEvent(event.EventOnProxyConnectionOver{})
conn.dc = nil
dc.Close()
pw.Close()
@ -663,7 +659,8 @@ func (sf *SnowflakeProxy) Start() error {
}
if !sf.DisableStatsLogger {
sf.periodicProxyStats = newPeriodicProxyStats(sf.SummaryInterval, sf.EventDispatcher)
sf.bytesLogger = newBytesSyncLogger()
sf.periodicProxyStats = newPeriodicProxyStats(sf.SummaryInterval, sf.EventDispatcher, sf.bytesLogger)
}
broker, err = newSignalingServer(sf.BrokerURL, sf.KeepLocalAddresses)