mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
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.
This commit is contained in:
parent
b73add1550
commit
281d917beb
6 changed files with 22 additions and 53 deletions
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue