aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormeskio <meskio@torproject.org>2022-03-11 16:42:05 +0100
committermeskio <meskio@torproject.org>2022-03-21 19:24:51 +0100
commitb73add155074657cb763fcf12a3f7d2e9e22316d (patch)
treedb64316147842853a811f7c9d8976bd82f2360a9
parentb265bd3092742bb0f71acffa52c0f5b7b8216a10 (diff)
downloadsnowflake-b73add155074657cb763fcf12a3f7d2e9e22316d.tar.gz
snowflake-b73add155074657cb763fcf12a3f7d2e9e22316d.zip
Make the proxy type configurable for users of the library
Closes: #40104
-rw-r--r--proxy/lib/proxy-go_test.go4
-rw-r--r--proxy/lib/snowflake.go16
2 files changed, 13 insertions, 7 deletions
diff --git a/proxy/lib/proxy-go_test.go b/proxy/lib/proxy-go_test.go
index 86616c4..f4cbfbf 100644
--- a/proxy/lib/proxy-go_test.go
+++ b/proxy/lib/proxy-go_test.go
@@ -365,7 +365,7 @@ func TestBrokerInteractions(t *testing.T) {
b,
}
- sdp := broker.pollOffer(sampleOffer, nil)
+ sdp := broker.pollOffer(sampleOffer, DefaultProxyType, nil)
expectedSDP, _ := strconv.Unquote(sampleSDP)
So(sdp.SDP, ShouldResemble, expectedSDP)
})
@@ -379,7 +379,7 @@ func TestBrokerInteractions(t *testing.T) {
b,
}
- sdp := broker.pollOffer(sampleOffer, nil)
+ sdp := broker.pollOffer(sampleOffer, DefaultProxyType, nil)
So(sdp, ShouldBeNil)
})
Convey("sends answer to broker", func() {
diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go
index ae9d5bf..17f0126 100644
--- a/proxy/lib/snowflake.go
+++ b/proxy/lib/snowflake.go
@@ -56,6 +56,7 @@ const DefaultNATProbeURL = "https://snowflake-broker.torproject.net:8443/probe"
const DefaultRelayURL = "wss://snowflake.bamsoftware.com/"
const DefaultSTUNURL = "stun:stun.stunprotocol.org:3478"
+const DefaultProxyType = "standalone"
const pollInterval = 5 * time.Second
const (
@@ -115,8 +116,10 @@ type SnowflakeProxy struct {
NATProbeURL string
// NATTypeMeasurementInterval is time before NAT type is retested
NATTypeMeasurementInterval time.Duration
- EventDispatcher event.SnowflakeEventDispatcher
- shutdown chan struct{}
+ // ProxyType is the type reported to the broker, if not provided it "standalone" will be used
+ ProxyType string
+ EventDispatcher event.SnowflakeEventDispatcher
+ shutdown chan struct{}
}
// Checks whether an IP address is a remote address for the client
@@ -185,7 +188,7 @@ func (s *SignalingServer) Post(path string, payload io.Reader) ([]byte, error) {
return limitedRead(resp.Body, readLimit)
}
-func (s *SignalingServer) pollOffer(sid string, shutdown chan struct{}) *webrtc.SessionDescription {
+func (s *SignalingServer) pollOffer(sid string, proxyType string, shutdown chan struct{}) *webrtc.SessionDescription {
brokerPath := s.url.ResolveReference(&url.URL{Path: "proxy"})
ticker := time.NewTicker(pollInterval)
@@ -199,7 +202,7 @@ func (s *SignalingServer) pollOffer(sid string, shutdown chan struct{}) *webrtc.
default:
numClients := int((tokens.count() / 8) * 8) // Round down to 8
currentNATTypeLoaded := getCurrentNATType()
- body, err := messages.EncodeProxyPollRequest(sid, "standalone", currentNATTypeLoaded, numClients)
+ body, err := messages.EncodeProxyPollRequest(sid, proxyType, currentNATTypeLoaded, numClients)
if err != nil {
log.Printf("Error encoding poll message: %s", err.Error())
return nil
@@ -467,7 +470,7 @@ func (sf *SnowflakeProxy) makeNewPeerConnection(config webrtc.Configuration,
}
func (sf *SnowflakeProxy) runSession(sid string) {
- offer := broker.pollOffer(sid, sf.shutdown)
+ offer := broker.pollOffer(sid, sf.ProxyType, sf.shutdown)
if offer == nil {
log.Printf("bad offer from broker")
tokens.ret()
@@ -525,6 +528,9 @@ func (sf *SnowflakeProxy) Start() error {
if sf.NATProbeURL == "" {
sf.NATProbeURL = DefaultNATProbeURL
}
+ if sf.ProxyType == "" {
+ sf.ProxyType = DefaultProxyType
+ }
if sf.EventDispatcher == nil {
sf.EventDispatcher = event.NewSnowflakeEventDispatcher()
}