[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [pluggable-transports/snowflake] 02/02: Make the proxy type configurable for users of the library



This is an automated email from the git hooks/post-receive script.

meskio pushed a commit to branch main
in repository pluggable-transports/snowflake.

commit b73add155074657cb763fcf12a3f7d2e9e22316d
Author: meskio <meskio@xxxxxxxxxxxxxx>
AuthorDate: Fri Mar 11 16:42:05 2022 +0100

    Make the proxy type configurable for users of the library
    
    Closes: #40104
---
 proxy/lib/proxy-go_test.go |  4 ++--
 proxy/lib/snowflake.go     | 16 +++++++++++-----
 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()
 	}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits