mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Implement String() method on events
To make it safe for logging safelog.Scrub function is now public. Closes: #40141
This commit is contained in:
parent
9757784c5a
commit
1d592b06e5
3 changed files with 38 additions and 69 deletions
|
@ -1,6 +1,11 @@
|
|||
package event
|
||||
|
||||
import "github.com/pion/webrtc/v3"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog"
|
||||
"github.com/pion/webrtc/v3"
|
||||
)
|
||||
|
||||
type SnowflakeEvent interface {
|
||||
IsSnowflakeEvent()
|
||||
|
@ -13,27 +18,56 @@ type EventOnOfferCreated struct {
|
|||
Error error
|
||||
}
|
||||
|
||||
func (e EventOnOfferCreated) String() string {
|
||||
if e.Error != nil {
|
||||
scrubbed := safelog.Scrub([]byte(e.Error.Error()))
|
||||
return fmt.Sprintf("offer creation failure %s", scrubbed)
|
||||
}
|
||||
return "offer created"
|
||||
}
|
||||
|
||||
type EventOnBrokerRendezvous struct {
|
||||
SnowflakeEvent
|
||||
WebRTCRemoteDescription *webrtc.SessionDescription
|
||||
Error error
|
||||
}
|
||||
|
||||
func (e EventOnBrokerRendezvous) String() string {
|
||||
if e.Error != nil {
|
||||
scrubbed := safelog.Scrub([]byte(e.Error.Error()))
|
||||
return fmt.Sprintf("broker failure %s", scrubbed)
|
||||
}
|
||||
return "broker rendezvous peer received"
|
||||
}
|
||||
|
||||
type EventOnSnowflakeConnected struct {
|
||||
SnowflakeEvent
|
||||
}
|
||||
|
||||
func (e EventOnSnowflakeConnected) String() string {
|
||||
return "connected"
|
||||
}
|
||||
|
||||
type EventOnSnowflakeConnectionFailed struct {
|
||||
SnowflakeEvent
|
||||
Error error
|
||||
}
|
||||
|
||||
func (e EventOnSnowflakeConnectionFailed) String() string {
|
||||
scrubbed := safelog.Scrub([]byte(e.Error.Error()))
|
||||
return fmt.Sprintf("trying a new proxy: %s", scrubbed)
|
||||
}
|
||||
|
||||
type EventOnProxyConnectionOver struct {
|
||||
SnowflakeEvent
|
||||
InboundTraffic int
|
||||
OutboundTraffic int
|
||||
}
|
||||
|
||||
func (e EventOnProxyConnectionOver) String() string {
|
||||
return fmt.Sprintf("Proxy connection closed (↑ %d, ↓ %d)", e.InboundTraffic, e.OutboundTraffic)
|
||||
}
|
||||
|
||||
type SnowflakeEventReceiver interface {
|
||||
// OnNewSnowflakeEvent notify receiver about a new event
|
||||
// This method MUST not block
|
||||
|
|
|
@ -38,7 +38,7 @@ type LogScrubber struct {
|
|||
func (ls *LogScrubber) Lock() { (*ls).lock.Lock() }
|
||||
func (ls *LogScrubber) Unlock() { (*ls).lock.Unlock() }
|
||||
|
||||
func scrub(b []byte) []byte {
|
||||
func Scrub(b []byte) []byte {
|
||||
scrubbedBytes := b
|
||||
for _, pattern := range scrubberPatterns {
|
||||
// this is a workaround since go does not yet support look ahead or look
|
||||
|
@ -62,7 +62,7 @@ func (ls *LogScrubber) Write(b []byte) (n int, err error) {
|
|||
return
|
||||
}
|
||||
fullLines := ls.buffer[:i+1]
|
||||
_, err = ls.Output.Write(scrub(fullLines))
|
||||
_, err = ls.Output.Write(Scrub(fullLines))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue