mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
add connection padding on server side
This commit is contained in:
parent
53172a588b
commit
0aa1470e01
3 changed files with 24 additions and 4 deletions
|
@ -28,6 +28,7 @@ package snowflake_client
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/packetpadding"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
@ -342,7 +343,11 @@ func newSession(snowflakes SnowflakeCollector) (net.PacketConn, *smux.Session, e
|
||||||
}
|
}
|
||||||
log.Println("---- Handler: snowflake assigned ----")
|
log.Println("---- Handler: snowflake assigned ----")
|
||||||
|
|
||||||
packetConnWrapper := newPacketConnWrapper(dummyAddr{}, dummyAddr{}, ConfirmsReadWriteCloserPreservesMessageBoundary(conn))
|
packetConnWrapper := newPacketConnWrapper(dummyAddr{}, dummyAddr{},
|
||||||
|
packetpadding.NewPaddableConnection(
|
||||||
|
ConfirmsReadWriteCloserPreservesMessageBoundary(conn),
|
||||||
|
packetpadding.New()))
|
||||||
|
|
||||||
return packetConnWrapper, nil
|
return packetConnWrapper, nil
|
||||||
}
|
}
|
||||||
pconn := turbotunnel.NewRedialPacketConn(dummyAddr{}, dummyAddr{}, dialContext)
|
pconn := turbotunnel.NewRedialPacketConn(dummyAddr{}, dummyAddr{}, dialContext)
|
||||||
|
|
|
@ -7,6 +7,17 @@ type ReadWriteCloserPreservesBoundary interface {
|
||||||
MessageBoundaryPreserved()
|
MessageBoundaryPreserved()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type messageBoundaryPreservedReadWriteCloser struct {
|
||||||
|
io.ReadWriteCloser
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *messageBoundaryPreservedReadWriteCloser) MessageBoundaryPreserved() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConfirmsReadWriteCloserPreservesMessageBoundary(rwc io.ReadWriteCloser) ReadWriteCloserPreservesBoundary {
|
||||||
|
return &messageBoundaryPreservedReadWriteCloser{rwc}
|
||||||
|
}
|
||||||
|
|
||||||
type PaddableConnection interface {
|
type PaddableConnection interface {
|
||||||
ReadWriteCloserPreservesBoundary
|
ReadWriteCloserPreservesBoundary
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/packetpadding"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
@ -15,6 +15,7 @@ import (
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
|
||||||
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/turbotunnel"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/websocketconn"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/websocketconn"
|
||||||
)
|
)
|
||||||
|
@ -142,6 +143,9 @@ func (handler *httpHandler) turboTunnelUDPLikeMode(conn net.Conn, addr net.Addr,
|
||||||
wg.Add(2)
|
wg.Add(2)
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
connPaddable := packetpadding.NewPaddableConnection(
|
||||||
|
packetpadding.ConfirmsReadWriteCloserPreservesMessageBoundary(conn), packetpadding.New())
|
||||||
|
|
||||||
// The remainder of the WebSocket stream consists of packets, one packet
|
// The remainder of the WebSocket stream consists of packets, one packet
|
||||||
// per WebSocket message. We read them one by one and feed them into the
|
// per WebSocket message. We read them one by one and feed them into the
|
||||||
// QueuePacketConn on which kcp.ServeConn was set up, which eventually
|
// QueuePacketConn on which kcp.ServeConn was set up, which eventually
|
||||||
|
@ -151,7 +155,7 @@ func (handler *httpHandler) turboTunnelUDPLikeMode(conn net.Conn, addr net.Addr,
|
||||||
defer close(done) // Signal the write loop to finish
|
defer close(done) // Signal the write loop to finish
|
||||||
var p [2048]byte
|
var p [2048]byte
|
||||||
for {
|
for {
|
||||||
n, err := conn.Read(p[:])
|
n, err := connPaddable.Read(p[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -173,7 +177,7 @@ func (handler *httpHandler) turboTunnelUDPLikeMode(conn net.Conn, addr net.Addr,
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, err := conn.Write(p)
|
_, err := connPaddable.Write(p)
|
||||||
pconn.Restore(p)
|
pconn.Restore(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue