mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -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
|
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.
|
// 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
|
// brokerURL and frontDomain are the urls for the broker host and domain fronting host
|
||||||
// iceAddresses are the STUN/TURN urls needed for WebRTC negotiation
|
// iceAddresses are the STUN/TURN urls needed for WebRTC negotiation
|
||||||
// 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(brokerURL, ampCacheURL, frontDomain string,
|
func NewSnowflakeClient(config ClientConfig) (*Transport, error) {
|
||||||
iceAddresses []string, keepLocalAddresses bool, max int) (*Transport, error) {
|
|
||||||
|
|
||||||
log.Println("\n\n\n --- Starting Snowflake Client ---")
|
log.Println("\n\n\n --- Starting Snowflake Client ---")
|
||||||
|
|
||||||
iceServers := parseIceServers(iceAddresses)
|
iceServers := parseIceServers(config.ICEAddresses)
|
||||||
// chooses a random subset of servers from inputs
|
// chooses a random subset of servers from inputs
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
rand.Shuffle(len(iceServers), func(i, j int) {
|
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.
|
// Rendezvous with broker using the given parameters.
|
||||||
broker, err := NewBrokerChannel(
|
broker, err := NewBrokerChannel(
|
||||||
brokerURL, ampCacheURL, frontDomain, CreateBrokerTransport(),
|
config.BrokerURL, config.AmpCacheURL, config.FrontDomain, CreateBrokerTransport(),
|
||||||
keepLocalAddresses)
|
config.KeepLocalAddresses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
go updateNATType(iceServers, broker)
|
go updateNATType(iceServers, broker)
|
||||||
|
|
||||||
transport := &Transport{dialer: NewWebRTCDialer(broker, iceServers, max)}
|
transport := &Transport{dialer: NewWebRTCDialer(broker, iceServers, config.Max)}
|
||||||
|
|
||||||
return transport, nil
|
return transport, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,8 +141,15 @@ func main() {
|
||||||
|
|
||||||
iceAddresses := strings.Split(strings.TrimSpace(*iceServersCommas), ",")
|
iceAddresses := strings.Split(strings.TrimSpace(*iceServersCommas), ",")
|
||||||
|
|
||||||
transport, err := sf.NewSnowflakeClient(*brokerURL, *ampCacheURL, *frontDomain, iceAddresses,
|
config := sf.ClientConfig{
|
||||||
*keepLocalAddresses || *oldKeepLocalAddresses, *max)
|
BrokerURL: *brokerURL,
|
||||||
|
AmpCacheURL: *ampCacheURL,
|
||||||
|
FrontDomain: *frontDomain,
|
||||||
|
ICEAddresses: iceAddresses,
|
||||||
|
KeepLocalAddresses: *keepLocalAddresses || *oldKeepLocalAddresses,
|
||||||
|
Max: *max,
|
||||||
|
}
|
||||||
|
transport, err := sf.NewSnowflakeClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Failed to start snowflake transport: ", err)
|
log.Fatal("Failed to start snowflake transport: ", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue