mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Cosmetic fixes taken from !219.
shelikhoo/dev-udp-performance-rebased branch https://gitlab.torproject.org/shelikhoo/snowflake/-/commits/9dce28cfc2093490473432ffecd9abaab7ebdbdb
This commit is contained in:
parent
f7a468e31b
commit
d0529141ac
6 changed files with 32 additions and 23 deletions
|
@ -39,6 +39,7 @@ import (
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
"github.com/xtaci/kcp-go/v5"
|
"github.com/xtaci/kcp-go/v5"
|
||||||
"github.com/xtaci/smux"
|
"github.com/xtaci/smux"
|
||||||
|
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/nat"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/nat"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
||||||
|
@ -122,7 +123,6 @@ type ClientConfig struct {
|
||||||
// keepLocalAddresses is a flag to enable sending local network addresses (for testing purposes)
|
// keepLocalAddresses is a flag to enable sending local network addresses (for testing purposes)
|
||||||
// max is the maximum number of snowflakes the client should gather for each SOCKS connection
|
// max is the maximum number of snowflakes the client should gather for each SOCKS connection
|
||||||
func NewSnowflakeClient(config ClientConfig) (*Transport, error) {
|
func NewSnowflakeClient(config ClientConfig) (*Transport, error) {
|
||||||
|
|
||||||
log.Println("\n\n\n --- Starting Snowflake Client ---")
|
log.Println("\n\n\n --- Starting Snowflake Client ---")
|
||||||
|
|
||||||
iceServers := parseIceServers(config.ICEAddresses)
|
iceServers := parseIceServers(config.ICEAddresses)
|
||||||
|
@ -212,6 +212,7 @@ func (t *Transport) Dial() (net.Conn, error) {
|
||||||
cleanup = nil
|
cleanup = nil
|
||||||
return &SnowflakeConn{Stream: stream, sess: sess, pconn: pconn, snowflakes: snowflakes}, nil
|
return &SnowflakeConn{Stream: stream, sess: sess, pconn: pconn, snowflakes: snowflakes}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Transport) AddSnowflakeEventListener(receiver event.SnowflakeEventReceiver) {
|
func (t *Transport) AddSnowflakeEventListener(receiver event.SnowflakeEventReceiver) {
|
||||||
t.eventDispatcher.AddSnowflakeEventListener(receiver)
|
t.eventDispatcher.AddSnowflakeEventListener(receiver)
|
||||||
}
|
}
|
||||||
|
@ -250,7 +251,6 @@ func (conn *SnowflakeConn) Close() error {
|
||||||
// loop through all provided STUN servers until we exhaust the list or find
|
// loop through all provided STUN servers until we exhaust the list or find
|
||||||
// one that is compatible with RFC 5780
|
// one that is compatible with RFC 5780
|
||||||
func updateNATType(servers []webrtc.ICEServer, broker *BrokerChannel, proxy *url.URL) {
|
func updateNATType(servers []webrtc.ICEServer, broker *BrokerChannel, proxy *url.URL) {
|
||||||
|
|
||||||
var restrictedNAT bool
|
var restrictedNAT bool
|
||||||
var err error
|
var err error
|
||||||
for _, server := range servers {
|
for _, server := range servers {
|
||||||
|
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pion/transport/v2"
|
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/proxy"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -15,9 +13,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pion/ice/v2"
|
"github.com/pion/ice/v2"
|
||||||
|
"github.com/pion/transport/v2"
|
||||||
"github.com/pion/transport/v2/stdnet"
|
"github.com/pion/transport/v2/stdnet"
|
||||||
"github.com/pion/webrtc/v3"
|
"github.com/pion/webrtc/v3"
|
||||||
|
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
|
||||||
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WebRTCPeer represents a WebRTC connection to a remote snowflake proxy.
|
// WebRTCPeer represents a WebRTC connection to a remote snowflake proxy.
|
||||||
|
@ -45,14 +46,17 @@ type WebRTCPeer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: Use NewWebRTCPeerWithEventsAndProxy Instead.
|
// Deprecated: Use NewWebRTCPeerWithEventsAndProxy Instead.
|
||||||
func NewWebRTCPeer(config *webrtc.Configuration,
|
func NewWebRTCPeer(
|
||||||
broker *BrokerChannel) (*WebRTCPeer, error) {
|
config *webrtc.Configuration, broker *BrokerChannel,
|
||||||
|
) (*WebRTCPeer, error) {
|
||||||
return NewWebRTCPeerWithEventsAndProxy(config, broker, nil, nil)
|
return NewWebRTCPeerWithEventsAndProxy(config, broker, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: Use NewWebRTCPeerWithEventsAndProxy Instead.
|
// Deprecated: Use NewWebRTCPeerWithEventsAndProxy Instead.
|
||||||
func NewWebRTCPeerWithEvents(config *webrtc.Configuration,
|
func NewWebRTCPeerWithEvents(
|
||||||
broker *BrokerChannel, eventsLogger event.SnowflakeEventReceiver) (*WebRTCPeer, error) {
|
config *webrtc.Configuration, broker *BrokerChannel,
|
||||||
|
eventsLogger event.SnowflakeEventReceiver,
|
||||||
|
) (*WebRTCPeer, error) {
|
||||||
return NewWebRTCPeerWithEventsAndProxy(config, broker, eventsLogger, nil)
|
return NewWebRTCPeerWithEventsAndProxy(config, broker, eventsLogger, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +65,10 @@ func NewWebRTCPeerWithEvents(config *webrtc.Configuration,
|
||||||
// The creation of the peer handles the signaling to the Snowflake broker, including
|
// The creation of the peer handles the signaling to the Snowflake broker, including
|
||||||
// the exchange of SDP information, the creation of a PeerConnection, and the establishment
|
// the exchange of SDP information, the creation of a PeerConnection, and the establishment
|
||||||
// of a DataChannel to the Snowflake proxy.
|
// of a DataChannel to the Snowflake proxy.
|
||||||
func NewWebRTCPeerWithEventsAndProxy(config *webrtc.Configuration,
|
func NewWebRTCPeerWithEventsAndProxy(
|
||||||
broker *BrokerChannel, eventsLogger event.SnowflakeEventReceiver, proxy *url.URL) (*WebRTCPeer, error) {
|
config *webrtc.Configuration, broker *BrokerChannel,
|
||||||
|
eventsLogger event.SnowflakeEventReceiver, proxy *url.URL,
|
||||||
|
) (*WebRTCPeer, error) {
|
||||||
if eventsLogger == nil {
|
if eventsLogger == nil {
|
||||||
eventsLogger = event.NewSnowflakeEventDispatcher()
|
eventsLogger = event.NewSnowflakeEventDispatcher()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/proxy"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
@ -18,8 +17,10 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
pt "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib"
|
pt "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib"
|
||||||
|
|
||||||
sf "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/client/lib"
|
sf "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/client/lib"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/event"
|
||||||
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/proxy"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/safelog"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/safelog"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/version"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/version"
|
||||||
)
|
)
|
||||||
|
|
|
@ -406,11 +406,11 @@ func (sf *SnowflakeProxy) makeWebRTCAPI() *webrtc.API {
|
||||||
// candidates is complete and the answer is available in LocalDescription.
|
// candidates is complete and the answer is available in LocalDescription.
|
||||||
// Installs an OnDataChannel callback that creates a webRTCConn and passes it to
|
// Installs an OnDataChannel callback that creates a webRTCConn and passes it to
|
||||||
// datachannelHandler.
|
// datachannelHandler.
|
||||||
func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescription,
|
func (sf *SnowflakeProxy) makePeerConnectionFromOffer(
|
||||||
config webrtc.Configuration,
|
sdp *webrtc.SessionDescription,
|
||||||
dataChan chan struct{},
|
config webrtc.Configuration, dataChan chan struct{},
|
||||||
handler func(conn *webRTCConn, remoteAddr net.Addr)) (*webrtc.PeerConnection, error) {
|
handler func(conn *webRTCConn, remoteAddr net.Addr),
|
||||||
|
) (*webrtc.PeerConnection, error) {
|
||||||
api := sf.makeWebRTCAPI()
|
api := sf.makeWebRTCAPI()
|
||||||
pc, err := api.NewPeerConnection(config)
|
pc, err := api.NewPeerConnection(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -523,9 +523,9 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
|
||||||
|
|
||||||
// Create a new PeerConnection. Blocks until the gathering of ICE
|
// Create a new PeerConnection. Blocks until the gathering of ICE
|
||||||
// candidates is complete and the answer is available in LocalDescription.
|
// candidates is complete and the answer is available in LocalDescription.
|
||||||
func (sf *SnowflakeProxy) makeNewPeerConnection(config webrtc.Configuration,
|
func (sf *SnowflakeProxy) makeNewPeerConnection(
|
||||||
dataChan chan struct{}) (*webrtc.PeerConnection, error) {
|
config webrtc.Configuration, dataChan chan struct{},
|
||||||
|
) (*webrtc.PeerConnection, error) {
|
||||||
api := sf.makeWebRTCAPI()
|
api := sf.makeWebRTCAPI()
|
||||||
pc, err := api.NewPeerConnection(config)
|
pc, err := api.NewPeerConnection(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/encapsulation"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/encapsulation"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/websocketconn"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/websocketconn"
|
||||||
|
|
|
@ -46,8 +46,9 @@ import (
|
||||||
|
|
||||||
"github.com/xtaci/kcp-go/v5"
|
"github.com/xtaci/kcp-go/v5"
|
||||||
"github.com/xtaci/smux"
|
"github.com/xtaci/smux"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
|
|
||||||
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue