mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Use a config struct for snowflake client options
This commit is contained in:
parent
e6715cb4ee
commit
4acc08cc60
2 changed files with 23 additions and 8 deletions
|
@ -37,17 +37,25 @@ type Transport struct {
|
|||
dialer *WebRTCDialer
|
||||
}
|
||||
|
||||
type ClientConfig struct {
|
||||
BrokerURL string
|
||||
AmpCacheURL string
|
||||
FrontDomain string
|
||||
ICEAddresses []string
|
||||
KeepLocalAddresses bool
|
||||
Max int
|
||||
}
|
||||
|
||||
// Create a new Snowflake transport client that can spawn multiple Snowflake connections.
|
||||
// brokerURL and frontDomain are the urls for the broker host and domain fronting host
|
||||
// iceAddresses are the STUN/TURN urls needed for WebRTC negotiation
|
||||
// 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(brokerURL, ampCacheURL, frontDomain string,
|
||||
iceAddresses []string, keepLocalAddresses bool, max int) (*Transport, error) {
|
||||
func NewSnowflakeClient(config ClientConfig) (*Transport, error) {
|
||||
|
||||
log.Println("\n\n\n --- Starting Snowflake Client ---")
|
||||
|
||||
iceServers := parseIceServers(iceAddresses)
|
||||
iceServers := parseIceServers(config.ICEAddresses)
|
||||
// chooses a random subset of servers from inputs
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
rand.Shuffle(len(iceServers), func(i, j int) {
|
||||
|
@ -63,14 +71,14 @@ func NewSnowflakeClient(brokerURL, ampCacheURL, frontDomain string,
|
|||
|
||||
// Rendezvous with broker using the given parameters.
|
||||
broker, err := NewBrokerChannel(
|
||||
brokerURL, ampCacheURL, frontDomain, CreateBrokerTransport(),
|
||||
keepLocalAddresses)
|
||||
config.BrokerURL, config.AmpCacheURL, config.FrontDomain, CreateBrokerTransport(),
|
||||
config.KeepLocalAddresses)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
go updateNATType(iceServers, broker)
|
||||
|
||||
transport := &Transport{dialer: NewWebRTCDialer(broker, iceServers, max)}
|
||||
transport := &Transport{dialer: NewWebRTCDialer(broker, iceServers, config.Max)}
|
||||
|
||||
return transport, nil
|
||||
}
|
||||
|
|
|
@ -141,8 +141,15 @@ func main() {
|
|||
|
||||
iceAddresses := strings.Split(strings.TrimSpace(*iceServersCommas), ",")
|
||||
|
||||
transport, err := sf.NewSnowflakeClient(*brokerURL, *ampCacheURL, *frontDomain, iceAddresses,
|
||||
*keepLocalAddresses || *oldKeepLocalAddresses, *max)
|
||||
config := sf.ClientConfig{
|
||||
BrokerURL: *brokerURL,
|
||||
AmpCacheURL: *ampCacheURL,
|
||||
FrontDomain: *frontDomain,
|
||||
ICEAddresses: iceAddresses,
|
||||
KeepLocalAddresses: *keepLocalAddresses || *oldKeepLocalAddresses,
|
||||
Max: *max,
|
||||
}
|
||||
transport, err := sf.NewSnowflakeClient(config)
|
||||
if err != nil {
|
||||
log.Fatal("Failed to start snowflake transport: ", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue