mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
change bandwidth type from int to int64 to prevent overflow
This commit is contained in:
parent
115ba6a745
commit
2c599f8827
7 changed files with 36 additions and 34 deletions
|
@ -10,35 +10,36 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type bytesLogger interface {
|
type bytesLogger interface {
|
||||||
addOutbound(int)
|
addOutbound(int64)
|
||||||
addInbound(int)
|
addInbound(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default bytesLogger does nothing.
|
// Default bytesLogger does nothing.
|
||||||
type bytesNullLogger struct{}
|
type bytesNullLogger struct{}
|
||||||
|
|
||||||
func (b bytesNullLogger) addOutbound(amount int) {}
|
func (b bytesNullLogger) addOutbound(amount int64) {}
|
||||||
func (b bytesNullLogger) addInbound(amount int) {}
|
func (b bytesNullLogger) addInbound(amount int64) {}
|
||||||
|
|
||||||
// bytesSyncLogger uses channels to safely log from multiple sources with output
|
// bytesSyncLogger uses channels to safely log from multiple sources with output
|
||||||
// occuring at reasonable intervals.
|
// occuring at reasonable intervals.
|
||||||
type bytesSyncLogger struct {
|
type bytesSyncLogger struct {
|
||||||
outboundChan chan int
|
outboundChan chan int64
|
||||||
inboundChan chan int
|
inboundChan chan int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// newBytesSyncLogger returns a new bytesSyncLogger and starts it loggin.
|
// newBytesSyncLogger returns a new bytesSyncLogger and starts it loggin.
|
||||||
func newBytesSyncLogger() *bytesSyncLogger {
|
func newBytesSyncLogger() *bytesSyncLogger {
|
||||||
b := &bytesSyncLogger{
|
b := &bytesSyncLogger{
|
||||||
outboundChan: make(chan int, 5),
|
outboundChan: make(chan int64, 5),
|
||||||
inboundChan: make(chan int, 5),
|
inboundChan: make(chan int64, 5),
|
||||||
}
|
}
|
||||||
go b.log()
|
go b.log()
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bytesSyncLogger) log() {
|
func (b *bytesSyncLogger) log() {
|
||||||
var outbound, inbound, outEvents, inEvents int
|
var outbound, inbound int64
|
||||||
|
var outEvents, inEvents int
|
||||||
ticker := time.NewTicker(LogTimeInterval)
|
ticker := time.NewTicker(LogTimeInterval)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -61,10 +62,10 @@ func (b *bytesSyncLogger) log() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bytesSyncLogger) addOutbound(amount int) {
|
func (b *bytesSyncLogger) addOutbound(amount int64) {
|
||||||
b.outboundChan <- amount
|
b.outboundChan <- amount
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bytesSyncLogger) addInbound(amount int) {
|
func (b *bytesSyncLogger) addInbound(amount int64) {
|
||||||
b.inboundChan <- amount
|
b.inboundChan <- amount
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ func (c *WebRTCPeer) Write(b []byte) (int, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
c.bytesLogger.addOutbound(len(b))
|
c.bytesLogger.addOutbound(int64(len(b)))
|
||||||
return len(b), nil
|
return len(b), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ func (c *WebRTCPeer) preparePeerConnection(config *webrtc.Configuration) error {
|
||||||
log.Println("0 length message---")
|
log.Println("0 length message---")
|
||||||
}
|
}
|
||||||
n, err := c.writePipe.Write(msg.Data)
|
n, err := c.writePipe.Write(msg.Data)
|
||||||
c.bytesLogger.addInbound(n)
|
c.bytesLogger.addInbound(int64(n))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: Maybe shouldn't actually close.
|
// TODO: Maybe shouldn't actually close.
|
||||||
log.Println("Error writing to SOCKS pipe")
|
log.Println("Error writing to SOCKS pipe")
|
||||||
|
|
|
@ -68,8 +68,8 @@ func (e EventOnProxyStarting) String() string {
|
||||||
|
|
||||||
type EventOnProxyConnectionOver struct {
|
type EventOnProxyConnectionOver struct {
|
||||||
SnowflakeEvent
|
SnowflakeEvent
|
||||||
InboundTraffic int
|
InboundTraffic int64
|
||||||
OutboundTraffic int
|
OutboundTraffic int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e EventOnProxyConnectionOver) String() string {
|
func (e EventOnProxyConnectionOver) String() string {
|
||||||
|
|
|
@ -18,8 +18,8 @@ func NewProxyEventLogger(logPeriod time.Duration, output io.Writer) event.Snowfl
|
||||||
}
|
}
|
||||||
|
|
||||||
type logEventLogger struct {
|
type logEventLogger struct {
|
||||||
inboundSum int
|
inboundSum int64
|
||||||
outboundSum int
|
outboundSum int64
|
||||||
connectionCount int
|
connectionCount int
|
||||||
logPeriod time.Duration
|
logPeriod time.Duration
|
||||||
task *task.Periodic
|
task *task.Periodic
|
||||||
|
|
|
@ -412,7 +412,7 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
|
||||||
log.Printf("close with error generated an error: %v", inerr)
|
log.Printf("close with error generated an error: %v", inerr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
conn.bytesLogger.AddOutbound(n)
|
conn.bytesLogger.AddOutbound(int64(n))
|
||||||
if n != len(msg.Data) {
|
if n != len(msg.Data) {
|
||||||
panic("short write")
|
panic("short write")
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,39 +8,40 @@ import (
|
||||||
// bytesLogger is an interface which is used to allow logging the throughput
|
// bytesLogger is an interface which is used to allow logging the throughput
|
||||||
// of the Snowflake. A default bytesLogger(bytesNullLogger) does nothing.
|
// of the Snowflake. A default bytesLogger(bytesNullLogger) does nothing.
|
||||||
type bytesLogger interface {
|
type bytesLogger interface {
|
||||||
AddOutbound(int)
|
AddOutbound(int64)
|
||||||
AddInbound(int)
|
AddInbound(int64)
|
||||||
ThroughputSummary() string
|
ThroughputSummary() string
|
||||||
GetStat() (in int, out int)
|
GetStat() (in int64, out int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// bytesNullLogger Default bytesLogger does nothing.
|
// bytesNullLogger Default bytesLogger does nothing.
|
||||||
type bytesNullLogger struct{}
|
type bytesNullLogger struct{}
|
||||||
|
|
||||||
// AddOutbound in bytesNullLogger does nothing
|
// AddOutbound in bytesNullLogger does nothing
|
||||||
func (b bytesNullLogger) AddOutbound(amount int) {}
|
func (b bytesNullLogger) AddOutbound(amount int64) {}
|
||||||
|
|
||||||
// AddInbound in bytesNullLogger does nothing
|
// AddInbound in bytesNullLogger does nothing
|
||||||
func (b bytesNullLogger) AddInbound(amount int) {}
|
func (b bytesNullLogger) AddInbound(amount int64) {}
|
||||||
|
|
||||||
// ThroughputSummary in bytesNullLogger does nothing
|
// ThroughputSummary in bytesNullLogger does nothing
|
||||||
func (b bytesNullLogger) ThroughputSummary() string { return "" }
|
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
|
// bytesSyncLogger uses channels to safely log from multiple sources with output
|
||||||
// occuring at reasonable intervals.
|
// occuring at reasonable intervals.
|
||||||
type bytesSyncLogger struct {
|
type bytesSyncLogger struct {
|
||||||
outboundChan, inboundChan chan int
|
outboundChan, inboundChan chan int64
|
||||||
outbound, inbound, outEvents, inEvents int
|
outbound, inbound int64
|
||||||
start time.Time
|
outEvents, inEvents int
|
||||||
|
start time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// newBytesSyncLogger returns a new bytesSyncLogger and starts it loggin.
|
// newBytesSyncLogger returns a new bytesSyncLogger and starts it loggin.
|
||||||
func newBytesSyncLogger() *bytesSyncLogger {
|
func newBytesSyncLogger() *bytesSyncLogger {
|
||||||
b := &bytesSyncLogger{
|
b := &bytesSyncLogger{
|
||||||
outboundChan: make(chan int, 5),
|
outboundChan: make(chan int64, 5),
|
||||||
inboundChan: make(chan int, 5),
|
inboundChan: make(chan int64, 5),
|
||||||
}
|
}
|
||||||
go b.log()
|
go b.log()
|
||||||
b.start = time.Now()
|
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
|
// 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
|
b.outboundChan <- amount
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddInbound add a number of bytes to the inbound total reported by the logger
|
// 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
|
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()))
|
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" }
|
||||||
|
|
|
@ -39,7 +39,7 @@ func (c *webRTCConn) Read(b []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *webRTCConn) Write(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()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
if c.dc != nil {
|
if c.dc != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue