mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -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/xtaci/kcp-go/v5"
|
||||
"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/nat"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
||||
|
@ -60,7 +61,7 @@ const (
|
|||
// WindowSize is the number of packets in the send and receive window of a KCP connection.
|
||||
WindowSize = 65535
|
||||
// StreamSize controls the maximum amount of in flight data between a client and server.
|
||||
StreamSize = 1048576 //1MB
|
||||
StreamSize = 1048576 // 1MB
|
||||
)
|
||||
|
||||
type dummyAddr struct{}
|
||||
|
@ -122,7 +123,6 @@ type ClientConfig struct {
|
|||
// 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
|
||||
func NewSnowflakeClient(config ClientConfig) (*Transport, error) {
|
||||
|
||||
log.Println("\n\n\n --- Starting Snowflake Client ---")
|
||||
|
||||
iceServers := parseIceServers(config.ICEAddresses)
|
||||
|
@ -212,6 +212,7 @@ func (t *Transport) Dial() (net.Conn, error) {
|
|||
cleanup = nil
|
||||
return &SnowflakeConn{Stream: stream, sess: sess, pconn: pconn, snowflakes: snowflakes}, nil
|
||||
}
|
||||
|
||||
func (t *Transport) AddSnowflakeEventListener(receiver event.SnowflakeEventReceiver) {
|
||||
t.eventDispatcher.AddSnowflakeEventListener(receiver)
|
||||
}
|
||||
|
@ -244,13 +245,12 @@ func (conn *SnowflakeConn) Close() error {
|
|||
conn.pconn.Close()
|
||||
log.Printf("---- SnowflakeConn: discarding finished session ---")
|
||||
conn.sess.Close()
|
||||
return nil //TODO: return errors if any of the above do
|
||||
return nil // TODO: return errors if any of the above do
|
||||
}
|
||||
|
||||
// loop through all provided STUN servers until we exhaust the list or find
|
||||
// one that is compatible with RFC 5780
|
||||
func updateNATType(servers []webrtc.ICEServer, broker *BrokerChannel, proxy *url.URL) {
|
||||
|
||||
var restrictedNAT bool
|
||||
var err error
|
||||
for _, server := range servers {
|
||||
|
|
|
@ -5,8 +5,6 @@ import (
|
|||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/pion/transport/v2"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/proxy"
|
||||
"io"
|
||||
"log"
|
||||
"net/url"
|
||||
|
@ -15,9 +13,12 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/pion/ice/v2"
|
||||
"github.com/pion/transport/v2"
|
||||
"github.com/pion/transport/v2/stdnet"
|
||||
"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/proxy"
|
||||
)
|
||||
|
||||
// WebRTCPeer represents a WebRTC connection to a remote snowflake proxy.
|
||||
|
@ -45,14 +46,17 @@ type WebRTCPeer struct {
|
|||
}
|
||||
|
||||
// Deprecated: Use NewWebRTCPeerWithEventsAndProxy Instead.
|
||||
func NewWebRTCPeer(config *webrtc.Configuration,
|
||||
broker *BrokerChannel) (*WebRTCPeer, error) {
|
||||
func NewWebRTCPeer(
|
||||
config *webrtc.Configuration, broker *BrokerChannel,
|
||||
) (*WebRTCPeer, error) {
|
||||
return NewWebRTCPeerWithEventsAndProxy(config, broker, nil, nil)
|
||||
}
|
||||
|
||||
// Deprecated: Use NewWebRTCPeerWithEventsAndProxy Instead.
|
||||
func NewWebRTCPeerWithEvents(config *webrtc.Configuration,
|
||||
broker *BrokerChannel, eventsLogger event.SnowflakeEventReceiver) (*WebRTCPeer, error) {
|
||||
func NewWebRTCPeerWithEvents(
|
||||
config *webrtc.Configuration, broker *BrokerChannel,
|
||||
eventsLogger event.SnowflakeEventReceiver,
|
||||
) (*WebRTCPeer, error) {
|
||||
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 exchange of SDP information, the creation of a PeerConnection, and the establishment
|
||||
// of a DataChannel to the Snowflake proxy.
|
||||
func NewWebRTCPeerWithEventsAndProxy(config *webrtc.Configuration,
|
||||
broker *BrokerChannel, eventsLogger event.SnowflakeEventReceiver, proxy *url.URL) (*WebRTCPeer, error) {
|
||||
func NewWebRTCPeerWithEventsAndProxy(
|
||||
config *webrtc.Configuration, broker *BrokerChannel,
|
||||
eventsLogger event.SnowflakeEventReceiver, proxy *url.URL,
|
||||
) (*WebRTCPeer, error) {
|
||||
if eventsLogger == nil {
|
||||
eventsLogger = event.NewSnowflakeEventDispatcher()
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/proxy"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
@ -18,8 +17,10 @@ import (
|
|||
"syscall"
|
||||
|
||||
pt "gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib"
|
||||
|
||||
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/proxy"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/safelog"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/version"
|
||||
)
|
||||
|
|
|
@ -78,7 +78,7 @@ const (
|
|||
// client is not going to connect
|
||||
dataChannelTimeout = 20 * time.Second
|
||||
|
||||
//Maximum number of bytes to be read from an HTTP request
|
||||
// Maximum number of bytes to be read from an HTTP request
|
||||
readLimit = 100000
|
||||
|
||||
sessionIDLength = 16
|
||||
|
@ -406,11 +406,11 @@ func (sf *SnowflakeProxy) makeWebRTCAPI() *webrtc.API {
|
|||
// candidates is complete and the answer is available in LocalDescription.
|
||||
// Installs an OnDataChannel callback that creates a webRTCConn and passes it to
|
||||
// datachannelHandler.
|
||||
func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescription,
|
||||
config webrtc.Configuration,
|
||||
dataChan chan struct{},
|
||||
handler func(conn *webRTCConn, remoteAddr net.Addr)) (*webrtc.PeerConnection, error) {
|
||||
|
||||
func (sf *SnowflakeProxy) makePeerConnectionFromOffer(
|
||||
sdp *webrtc.SessionDescription,
|
||||
config webrtc.Configuration, dataChan chan struct{},
|
||||
handler func(conn *webRTCConn, remoteAddr net.Addr),
|
||||
) (*webrtc.PeerConnection, error) {
|
||||
api := sf.makeWebRTCAPI()
|
||||
pc, err := api.NewPeerConnection(config)
|
||||
if err != nil {
|
||||
|
@ -523,9 +523,9 @@ func (sf *SnowflakeProxy) makePeerConnectionFromOffer(sdp *webrtc.SessionDescrip
|
|||
|
||||
// Create a new PeerConnection. Blocks until the gathering of ICE
|
||||
// candidates is complete and the answer is available in LocalDescription.
|
||||
func (sf *SnowflakeProxy) makeNewPeerConnection(config webrtc.Configuration,
|
||||
dataChan chan struct{}) (*webrtc.PeerConnection, error) {
|
||||
|
||||
func (sf *SnowflakeProxy) makeNewPeerConnection(
|
||||
config webrtc.Configuration, dataChan chan struct{},
|
||||
) (*webrtc.PeerConnection, error) {
|
||||
api := sf.makeWebRTCAPI()
|
||||
pc, err := api.NewPeerConnection(config)
|
||||
if err != nil {
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"time"
|
||||
|
||||
"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/turbotunnel"
|
||||
"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/smux"
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
||||
"golang.org/x/net/http2"
|
||||
|
||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue