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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue