mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Modify EventOnProxyStats to include summary data
This commit is contained in:
parent
018bbd6d65
commit
5c5eb2c339
2 changed files with 15 additions and 8 deletions
|
@ -2,6 +2,7 @@ package event
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/safelog"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/safelog"
|
||||||
|
@ -78,11 +79,16 @@ func (e EventOnProxyConnectionOver) String() string {
|
||||||
|
|
||||||
type EventOnProxyStats struct {
|
type EventOnProxyStats struct {
|
||||||
SnowflakeEvent
|
SnowflakeEvent
|
||||||
StatString string
|
ConnectionCount int
|
||||||
|
InboundBytes, OutboundBytes int64
|
||||||
|
InboundUnit, OutboundUnit string
|
||||||
|
SummaryInterval time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EventOnProxyStats) String() string {
|
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 {
|
type EventOnCurrentNATTypeDetermined struct {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package snowflake_proxy
|
package snowflake_proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
@ -47,11 +46,13 @@ func (p *periodicProxyStats) OnNewSnowflakeEvent(e event.SnowflakeEvent) {
|
||||||
|
|
||||||
func (p *periodicProxyStats) logTick() error {
|
func (p *periodicProxyStats) logTick() error {
|
||||||
inboundSum, outboundSum := p.bytesLogger.GetStat()
|
inboundSum, outboundSum := p.bytesLogger.GetStat()
|
||||||
inbound, inboundUnit := formatTraffic(inboundSum)
|
e := &event.EventOnProxyStats{
|
||||||
outbound, outboundUnit := formatTraffic(outboundSum)
|
SummaryInterval: p.logPeriod,
|
||||||
statString := fmt.Sprintf("In the last %v, there were %v completed connections. Traffic Relayed ↓ %v %v, ↑ %v %v.",
|
ConnectionCount: p.connectionCount,
|
||||||
p.logPeriod.String(), p.connectionCount, inbound, inboundUnit, outbound, outboundUnit)
|
}
|
||||||
p.dispatcher.OnNewSnowflakeEvent(&event.EventOnProxyStats{StatString: statString})
|
e.InboundBytes, e.InboundUnit = formatTraffic(inboundSum)
|
||||||
|
e.OutboundBytes, e.OutboundUnit = formatTraffic(outboundSum)
|
||||||
|
p.dispatcher.OnNewSnowflakeEvent(e)
|
||||||
p.connectionCount = 0
|
p.connectionCount = 0
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue