This is an automated email from the git hooks/post-receive script.
meskio pushed a change to branch main in repository pluggable-transports/snowflake.
from 9757784 Wait some time before displaying the proxy usage log new 1d592b0 Implement String() method on events new 3473b43 Move ptEventLogger into the client/snowflake.go
The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
Summary of changes: client/pt_event_logger.go | 82 ----------------------------------------------- client/snowflake.go | 12 +++++++ common/event/interface.go | 36 ++++++++++++++++++++- common/safelog/log.go | 4 +-- 4 files changed, 49 insertions(+), 85 deletions(-) delete mode 100644 client/pt_event_logger.go
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake.
commit 1d592b06e51b42ca4ed13ec219f012a2915c2b1d Author: meskio meskio@torproject.org AuthorDate: Fri May 20 09:43:03 2022 +0200
Implement String() method on events
To make it safe for logging safelog.Scrub function is now public.
Closes: #40141 --- client/pt_event_logger.go | 67 +---------------------------------------------- common/event/interface.go | 36 ++++++++++++++++++++++++- common/safelog/log.go | 4 +-- 3 files changed, 38 insertions(+), 69 deletions(-)
diff --git a/client/pt_event_logger.go b/client/pt_event_logger.go index aae8716..483a3c6 100644 --- a/client/pt_event_logger.go +++ b/client/pt_event_logger.go @@ -1,12 +1,8 @@ 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 { @@ -16,67 +12,6 @@ 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 { - safePTLog(Notice, "offer creation failure %v", e.Error.Error()) - } else { - safePTLog(Notice, "offer created") - } - - case event.EventOnBrokerRendezvous: - e := e.(event.EventOnBrokerRendezvous) - if e.Error != nil { - safePTLog(Notice, "broker failure %v", e.Error.Error()) - } else { - safePTLog(Notice, "broker rendezvous peer received") - } - - case event.EventOnSnowflakeConnected: - safePTLog(Notice, "connected") - - case event.EventOnSnowflakeConnectionFailed: - e := e.(event.EventOnSnowflakeConnectionFailed) - safePTLog(Notice, "trying a new proxy: %v", e.Error.Error()) - } - + pt.Log(pt.LogSeverityNotice, e.String()) } diff --git a/common/event/interface.go b/common/event/interface.go index b41d7c3..968b270 100644 --- a/common/event/interface.go +++ b/common/event/interface.go @@ -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 diff --git a/common/safelog/log.go b/common/safelog/log.go index 4a135ce..6ca23ee 100644 --- a/common/safelog/log.go +++ b/common/safelog/log.go @@ -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 }
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake.
commit 3473b438e518f12fc1e0945b362e8cef25756b4f Author: meskio meskio@torproject.org AuthorDate: Wed May 25 17:56:12 2022 +0200
Move ptEventLogger into the client/snowflake.go
Remove client/pt_event_logger.go file as is very minimal. --- client/pt_event_logger.go | 17 ----------------- client/snowflake.go | 12 ++++++++++++ 2 files changed, 12 insertions(+), 17 deletions(-)
diff --git a/client/pt_event_logger.go b/client/pt_event_logger.go deleted file mode 100644 index 483a3c6..0000000 --- a/client/pt_event_logger.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - pt "git.torproject.org/pluggable-transports/goptlib.git" - "git.torproject.org/pluggable-transports/snowflake.git/v2/common/event" -) - -func NewPTEventLogger() event.SnowflakeEventReceiver { - return &ptEventLogger{} -} - -type ptEventLogger struct { -} - -func (p ptEventLogger) OnNewSnowflakeEvent(e event.SnowflakeEvent) { - pt.Log(pt.LogSeverityNotice, e.String()) -} diff --git a/client/snowflake.go b/client/snowflake.go index ac66a0d..2cb6549 100644 --- a/client/snowflake.go +++ b/client/snowflake.go @@ -17,6 +17,7 @@ import (
pt "git.torproject.org/pluggable-transports/goptlib.git" sf "git.torproject.org/pluggable-transports/snowflake.git/v2/client/lib" + "git.torproject.org/pluggable-transports/snowflake.git/v2/common/event" "git.torproject.org/pluggable-transports/snowflake.git/v2/common/safelog" )
@@ -24,6 +25,17 @@ const ( DefaultSnowflakeCapacity = 1 )
+type ptEventLogger struct { +} + +func NewPTEventLogger() event.SnowflakeEventReceiver { + return &ptEventLogger{} +} + +func (p ptEventLogger) OnNewSnowflakeEvent(e event.SnowflakeEvent) { + pt.Log(pt.LogSeverityNotice, e.String()) +} + // Exchanges bytes between two ReadWriters. // (In this case, between a SOCKS connection and a snowflake transport conn) func copyLoop(socks, sfconn io.ReadWriter) {
tor-commits@lists.torproject.org