aboutsummaryrefslogtreecommitdiff
path: root/proxy
diff options
context:
space:
mode:
authorluciole <luciole@systemli.org>2022-11-17 14:30:16 +0100
committerCecylia Bocovich <cohosh@torproject.org>2022-11-21 10:33:21 -0500
commit2c599f88274b37f743996ed9f4ff0744b84c119d (patch)
tree9257cd19979d08e37c260ad229d6c7d72b56ef92 /proxy
parent115ba6a745b877904f5f4b6a4c852c3f2d5a87b8 (diff)
downloadsnowflake-2c599f88274b37f743996ed9f4ff0744b84c119d.tar.gz
snowflake-2c599f88274b37f743996ed9f4ff0744b84c119d.zip
change bandwidth type from int to int64 to prevent overflow
Diffstat (limited to 'proxy')
-rw-r--r--proxy/lib/pt_event_logger.go4
-rw-r--r--proxy/lib/snowflake.go2
-rw-r--r--proxy/lib/util.go31
-rw-r--r--proxy/lib/webrtcconn.go2
4 files changed, 20 insertions, 19 deletions
diff --git a/proxy/lib/pt_event_logger.go b/proxy/lib/pt_event_logger.go
index b16f5ba..ce89545 100644
--- a/proxy/lib/pt_event_logger.go
+++ b/proxy/lib/pt_event_logger.go
@@ -18,8 +18,8 @@ func NewProxyEventLogger(logPeriod time.Duration, output io.Writer) event.Snowfl
}
type logEventLogger struct {
- inboundSum int
- outboundSum int
+ inboundSum int64
+ outboundSum int64
connectionCount int
logPeriod time.Duration
task *task.Periodic
diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go
index b4ca5c3..ac88f0c 100644
--- a/proxy/lib/snowflake.go
+++ b/proxy/lib/snowflake.go
@@ -412,7 +412,7 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
log.Printf("close with error generated an error: %v", inerr)
}
}
- conn.bytesLogger.AddOutbound(n)
+ conn.bytesLogger.AddOutbound(int64(n))
if n != len(msg.Data) {
panic("short write")
}
diff --git a/proxy/lib/util.go b/proxy/lib/util.go
index c444bb0..0bbe588 100644
--- a/proxy/lib/util.go
+++ b/proxy/lib/util.go
@@ -8,39 +8,40 @@ import (
// bytesLogger is an interface which is used to allow logging the throughput
// of the Snowflake. A default bytesLogger(bytesNullLogger) does nothing.
type bytesLogger interface {
- AddOutbound(int)
- AddInbound(int)
+ AddOutbound(int64)
+ AddInbound(int64)
ThroughputSummary() string
- GetStat() (in int, out int)
+ GetStat() (in int64, out int64)
}
// bytesNullLogger Default bytesLogger does nothing.
type bytesNullLogger struct{}
// AddOutbound in bytesNullLogger does nothing
-func (b bytesNullLogger) AddOutbound(amount int) {}
+func (b bytesNullLogger) AddOutbound(amount int64) {}
// AddInbound in bytesNullLogger does nothing
-func (b bytesNullLogger) AddInbound(amount int) {}
+func (b bytesNullLogger) AddInbound(amount int64) {}
// ThroughputSummary in bytesNullLogger does nothing
func (b bytesNullLogger) ThroughputSummary() string { return "" }
-func (b bytesNullLogger) GetStat() (in int, out int) { return -1, -1 }
+func (b bytesNullLogger) GetStat() (in int64, out int64) { return -1, -1 }
// bytesSyncLogger uses channels to safely log from multiple sources with output
// occuring at reasonable intervals.
type bytesSyncLogger struct {
- outboundChan, inboundChan chan int
- outbound, inbound, outEvents, inEvents int
- start time.Time
+ outboundChan, inboundChan chan int64
+ outbound, inbound int64
+ outEvents, inEvents int
+ start time.Time
}
// newBytesSyncLogger returns a new bytesSyncLogger and starts it loggin.
func newBytesSyncLogger() *bytesSyncLogger {
b := &bytesSyncLogger{
- outboundChan: make(chan int, 5),
- inboundChan: make(chan int, 5),
+ outboundChan: make(chan int64, 5),
+ inboundChan: make(chan int64, 5),
}
go b.log()
b.start = time.Now()
@@ -61,12 +62,12 @@ func (b *bytesSyncLogger) log() {
}
// AddOutbound add a number of bytes to the outbound total reported by the logger
-func (b *bytesSyncLogger) AddOutbound(amount int) {
+func (b *bytesSyncLogger) AddOutbound(amount int64) {
b.outboundChan <- amount
}
// AddInbound add a number of bytes to the inbound total reported by the logger
-func (b *bytesSyncLogger) AddInbound(amount int) {
+func (b *bytesSyncLogger) AddInbound(amount int64) {
b.inboundChan <- amount
}
@@ -82,6 +83,6 @@ func (b *bytesSyncLogger) ThroughputSummary() string {
return fmt.Sprintf("Traffic throughput (up|down): %d %s|%d %s -- (%d OnMessages, %d Sends, over %d seconds)", inbound, inUnit, outbound, outUnit, b.outEvents, b.inEvents, int(t.Sub(b.start).Seconds()))
}
-func (b *bytesSyncLogger) GetStat() (in int, out int) { return b.inbound, b.outbound }
+func (b *bytesSyncLogger) GetStat() (in int64, out int64) { return b.inbound, b.outbound }
-func formatTraffic(amount int) (value int, unit string) { return amount / 1000, "KB" }
+func formatTraffic(amount int64) (value int64, unit string) { return amount / 1000, "KB" }
diff --git a/proxy/lib/webrtcconn.go b/proxy/lib/webrtcconn.go
index 919a679..49f98d8 100644
--- a/proxy/lib/webrtcconn.go
+++ b/proxy/lib/webrtcconn.go
@@ -39,7 +39,7 @@ func (c *webRTCConn) Read(b []byte) (int, error) {
}
func (c *webRTCConn) Write(b []byte) (int, error) {
- c.bytesLogger.AddInbound(len(b))
+ c.bytesLogger.AddInbound(int64(len(b)))
c.lock.Lock()
defer c.lock.Unlock()
if c.dc != nil {