mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
use protocol field encoder
This commit is contained in:
parent
fb57ad79f5
commit
00da3c95ed
3 changed files with 12 additions and 7 deletions
|
@ -4,7 +4,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
@ -318,7 +318,12 @@ func (c *WebRTCPeer) preparePeerConnection(
|
||||||
}
|
}
|
||||||
ordered := false
|
ordered := false
|
||||||
var maxRetransmission uint16 = 0
|
var maxRetransmission uint16 = 0
|
||||||
protocol := fmt.Sprintf("%s", c.clientID.String())
|
connectionMetadata := messages.ClientConnectionMetadata{ClientID: c.clientID[:]}
|
||||||
|
encodedMetadata, err := connectionMetadata.EncodeConnectionMetadata()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
protocol := encodedMetadata
|
||||||
dataChannelOptions := &webrtc.DataChannelInit{
|
dataChannelOptions := &webrtc.DataChannelInit{
|
||||||
Ordered: &ordered,
|
Ordered: &ordered,
|
||||||
Protocol: &protocol,
|
Protocol: &protocol,
|
||||||
|
|
|
@ -152,7 +152,7 @@ func DecodeClientPollResponse(data []byte) (*ClientPollResponse, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClientConnectionMetadata struct {
|
type ClientConnectionMetadata struct {
|
||||||
ClientID string `json:"client_id"`
|
ClientID []byte `json:"client_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (meta *ClientConnectionMetadata) EncodeConnectionMetadata() (string, error) {
|
func (meta *ClientConnectionMetadata) EncodeConnectionMetadata() (string, error) {
|
||||||
|
|
|
@ -5,8 +5,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
@ -120,10 +119,11 @@ func (handler *httpHandler) turboTunnelUDPLikeMode(conn net.Conn, addr net.Addr,
|
||||||
// packet received on this WebSocket connection pertains to the same
|
// packet received on this WebSocket connection pertains to the same
|
||||||
// ClientID.
|
// ClientID.
|
||||||
clientID := turbotunnel.ClientID{}
|
clientID := turbotunnel.ClientID{}
|
||||||
_, err := hex.Decode(clientID[:], []byte(protocol))
|
metaData, err := messages.DecodeConnectionMetadata(protocol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("reading ClientID: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
|
copy(clientID[:], metaData.ClientID[:])
|
||||||
|
|
||||||
// Store a short-term mapping from the ClientID to the client IP
|
// Store a short-term mapping from the ClientID to the client IP
|
||||||
// address attached to this WebSocket connection. tor will want us to
|
// address attached to this WebSocket connection. tor will want us to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue