[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/main] Add PT Event Logger



commit ac64d17705a48cb6ace310503e14b62c629655d6
Author: Shelikhoo <xiaokangwang@xxxxxxxxxxx>
Date:   Mon Dec 13 15:39:59 2021 +0000

    Add PT Event Logger
---
 client/lib/pt_event_logger.go | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/client/lib/pt_event_logger.go b/client/lib/pt_event_logger.go
new file mode 100644
index 0000000..b183005
--- /dev/null
+++ b/client/lib/pt_event_logger.go
@@ -0,0 +1,43 @@
+package snowflake_client
+
+import (
+	"fmt"
+
+	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) {
+	switch e.(type) {
+	case event.EventOnOfferCreated:
+		e := e.(event.EventOnOfferCreated)
+		if e.Error != nil {
+			pt.Log(pt.LogSeverityError, fmt.Sprintf("offer creation failure %v", e.Error.Error()))
+		} else {
+			pt.Log(pt.LogSeverityNotice, fmt.Sprintf("offer created %v", e.WebRTCLocalDescription))
+		}
+
+	case event.EventOnBrokerRendezvous:
+		e := e.(event.EventOnBrokerRendezvous)
+		if e.Error != nil {
+			pt.Log(pt.LogSeverityError, fmt.Sprintf("broker failure %v", e.Error.Error()))
+		} else {
+			pt.Log(pt.LogSeverityNotice, fmt.Sprintf("broker rendezvous peer %v", e.WebRTCRemoteDescription))
+		}
+
+	case event.EventOnSnowflakeConnected:
+		pt.Log(pt.LogSeverityNotice, fmt.Sprintf("connected"))
+
+	case event.EventOnSnowflakeConnectionFailed:
+		e := e.(event.EventOnSnowflakeConnectionFailed)
+		pt.Log(pt.LogSeverityError, fmt.Sprintf("connection failed %v", e.Error.Error()))
+	}
+
+}



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits