[tor-commits] [pluggable-transports/snowflake] 14/31: Add Allowed Relay Hostname Pattern Indication

gitolite role git at cupani.torproject.org
Thu Jun 16 17:04:01 UTC 2022


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

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

commit 2ebdc89c42dfb1331dd172282b4c2192bfbb4acc
Author: Shelikhoo <xiaokangwang at outlook.com>
AuthorDate: Wed Apr 13 17:51:17 2022 +0100

    Add Allowed Relay Hostname Pattern Indication
---
 broker/ipc.go                    |  3 ++-
 common/messages/messages_test.go |  2 +-
 common/messages/proxy.go         | 16 ++++++++++------
 proxy/lib/snowflake.go           |  2 +-
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/broker/ipc.go b/broker/ipc.go
index 780a9a5..fbaed48 100644
--- a/broker/ipc.go
+++ b/broker/ipc.go
@@ -66,8 +66,9 @@ func (i *IPC) Debug(_ interface{}, response *string) error {
 }
 
 func (i *IPC) ProxyPolls(arg messages.Arg, response *[]byte) error {
-	sid, proxyType, natType, clients, relayPattern, err := messages.DecodeProxyPollRequestWithRelayPrefix(arg.Body)
+	sid, proxyType, natType, clients, relayPattern, relayPatternSupported, err := messages.DecodeProxyPollRequestWithRelayPrefix(arg.Body)
 	_ = relayPattern
+	_ = relayPatternSupported
 	if err != nil {
 		return messages.ErrBadRequest
 	}
diff --git a/common/messages/messages_test.go b/common/messages/messages_test.go
index d1a5e96..017e959 100644
--- a/common/messages/messages_test.go
+++ b/common/messages/messages_test.go
@@ -108,7 +108,7 @@ func TestDecodeProxyPollRequest(t *testing.T) {
 				err:       fmt.Errorf(""),
 			},
 		} {
-			sid, proxyType, natType, clients, relayPattern, err := DecodeProxyPollRequestWithRelayPrefix([]byte(test.data))
+			sid, proxyType, natType, clients, relayPattern, _, err := DecodeProxyPollRequestWithRelayPrefix([]byte(test.data))
 			So(sid, ShouldResemble, test.sid)
 			So(proxyType, ShouldResemble, test.proxyType)
 			So(natType, ShouldResemble, test.natType)
diff --git a/common/messages/proxy.go b/common/messages/proxy.go
index d18a7c3..19cf6a3 100644
--- a/common/messages/proxy.go
+++ b/common/messages/proxy.go
@@ -97,7 +97,7 @@ type ProxyPollRequest struct {
 	NAT     string
 	Clients int
 
-	AcceptedRelayPattern string
+	AcceptedRelayPattern *string
 }
 
 func EncodeProxyPollRequest(sid string, proxyType string, natType string, clients int) ([]byte, error) {
@@ -111,13 +111,13 @@ func EncodeProxyPollRequestWithRelayPrefix(sid string, proxyType string, natType
 		Type:                 proxyType,
 		NAT:                  natType,
 		Clients:              clients,
-		AcceptedRelayPattern: relayPattern,
+		AcceptedRelayPattern: &relayPattern,
 	})
 }
 
 func DecodeProxyPollRequest(data []byte) (sid string, proxyType string, natType string, clients int, err error) {
 	var relayPrefix string
-	sid, proxyType, natType, clients, relayPrefix, err = DecodeProxyPollRequestWithRelayPrefix(data)
+	sid, proxyType, natType, clients, relayPrefix, _, err = DecodeProxyPollRequestWithRelayPrefix(data)
 	if relayPrefix != "" {
 		return "", "", "", 0, ErrExtraInfo
 	}
@@ -128,7 +128,7 @@ func DecodeProxyPollRequest(data []byte) (sid string, proxyType string, natType
 // sid, proxy type, nat type and clients of the proxy on success
 // and an error if it failed
 func DecodeProxyPollRequestWithRelayPrefix(data []byte) (
-	sid string, proxyType string, natType string, clients int, relayPrefix string, err error) {
+	sid string, proxyType string, natType string, clients int, relayPrefix string, relayPrefixAware bool, err error) {
 	var message ProxyPollRequest
 
 	err = json.Unmarshal(data, &message)
@@ -164,8 +164,12 @@ func DecodeProxyPollRequestWithRelayPrefix(data []byte) (
 	if !KnownProxyTypes[message.Type] {
 		message.Type = ProxyUnknown
 	}
-
-	return message.Sid, message.Type, message.NAT, message.Clients, message.AcceptedRelayPattern, nil
+	var acceptedRelayPattern = ""
+	if message.AcceptedRelayPattern != nil {
+		acceptedRelayPattern = *message.AcceptedRelayPattern
+	}
+	return message.Sid, message.Type, message.NAT, message.Clients,
+		acceptedRelayPattern, message.AcceptedRelayPattern != nil, nil
 }
 
 type ProxyPollResponse struct {
diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go
index 7dbc976..a60b5ab 100644
--- a/proxy/lib/snowflake.go
+++ b/proxy/lib/snowflake.go
@@ -210,7 +210,7 @@ func (s *SignalingServer) pollOffer(sid string, proxyType string, acceptedRelayP
 		default:
 			numClients := int((tokens.count() / 8) * 8) // Round down to 8
 			currentNATTypeLoaded := getCurrentNATType()
-			body, err := messages.EncodeProxyPollRequest(sid, proxyType, currentNATTypeLoaded, numClients)
+			body, err := messages.EncodeProxyPollRequestWithRelayPrefix(sid, proxyType, currentNATTypeLoaded, numClients, acceptedRelayPattern)
 			if err != nil {
 				log.Printf("Error encoding poll message: %s", err.Error())
 				return nil, ""

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tor-commits mailing list