mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
fix broken http tcp like mode *2
This commit is contained in:
parent
85017bc292
commit
b9cb3c9002
1 changed files with 28 additions and 0 deletions
|
@ -2,6 +2,7 @@ package snowflake_server
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/hmac"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
|
@ -131,6 +132,33 @@ func (handler *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
// their stream. These clients expect to send and receive encapsulated packets,
|
||||
// with a long-lived session identified by ClientID.
|
||||
func (handler *httpHandler) turbotunnelMode(conn net.Conn, addr net.Addr) error {
|
||||
{
|
||||
var err error
|
||||
var token [len(turbotunnel.Token)]byte
|
||||
_, err = io.ReadFull(conn, token[:])
|
||||
if err != nil {
|
||||
// Don't bother logging EOF: that happens with an unused
|
||||
// connection, which clients make frequently as they maintain a
|
||||
// pool of proxies.
|
||||
if err != io.EOF {
|
||||
log.Printf("reading token: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
switch {
|
||||
case bytes.Equal(token[:], turbotunnel.Token[:]):
|
||||
break
|
||||
default:
|
||||
// We didn't find a matching token, which means that we are
|
||||
// dealing with a client that doesn't know about such things.
|
||||
// Close the conn as we no longer support the old
|
||||
// one-session-per-WebSocket mode.
|
||||
log.Println("Received unsupported oneshot connection")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Read the ClientID prefix. Every packet encapsulated in this WebSocket
|
||||
// connection pertains to the same ClientID.
|
||||
var clientID turbotunnel.ClientID
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue