This is an automated email from the git hooks/post-receive script.
cohosh pushed a commit to branch main in repository pluggable-transports/snowflake.
The following commit(s) were added to refs/heads/main by this push: new e283820 Scrub ptEvent logs e283820 is described below
commit e2838201adf1a98ee065cc65598463777afac2dc Author: itchyonion itchyonion@torproject.com AuthorDate: Wed Mar 23 08:49:28 2022 -0700
Scrub ptEvent logs --- client/pt_event_logger.go | 53 ++++++++++++++++++++++++++++++++++++++++------- go.mod | 3 +-- go.sum | 10 --------- 3 files changed, 47 insertions(+), 19 deletions(-)
diff --git a/client/pt_event_logger.go b/client/pt_event_logger.go index 788c074..aae8716 100644 --- a/client/pt_event_logger.go +++ b/client/pt_event_logger.go @@ -1,10 +1,12 @@ package main
import ( + "bytes" "fmt" - pt "git.torproject.org/pluggable-transports/goptlib.git" "git.torproject.org/pluggable-transports/snowflake.git/v2/common/event" + "git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog" + "strings" )
func NewPTEventLogger() event.SnowflakeEventReceiver { @@ -14,30 +16,67 @@ func NewPTEventLogger() event.SnowflakeEventReceiver { type ptEventLogger struct { }
+type logSeverity int + +const ( + Debug logSeverity = iota + Info + Notice + Warning + Error +) + +func safePTLog(severity logSeverity, format string, a ...interface{}) { + var buff bytes.Buffer + scrubber := &safelog.LogScrubber{Output: &buff} + + // make sure logString ends with exactly one "\n" so it's not stuck in scrubber.Write()'s internal buffer + logString := strings.TrimRight(fmt.Sprintf(format, a...), "\n") + "\n" + scrubber.Write([]byte(logString)) + + // remove newline before calling pt.Log because it adds a newline + msg := strings.TrimRight(buff.String(), "\n") + + switch severity { + case Error: + pt.Log(pt.LogSeverityError, msg) + case Warning: + pt.Log(pt.LogSeverityWarning, msg) + case Notice: + pt.Log(pt.LogSeverityWarning, msg) + case Info: + pt.Log(pt.LogSeverityInfo, msg) + case Debug: + pt.Log(pt.LogSeverityDebug, msg) + default: + pt.Log(pt.LogSeverityNotice, msg) + } +} + func (p ptEventLogger) OnNewSnowflakeEvent(e event.SnowflakeEvent) { switch e.(type) { case event.EventOnOfferCreated: e := e.(event.EventOnOfferCreated) if e.Error != nil { - pt.Log(pt.LogSeverityNotice, fmt.Sprintf("offer creation failure %v", e.Error.Error())) + safePTLog(Notice, "offer creation failure %v", e.Error.Error()) } else { - pt.Log(pt.LogSeverityNotice, fmt.Sprintf("offer created")) + safePTLog(Notice, "offer created") }
case event.EventOnBrokerRendezvous: e := e.(event.EventOnBrokerRendezvous) if e.Error != nil { - pt.Log(pt.LogSeverityNotice, fmt.Sprintf("broker failure %v", e.Error.Error())) + safePTLog(Notice, "broker failure %v", e.Error.Error()) } else { - pt.Log(pt.LogSeverityNotice, fmt.Sprintf("broker rendezvous peer received")) + safePTLog(Notice, "broker rendezvous peer received") }
case event.EventOnSnowflakeConnected: - pt.Log(pt.LogSeverityNotice, fmt.Sprintf("connected")) + safePTLog(Notice, "connected")
case event.EventOnSnowflakeConnectionFailed: e := e.(event.EventOnSnowflakeConnectionFailed) - pt.Log(pt.LogSeverityNotice, fmt.Sprintf("connection failed %v", e.Error.Error())) + safePTLog(Notice, "trying a new proxy: %v", e.Error.Error()) }
} diff --git a/go.mod b/go.mod index 432a237..d05b325 100644 --- a/go.mod +++ b/go.mod @@ -10,13 +10,12 @@ require ( github.com/pion/ice/v2 v2.0.15 github.com/pion/sdp/v3 v3.0.4 github.com/pion/stun v0.3.5 - github.com/pion/transport v0.12.3 // indirect github.com/pion/webrtc/v3 v3.0.15 github.com/prometheus/client_golang v1.10.0 github.com/prometheus/client_model v0.2.0 github.com/refraction-networking/utls v1.0.0 github.com/smartystreets/goconvey v1.6.4 - github.com/stretchr/testify v1.7.0 // indirect + github.com/stretchr/testify v1.7.0 github.com/xtaci/kcp-go/v5 v5.6.1 github.com/xtaci/smux v1.5.15 gitlab.torproject.org/tpo/anti-censorship/geoip v0.0.0-20210928150955-7ce4b3d98d01 diff --git a/go.sum b/go.sum index c2fa108..c2258f0 100644 --- a/go.sum +++ b/go.sum @@ -224,7 +224,6 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi github.com/pion/datachannel v1.4.21 h1:3ZvhNyfmxsAqltQrApLPQMhSFNA+aT87RqyCq4OXmf0= github.com/pion/datachannel v1.4.21/go.mod h1:oiNyP4gHx2DIwRzX/MFyH0Rz/Gz05OgBlayAI2hAWjg= github.com/pion/dtls/v2 v2.0.4/go.mod h1:qAkFscX0ZHoI1E07RfYPoRw3manThveu+mlTDdOxoGI= -github.com/pion/dtls/v2 v2.0.8 h1:reGe8rNIMfO/UAeFLqO61tl64t154Qfkr4U3Gzu1tsg= github.com/pion/dtls/v2 v2.0.8/go.mod h1:QuDII+8FVvk9Dp5t5vYIMTo7hh7uBkra+8QIm7QGm10= github.com/pion/dtls/v2 v2.0.12 h1:QMSvNht7FM/XDXij3Ic90SCbl5yL7kppeI4ghfF4in8= github.com/pion/dtls/v2 v2.0.12/go.mod h1:5Pe3QJI0Ajsx+uCfxREeewGFlKYBzLrXe9ku7Y0oRXM= @@ -260,7 +259,6 @@ github.com/pion/transport v0.12.3 h1:vdBfvfU/0Wq8kd2yhUMSDB/x+O4Z9MYVl2fJ5BT4JZw github.com/pion/transport v0.12.3/go.mod h1:OViWW9SP2peE/HbwBvARicmAVnesphkNkCVZIWJ6q9A= github.com/pion/turn/v2 v2.0.5 h1:iwMHqDfPEDEOFzwWKT56eFmh6DYC6o/+xnLAEzgISbA= github.com/pion/turn/v2 v2.0.5/go.mod h1:APg43CFyt/14Uy7heYUOGWdkem/Wu4PhCO/bjyrTqMw= -github.com/pion/udp v0.1.0 h1:uGxQsNyrqG3GLINv36Ff60covYmfrLoxzwnCsIYspXI= github.com/pion/udp v0.1.0/go.mod h1:BPELIjbwE9PRbd/zxI/KYBnbo7B6+oA6YuEaNE8lths= github.com/pion/udp v0.1.1 h1:8UAPvyqmsxK8oOjloDk4wUt63TzFe9WEJkg5lChlj7o= github.com/pion/udp v0.1.1/go.mod h1:6AFo+CMdKQm7UiA0eUPA8/eVCTx8jBIITLZHc9DWX5M= @@ -380,8 +378,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= -golang.org/x/crypto v0.0.0-20210317152858-513c2a44f670 h1:gzMM0EjIYiRmJI3+jBdFuoynZlpxa2JQZsolKu09BXo= -golang.org/x/crypto v0.0.0-20210317152858-513c2a44f670/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 h1:/pEO3GD/ABYAjuakUS6xSEmmlyVS4kxBNkeA9tLJiTI= golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -421,8 +417,6 @@ golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20201201195509-5d6afe98e0b7/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4 h1:b0LrWgu8+q7z4J+0Y3Umo5q1dL7NXBkKBWkaVkAq17E= -golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c h1:WtYZ93XtWSO5KlOMgPZu7hXY9WhMZpprvlm5VwvAl8c= golang.org/x/net v0.0.0-20211201190559-0a0e4e1bb54c/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -465,9 +459,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e h1:XNp2Flc/1eWQGk5BLzqTAN7fQIwIbfyVTuVxXxZh73M= -golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -475,7 +466,6 @@ golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXR golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
tor-commits@lists.torproject.org