mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
add server side support for extra data based client id
This commit is contained in:
parent
bf165264b1
commit
c7ccaa38f9
1 changed files with 18 additions and 12 deletions
|
@ -7,11 +7,13 @@ import (
|
|||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -108,10 +110,16 @@ func (handler *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
// Pass the address of client as the remote address of incoming connection
|
||||
clientIPParam := r.URL.Query().Get("client_ip")
|
||||
addr := clientAddr(clientIPParam)
|
||||
clientTransport := r.URL.Query().Get("protocol")
|
||||
protocol := r.URL.Query().Get("protocol")
|
||||
|
||||
clientTransport := "t"
|
||||
|
||||
if protocol != "" {
|
||||
clientTransport = fmt.Sprintf("%c", protocol[0])
|
||||
}
|
||||
|
||||
if clientTransport == "u" {
|
||||
err = handler.turboTunnelUDPLikeMode(conn, addr)
|
||||
err = handler.turboTunnelUDPLikeMode(conn, addr, protocol)
|
||||
if err != nil && err != io.EOF {
|
||||
log.Println(err)
|
||||
return
|
||||
|
@ -231,21 +239,19 @@ func (handler *httpHandler) turbotunnelMode(conn net.Conn, addr net.Addr) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (handler *httpHandler) turboTunnelUDPLikeMode(conn net.Conn, addr net.Addr) error {
|
||||
packetConnIDCon := packetConnIDConnServer{Conn: conn}
|
||||
func (handler *httpHandler) turboTunnelUDPLikeMode(conn net.Conn, addr net.Addr, protocol string) error {
|
||||
var packet [1600]byte
|
||||
n, err := packetConnIDCon.Read(packet[:])
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading ClientID: %v", err)
|
||||
}
|
||||
clientID, err := packetConnIDCon.GetClientID()
|
||||
|
||||
clientID := turbotunnel.ClientID{}
|
||||
compoments := strings.Split(protocol, " ")
|
||||
_, err := hex.Decode(clientID[:], []byte(compoments[1]))
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading ClientID: %v", err)
|
||||
}
|
||||
|
||||
clientIDAddrMap.Set(clientID, addr)
|
||||
|
||||
pconn := handler.lookupPacketConn(clientID)
|
||||
pconn.QueueIncoming(packet[:n], clientID)
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
done := make(chan struct{})
|
||||
|
@ -253,7 +259,7 @@ func (handler *httpHandler) turboTunnelUDPLikeMode(conn net.Conn, addr net.Addr)
|
|||
defer wg.Done()
|
||||
defer close(done) // Signal the write loop to finish
|
||||
for {
|
||||
n, err := packetConnIDCon.Read(packet[:])
|
||||
n, err := conn.Read(packet[:])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
|
@ -272,7 +278,7 @@ func (handler *httpHandler) turboTunnelUDPLikeMode(conn net.Conn, addr net.Addr)
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
_, err := packetConnIDCon.Write(p)
|
||||
_, err := conn.Write(p)
|
||||
pconn.Restore(p)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue