Move tor-specific code outside of client library

This commit is contained in:
Cecylia Bocovich 2022-04-11 11:38:52 -04:00
parent 2f89fbc2ed
commit d807e9d370
No known key found for this signature in database
GPG key ID: 009DE379FD9B7B90
3 changed files with 5 additions and 4 deletions

43
client/pt_event_logger.go Normal file
View file

@ -0,0 +1,43 @@
package main
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.LogSeverityNotice, fmt.Sprintf("offer creation failure %v", e.Error.Error()))
} else {
pt.Log(pt.LogSeverityNotice, fmt.Sprintf("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()))
} else {
pt.Log(pt.LogSeverityNotice, fmt.Sprintf("broker rendezvous peer received"))
}
case event.EventOnSnowflakeConnected:
pt.Log(pt.LogSeverityNotice, fmt.Sprintf("connected"))
case event.EventOnSnowflakeConnectionFailed:
e := e.(event.EventOnSnowflakeConnectionFailed)
pt.Log(pt.LogSeverityNotice, fmt.Sprintf("connection failed %v", e.Error.Error()))
}
}