mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20: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 {
|
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
|
_ = relayPattern
|
||||||
|
_ = relayPatternSupported
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return messages.ErrBadRequest
|
return messages.ErrBadRequest
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ func TestDecodeProxyPollRequest(t *testing.T) {
|
||||||
err: fmt.Errorf(""),
|
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(sid, ShouldResemble, test.sid)
|
||||||
So(proxyType, ShouldResemble, test.proxyType)
|
So(proxyType, ShouldResemble, test.proxyType)
|
||||||
So(natType, ShouldResemble, test.natType)
|
So(natType, ShouldResemble, test.natType)
|
||||||
|
|
|
@ -97,7 +97,7 @@ type ProxyPollRequest struct {
|
||||||
NAT string
|
NAT string
|
||||||
Clients int
|
Clients int
|
||||||
|
|
||||||
AcceptedRelayPattern string
|
AcceptedRelayPattern *string
|
||||||
}
|
}
|
||||||
|
|
||||||
func EncodeProxyPollRequest(sid string, proxyType string, natType string, clients int) ([]byte, error) {
|
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,
|
Type: proxyType,
|
||||||
NAT: natType,
|
NAT: natType,
|
||||||
Clients: clients,
|
Clients: clients,
|
||||||
AcceptedRelayPattern: relayPattern,
|
AcceptedRelayPattern: &relayPattern,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func DecodeProxyPollRequest(data []byte) (sid string, proxyType string, natType string, clients int, err error) {
|
func DecodeProxyPollRequest(data []byte) (sid string, proxyType string, natType string, clients int, err error) {
|
||||||
var relayPrefix string
|
var relayPrefix string
|
||||||
sid, proxyType, natType, clients, relayPrefix, err = DecodeProxyPollRequestWithRelayPrefix(data)
|
sid, proxyType, natType, clients, relayPrefix, _, err = DecodeProxyPollRequestWithRelayPrefix(data)
|
||||||
if relayPrefix != "" {
|
if relayPrefix != "" {
|
||||||
return "", "", "", 0, ErrExtraInfo
|
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
|
// sid, proxy type, nat type and clients of the proxy on success
|
||||||
// and an error if it failed
|
// and an error if it failed
|
||||||
func DecodeProxyPollRequestWithRelayPrefix(data []byte) (
|
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
|
var message ProxyPollRequest
|
||||||
|
|
||||||
err = json.Unmarshal(data, &message)
|
err = json.Unmarshal(data, &message)
|
||||||
|
@ -164,8 +164,12 @@ func DecodeProxyPollRequestWithRelayPrefix(data []byte) (
|
||||||
if !KnownProxyTypes[message.Type] {
|
if !KnownProxyTypes[message.Type] {
|
||||||
message.Type = ProxyUnknown
|
message.Type = ProxyUnknown
|
||||||
}
|
}
|
||||||
|
var acceptedRelayPattern = ""
|
||||||
return message.Sid, message.Type, message.NAT, message.Clients, message.AcceptedRelayPattern, nil
|
if message.AcceptedRelayPattern != nil {
|
||||||
|
acceptedRelayPattern = *message.AcceptedRelayPattern
|
||||||
|
}
|
||||||
|
return message.Sid, message.Type, message.NAT, message.Clients,
|
||||||
|
acceptedRelayPattern, message.AcceptedRelayPattern != nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProxyPollResponse struct {
|
type ProxyPollResponse struct {
|
||||||
|
|
|
@ -210,7 +210,7 @@ func (s *SignalingServer) pollOffer(sid string, proxyType string, acceptedRelayP
|
||||||
default:
|
default:
|
||||||
numClients := int((tokens.count() / 8) * 8) // Round down to 8
|
numClients := int((tokens.count() / 8) * 8) // Round down to 8
|
||||||
currentNATTypeLoaded := getCurrentNATType()
|
currentNATTypeLoaded := getCurrentNATType()
|
||||||
body, err := messages.EncodeProxyPollRequest(sid, proxyType, currentNATTypeLoaded, numClients)
|
body, err := messages.EncodeProxyPollRequestWithRelayPrefix(sid, proxyType, currentNATTypeLoaded, numClients, acceptedRelayPattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error encoding poll message: %s", err.Error())
|
log.Printf("Error encoding poll message: %s", err.Error())
|
||||||
return nil, ""
|
return nil, ""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue