mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Remove code duplication and run goimports
This commit is contained in:
parent
c6a0bc299c
commit
2a212640ce
26 changed files with 53 additions and 65 deletions
|
@ -3,9 +3,11 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/bridgefingerprint"
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/bridgefingerprint"
|
||||
)
|
||||
|
||||
const DefaultBridges = `{"displayName":"default", "webSocketAddress":"wss://snowflake.torproject.org", "fingerprint":"2B280B23E1107BB62ABFC40DDCC8824814F80A72"}
|
||||
|
|
|
@ -27,9 +27,11 @@ import (
|
|||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/ptutil/safelog"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/namematcher"
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/ptutil/safelog"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/namematcher"
|
||||
)
|
||||
|
||||
type BrokerContext struct {
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/bridgefingerprint"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||
)
|
||||
|
||||
|
|
|
@ -16,7 +16,9 @@ import (
|
|||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/geoip"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/ptutil/safeprom"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||
)
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"time"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/amp"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||
)
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/sqsclient"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/util"
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
"github.com/golang/mock/gomock"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/sqsclient"
|
||||
)
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"time"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
|
||||
)
|
||||
|
||||
|
|
|
@ -197,18 +197,7 @@ func NewWebRTCDialerWithEvents(broker *BrokerChannel, iceServers []webrtc.ICESer
|
|||
func NewWebRTCDialerWithEventsAndProxy(broker *BrokerChannel, iceServers []webrtc.ICEServer, max int,
|
||||
eventLogger event.SnowflakeEventReceiver, proxy *url.URL,
|
||||
) *WebRTCDialer {
|
||||
config := webrtc.Configuration{
|
||||
ICEServers: iceServers,
|
||||
}
|
||||
|
||||
return &WebRTCDialer{
|
||||
BrokerChannel: broker,
|
||||
webrtcConfig: &config,
|
||||
max: max,
|
||||
|
||||
eventLogger: eventLogger,
|
||||
proxy: proxy,
|
||||
}
|
||||
return NewCovertWebRTCDialerWithEventsAndProxy(broker, iceServers, max, eventLogger, proxy, nil)
|
||||
}
|
||||
|
||||
// NewWebRTCDialerWithEventsAndProxy constructs a new WebRTCDialer setting DTLS mimicking and randomization.
|
||||
|
@ -235,10 +224,7 @@ func NewCovertWebRTCDialerWithEventsAndProxy(broker *BrokerChannel, iceServers [
|
|||
func (w WebRTCDialer) Catch() (*WebRTCPeer, error) {
|
||||
// TODO: [#25591] Fetch ICE server information from Broker.
|
||||
// TODO: [#25596] Consider TURN servers here too.
|
||||
if w.covertDTLSConfig != nil {
|
||||
return NewCovertWebRTCPeerWithEventsAndProxy(w.webrtcConfig, w.BrokerChannel, w.eventLogger, w.proxy, w.covertDTLSConfig)
|
||||
}
|
||||
return NewWebRTCPeerWithEventsAndProxy(w.webrtcConfig, w.BrokerChannel, w.eventLogger, w.proxy)
|
||||
}
|
||||
|
||||
// GetMax returns the maximum number of snowflakes to collect.
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/sqsclient"
|
||||
sqscreds "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/sqscreds/lib"
|
||||
)
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"github.com/golang/mock/gomock"
|
||||
"github.com/pion/webrtc/v4"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/amp"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/nat"
|
||||
|
|
|
@ -166,18 +166,18 @@ func NewSnowflakeClient(config ClientConfig) (*Transport, error) {
|
|||
}
|
||||
|
||||
eventsLogger := event.NewSnowflakeEventDispatcher()
|
||||
var transport *Transport
|
||||
|
||||
var covertDTLSConfig covertdtls.CovertDTLSConfig
|
||||
|
||||
if config.CovertDTLSConfig != "" {
|
||||
covertDTLSConfig := covertdtls.ParseConfigString(config.CovertDTLSConfig)
|
||||
covertDTLSConfig = covertdtls.ParseConfigString(config.CovertDTLSConfig)
|
||||
if config.CovertDTLSFingerprint != "" {
|
||||
covertDTLSConfig.Fingerprint = fingerprints.ClientHelloFingerprint(*&config.CovertDTLSFingerprint)
|
||||
covertDTLSConfig.Fingerprint = fingerprints.ClientHelloFingerprint(config.CovertDTLSFingerprint)
|
||||
}
|
||||
transport = &Transport{dialer: NewCovertWebRTCDialerWithEventsAndProxy(broker, iceServers, max, eventsLogger, config.CommunicationProxy, &covertDTLSConfig), eventDispatcher: eventsLogger}
|
||||
} else {
|
||||
transport = &Transport{dialer: NewWebRTCDialerWithEventsAndProxy(broker, iceServers, max, eventsLogger, config.CommunicationProxy), eventDispatcher: eventsLogger}
|
||||
}
|
||||
|
||||
transport := &Transport{dialer: NewCovertWebRTCDialerWithEventsAndProxy(broker, iceServers, max, eventsLogger, config.CommunicationProxy, &covertDTLSConfig), eventDispatcher: eventsLogger}
|
||||
|
||||
return transport, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -73,35 +73,7 @@ func NewWebRTCPeerWithEventsAndProxy(
|
|||
config *webrtc.Configuration, broker *BrokerChannel,
|
||||
eventsLogger event.SnowflakeEventReceiver, proxy *url.URL,
|
||||
) (*WebRTCPeer, error) {
|
||||
if eventsLogger == nil {
|
||||
eventsLogger = event.NewSnowflakeEventDispatcher()
|
||||
}
|
||||
|
||||
connection := new(WebRTCPeer)
|
||||
{
|
||||
var buf [8]byte
|
||||
if _, err := rand.Read(buf[:]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
connection.id = "snowflake-" + hex.EncodeToString(buf[:])
|
||||
}
|
||||
connection.closed = make(chan struct{})
|
||||
|
||||
// Override with something that's not NullLogger to have real logging.
|
||||
connection.bytesLogger = &bytesNullLogger{}
|
||||
|
||||
// Pipes remain the same even when DataChannel gets switched.
|
||||
connection.recvPipe, connection.writePipe = io.Pipe()
|
||||
|
||||
connection.eventsLogger = eventsLogger
|
||||
connection.proxy = proxy
|
||||
|
||||
err := connection.connect(config, broker, nil)
|
||||
if err != nil {
|
||||
connection.Close()
|
||||
return nil, err
|
||||
}
|
||||
return connection, nil
|
||||
return NewCovertWebRTCPeerWithEventsAndProxy(config, broker, eventsLogger, proxy, nil)
|
||||
}
|
||||
|
||||
// NewCovertWebRTCPeerWithEventsAndProxy constructs a WebRTC PeerConnection to a snowflake proxy using DTLS mimicking or randomization.
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package covertdtls
|
||||
|
||||
import (
|
||||
"github.com/theodorsm/covert-dtls/pkg/fingerprints"
|
||||
"strings"
|
||||
|
||||
"github.com/theodorsm/covert-dtls/pkg/fingerprints"
|
||||
)
|
||||
|
||||
type CovertDTLSConfig struct {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package event
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type stubReceiver struct {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/pion/webrtc/v4"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/ptutil/safelog"
|
||||
)
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/bridgefingerprint"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/nat"
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package namematcher
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
import . "github.com/smartystreets/goconvey/convey"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestMatchMember(t *testing.T) {
|
||||
testingVector := []struct {
|
||||
|
|
|
@ -16,12 +16,13 @@ package nat
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/proxy"
|
||||
"log"
|
||||
"net"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/proxy"
|
||||
|
||||
"github.com/pion/stun/v3"
|
||||
)
|
||||
|
||||
|
|
|
@ -2,8 +2,9 @@ package utls
|
|||
|
||||
import (
|
||||
"errors"
|
||||
utls "github.com/refraction-networking/utls"
|
||||
"strings"
|
||||
|
||||
utls "github.com/refraction-networking/utls"
|
||||
)
|
||||
|
||||
// ported from https://github.com/max-b/snowflake/commit/9dded063cb74c6941a16ad90b9dd0e06e618e55e
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package utls
|
||||
|
||||
import (
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/version"
|
||||
"strings"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/version"
|
||||
)
|
||||
|
||||
func generateVersionOutput() string {
|
||||
|
|
|
@ -5,13 +5,14 @@ import (
|
|||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"golang.org/x/net/proxy"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/proxy"
|
||||
|
||||
utls "github.com/refraction-networking/utls"
|
||||
"golang.org/x/net/http2"
|
||||
)
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"time"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/ptutil/safelog"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/util"
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
|
||||
"github.com/pion/webrtc/v4"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/util"
|
||||
)
|
||||
|
|
|
@ -12,7 +12,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/theodorsm/covert-dtls/pkg/fingerprints"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/ptutil/safelog"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/covertdtls"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/version"
|
||||
|
|
|
@ -18,11 +18,14 @@ import (
|
|||
"sync"
|
||||
"syscall"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/ptutil/safelog"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/version"
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/ptutil/safelog"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/version"
|
||||
|
||||
pt "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib"
|
||||
|
||||
sf "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/server/lib"
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue