mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Introduce an unexported newBrokerChannelFromConfig
A follow-up wants to pass in a new property from the ClientConfig but it would be an API breaking change to NewBrokerChannel. However, it's unclear why NewBrokerChannel is exported at all. No other package in the repo depends on it and the known users of the library probably wouldn't be construct them. While this patch was being reviewed, a new constructor was added, NewBrokerChannelWithUTLSSettings, with effectively the same issue. Both of those exported ones are deleted here.
This commit is contained in:
parent
829cacac5f
commit
bd636a1374
2 changed files with 17 additions and 25 deletions
|
@ -55,40 +55,34 @@ func createBrokerTransport() http.RoundTripper {
|
||||||
return transport
|
return transport
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBrokerChannel(broker, ampCache, front string, keepLocalAddresses bool) (*BrokerChannel, error) {
|
func newBrokerChannelFromConfig(config ClientConfig) (*BrokerChannel, error) {
|
||||||
return NewBrokerChannelWithUTLSSettings(broker, ampCache, front, keepLocalAddresses, "", false)
|
log.Println("Rendezvous using Broker at:", config.BrokerURL)
|
||||||
}
|
|
||||||
|
|
||||||
// NewBrokerChannelWithUTLSSettings construct a new BrokerChannel, where:
|
if config.FrontDomain != "" {
|
||||||
// |broker| is the full URL of the facilitating program which assigns proxies
|
log.Println("Domain fronting using:", config.FrontDomain)
|
||||||
// to clients, and |front| is the option fronting domain.
|
|
||||||
func NewBrokerChannelWithUTLSSettings(broker, ampCache, front string, keepLocalAddresses bool,
|
|
||||||
uTLSClientID string, removeSNI bool) (*BrokerChannel, error) {
|
|
||||||
log.Println("Rendezvous using Broker at:", broker)
|
|
||||||
if ampCache != "" {
|
|
||||||
log.Println("Through AMP cache at:", ampCache)
|
|
||||||
}
|
|
||||||
if front != "" {
|
|
||||||
log.Println("Domain fronting using:", front)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
brokerTransport := createBrokerTransport()
|
brokerTransport := createBrokerTransport()
|
||||||
|
|
||||||
if uTLSClientID != "" {
|
if config.UTLSClientID != "" {
|
||||||
utlsClientHelloID, err := utlsutil.NameToUTLSID(uTLSClientID)
|
utlsClientHelloID, err := utlsutil.NameToUTLSID(config.UTLSClientID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to create broker channel: %v", err)
|
return nil, fmt.Errorf("unable to create broker channel: %v", err)
|
||||||
}
|
}
|
||||||
config := &utls.Config{}
|
utlsConfig := &utls.Config{}
|
||||||
brokerTransport = utlsutil.NewUTLSHTTPRoundTripper(utlsClientHelloID, config, brokerTransport, removeSNI)
|
brokerTransport = utlsutil.NewUTLSHTTPRoundTripper(utlsClientHelloID, utlsConfig, brokerTransport, config.UTLSRemoveSNI)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rendezvous RendezvousMethod
|
var rendezvous RendezvousMethod
|
||||||
var err error
|
var err error
|
||||||
if ampCache != "" {
|
if config.AmpCacheURL != "" {
|
||||||
rendezvous, err = newAMPCacheRendezvous(broker, ampCache, front, brokerTransport)
|
log.Println("Through AMP cache at:", config.AmpCacheURL)
|
||||||
|
rendezvous, err = newAMPCacheRendezvous(
|
||||||
|
config.BrokerURL, config.AmpCacheURL, config.FrontDomain,
|
||||||
|
brokerTransport)
|
||||||
} else {
|
} else {
|
||||||
rendezvous, err = newHTTPRendezvous(broker, front, brokerTransport)
|
rendezvous, err = newHTTPRendezvous(
|
||||||
|
config.BrokerURL, config.FrontDomain, brokerTransport)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -96,7 +90,7 @@ func NewBrokerChannelWithUTLSSettings(broker, ampCache, front string, keepLocalA
|
||||||
|
|
||||||
return &BrokerChannel{
|
return &BrokerChannel{
|
||||||
Rendezvous: rendezvous,
|
Rendezvous: rendezvous,
|
||||||
keepLocalAddresses: keepLocalAddresses,
|
keepLocalAddresses: config.KeepLocalAddresses,
|
||||||
natType: nat.NATUnknown,
|
natType: nat.NATUnknown,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,9 +131,7 @@ func NewSnowflakeClient(config ClientConfig) (*Transport, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendezvous with broker using the given parameters.
|
// Rendezvous with broker using the given parameters.
|
||||||
broker, err := NewBrokerChannelWithUTLSSettings(
|
broker, err := newBrokerChannelFromConfig(config)
|
||||||
config.BrokerURL, config.AmpCacheURL, config.FrontDomain,
|
|
||||||
config.KeepLocalAddresses, config.UTLSClientID, config.UTLSRemoveSNI)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue