mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Add Allowed Relay Hostname Pattern Indication
This commit is contained in:
parent
b09a2e09b3
commit
2ebdc89c42
4 changed files with 14 additions and 9 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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, ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue