mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Remove BytesLoggers from exported functions
This commit is contained in:
parent
50e4f4fd61
commit
b2edf948e2
3 changed files with 22 additions and 22 deletions
|
@ -306,7 +306,7 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
|
||||||
|
|
||||||
pr, pw := io.Pipe()
|
pr, pw := io.Pipe()
|
||||||
conn := &webRTCConn{pc: pc, dc: dc, pr: pr}
|
conn := &webRTCConn{pc: pc, dc: dc, pr: pr}
|
||||||
conn.bytesLogger = NewBytesSyncLogger()
|
conn.bytesLogger = newBytesSyncLogger()
|
||||||
|
|
||||||
dc.OnOpen(func() {
|
dc.OnOpen(func() {
|
||||||
log.Println("OnOpen channel")
|
log.Println("OnOpen channel")
|
||||||
|
|
|
@ -5,37 +5,37 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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(int)
|
||||||
AddInbound(int)
|
AddInbound(int)
|
||||||
ThroughputSummary() string
|
ThroughputSummary() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 int) {}
|
||||||
|
|
||||||
// AddInbound in BytesNullLogger does nothing
|
// AddInbound in bytesNullLogger does nothing
|
||||||
func (b BytesNullLogger) AddInbound(amount int) {}
|
func (b bytesNullLogger) AddInbound(amount int) {}
|
||||||
|
|
||||||
// ThroughputSummary in BytesNullLogger does nothing
|
// ThroughputSummary in bytesNullLogger does nothing
|
||||||
func (b BytesNullLogger) ThroughputSummary() string { return "" }
|
func (b bytesNullLogger) ThroughputSummary() string { return "" }
|
||||||
|
|
||||||
// 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 int
|
||||||
outbound, inbound, outEvents, inEvents int
|
outbound, inbound, outEvents, inEvents int
|
||||||
start time.Time
|
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 int, 5),
|
||||||
inboundChan: make(chan int, 5),
|
inboundChan: make(chan int, 5),
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func NewBytesSyncLogger() *BytesSyncLogger {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BytesSyncLogger) log() {
|
func (b *bytesSyncLogger) log() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case amount := <-b.outboundChan:
|
case amount := <-b.outboundChan:
|
||||||
|
@ -58,17 +58,17 @@ 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 int) {
|
||||||
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 int) {
|
||||||
b.inboundChan <- amount
|
b.inboundChan <- amount
|
||||||
}
|
}
|
||||||
|
|
||||||
// ThroughputSummary view a formatted summary of the throughput totals
|
// ThroughputSummary view a formatted summary of the throughput totals
|
||||||
func (b *BytesSyncLogger) ThroughputSummary() string {
|
func (b *bytesSyncLogger) ThroughputSummary() string {
|
||||||
var inUnit, outUnit string
|
var inUnit, outUnit string
|
||||||
units := []string{"B", "KB", "MB", "GB"}
|
units := []string{"B", "KB", "MB", "GB"}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ type webRTCConn struct {
|
||||||
lock sync.Mutex // Synchronization for DataChannel destruction
|
lock sync.Mutex // Synchronization for DataChannel destruction
|
||||||
once sync.Once // Synchronization for PeerConnection destruction
|
once sync.Once // Synchronization for PeerConnection destruction
|
||||||
|
|
||||||
bytesLogger BytesLogger
|
bytesLogger bytesLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *webRTCConn) Read(b []byte) (int, error) {
|
func (c *webRTCConn) Read(b []byte) (int, error) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue