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

[tor-commits] [pluggable-transports/snowflake] 01/03: Stop storing version in ClientPollRequest



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

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

commit 281d917bebe19642914ec94d7d5ef911f03c8f57
Author: Arlo Breault <arlolra@xxxxxxxxx>
AuthorDate: Wed Mar 16 20:26:40 2022 -0400

    Stop storing version in ClientPollRequest
    
    This continues to asserts the known version while decoding.  The client
    will only ever generate the latest version while encoding and if the
    response needs to change, the impetus will be a new feature, set in the
    deserialized request, which can be used as a distinguisher.
---
 broker/http.go                   |  5 ++---
 broker/ipc.go                    | 39 +++++++++------------------------------
 client/lib/rendezvous.go         |  5 ++---
 client/lib/rendezvous_test.go    |  5 ++---
 common/messages/client.go        | 16 +++++-----------
 common/messages/messages_test.go |  5 ++---
 6 files changed, 22 insertions(+), 53 deletions(-)

diff --git a/broker/http.go b/broker/http.go
index 7acc465..3b0ba1f 100644
--- a/broker/http.go
+++ b/broker/http.go
@@ -146,9 +146,8 @@ func clientOffers(i *IPC, w http.ResponseWriter, r *http.Request) {
 	if len(body) > 0 && body[0] == '{' {
 		isLegacy = true
 		req := messages.ClientPollRequest{
-			Offer:   string(body),
-			NAT:     r.Header.Get("Snowflake-NAT-Type"),
-			Version: messages.ClientVersion1_0,
+			Offer: string(body),
+			NAT:   r.Header.Get("Snowflake-NAT-Type"),
 		}
 		body, err = req.EncodeClientPollRequest()
 		if err != nil {
diff --git a/broker/ipc.go b/broker/ipc.go
index 9b47b90..5cc595b 100644
--- a/broker/ipc.go
+++ b/broker/ipc.go
@@ -129,15 +129,9 @@ func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
 		return sendClientResponse(&messages.ClientPollResponse{Error: err.Error()}, response)
 	}
 
-	var offer *ClientOffer
-	switch req.Version {
-	case messages.ClientVersion1_0:
-		offer = &ClientOffer{
-			natType: req.NAT,
-			sdp:     []byte(req.Offer),
-		}
-	default:
-		panic("unknown version")
+	offer := &ClientOffer{
+		natType: req.NAT,
+		sdp:     []byte(req.Offer),
 	}
 
 	// Only hand out known restricted snowflakes to unrestricted clients
@@ -162,13 +156,8 @@ func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
 			i.ctx.metrics.clientRestrictedDeniedCount++
 		}
 		i.ctx.metrics.lock.Unlock()
-		switch req.Version {
-		case messages.ClientVersion1_0:
-			resp := &messages.ClientPollResponse{Error: messages.StrNoProxies}
-			return sendClientResponse(resp, response)
-		default:
-			panic("unknown version")
-		}
+		resp := &messages.ClientPollResponse{Error: messages.StrNoProxies}
+		return sendClientResponse(resp, response)
 	}
 
 	// Otherwise, find the most available snowflake proxy, and pass the offer to it.
@@ -185,24 +174,14 @@ func (i *IPC) ClientOffers(arg messages.Arg, response *[]byte) error {
 		i.ctx.metrics.clientProxyMatchCount++
 		i.ctx.metrics.promMetrics.ClientPollTotal.With(prometheus.Labels{"nat": offer.natType, "status": "matched"}).Inc()
 		i.ctx.metrics.lock.Unlock()
-		switch req.Version {
-		case messages.ClientVersion1_0:
-			resp := &messages.ClientPollResponse{Answer: answer}
-			err = sendClientResponse(resp, response)
-		default:
-			panic("unknown version")
-		}
+		resp := &messages.ClientPollResponse{Answer: answer}
+		err = sendClientResponse(resp, response)
 		// Initial tracking of elapsed time.
 		i.ctx.metrics.clientRoundtripEstimate = time.Since(startTime) / time.Millisecond
 	case <-time.After(time.Second * ClientTimeout):
 		log.Println("Client: Timed out.")
-		switch req.Version {
-		case messages.ClientVersion1_0:
-			resp := &messages.ClientPollResponse{Error: messages.StrTimedOut}
-			err = sendClientResponse(resp, response)
-		default:
-			panic("unknown version")
-		}
+		resp := &messages.ClientPollResponse{Error: messages.StrTimedOut}
+		err = sendClientResponse(resp, response)
 	}
 
 	i.ctx.snowflakeLock.Lock()
diff --git a/client/lib/rendezvous.go b/client/lib/rendezvous.go
index 73c62ed..d908b77 100644
--- a/client/lib/rendezvous.go
+++ b/client/lib/rendezvous.go
@@ -116,9 +116,8 @@ func (bc *BrokerChannel) Negotiate(offer *webrtc.SessionDescription) (
 	// Encode the client poll request.
 	bc.lock.Lock()
 	req := &messages.ClientPollRequest{
-		Offer:   offerSDP,
-		NAT:     bc.natType,
-		Version: messages.ClientVersion1_0,
+		Offer: offerSDP,
+		NAT:   bc.natType,
 	}
 	encReq, err := req.EncodeClientPollRequest()
 	bc.lock.Unlock()
diff --git a/client/lib/rendezvous_test.go b/client/lib/rendezvous_test.go
index a233e7d..21b9f57 100644
--- a/client/lib/rendezvous_test.go
+++ b/client/lib/rendezvous_test.go
@@ -43,9 +43,8 @@ func (t errorTransport) RoundTrip(req *http.Request) (*http.Response, error) {
 // offer.
 func makeEncPollReq(offer string) []byte {
 	encPollReq, err := (&messages.ClientPollRequest{
-		Offer:   offer,
-		NAT:     nat.NATUnknown,
-		Version: messages.ClientVersion1_0,
+		Offer: offer,
+		NAT:   nat.NATUnknown,
 	}).EncodeClientPollRequest()
 	if err != nil {
 		panic(err)
diff --git a/common/messages/client.go b/common/messages/client.go
index 2a35594..b6155f7 100644
--- a/common/messages/client.go
+++ b/common/messages/client.go
@@ -11,7 +11,7 @@ import (
 	"git.torproject.org/pluggable-transports/snowflake.git/v2/common/nat"
 )
 
-const ClientVersion1_0 = "1.0"
+const ClientVersion = "1.0"
 
 /* Client--Broker protocol v1.x specification:
 
@@ -50,21 +50,17 @@ for the error.
 */
 
 type ClientPollRequest struct {
-	Offer   string `json:"offer"`
-	NAT     string `json:"nat"`
-	Version string `json:"-"`
+	Offer string `json:"offer"`
+	NAT   string `json:"nat"`
 }
 
 // Encodes a poll message from a snowflake client
 func (req *ClientPollRequest) EncodeClientPollRequest() ([]byte, error) {
-	if req.Version != ClientVersion1_0 {
-		return nil, fmt.Errorf("unsupported message version")
-	}
 	body, err := json.Marshal(req)
 	if err != nil {
 		return nil, err
 	}
-	return append([]byte(req.Version+"\n"), body...), nil
+	return append([]byte(ClientVersion+"\n"), body...), nil
 }
 
 // Decodes a poll message from a snowflake client
@@ -78,9 +74,7 @@ func DecodeClientPollRequest(data []byte) (*ClientPollRequest, error) {
 
 	var message ClientPollRequest
 
-	if string(parts[0]) == ClientVersion1_0 {
-		message.Version = ClientVersion1_0
-	} else {
+	if string(parts[0]) != ClientVersion {
 		return nil, fmt.Errorf("unsupported message version")
 	}
 
diff --git a/common/messages/messages_test.go b/common/messages/messages_test.go
index e0aa2a8..ae0d4f9 100644
--- a/common/messages/messages_test.go
+++ b/common/messages/messages_test.go
@@ -327,9 +327,8 @@ func TestDecodeClientPollRequest(t *testing.T) {
 func TestEncodeClientPollRequests(t *testing.T) {
 	Convey("Context", t, func() {
 		req1 := &ClientPollRequest{
-			NAT:     "unknown",
-			Offer:   "fake",
-			Version: ClientVersion1_0,
+			NAT:   "unknown",
+			Offer: "fake",
 		}
 		b, err := req1.EncodeClientPollRequest()
 		So(err, ShouldEqual, nil)

-- 
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