mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
refactor message boundary constrains
This commit is contained in:
parent
33b3891648
commit
1ba58c864d
6 changed files with 10 additions and 27 deletions
|
@ -12,16 +12,6 @@ type ReadWriteCloserPreservesBoundary interface {
|
||||||
MessageBoundaryPreserved()
|
MessageBoundaryPreserved()
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfirmsReadWriteCloserPreservesMessageBoundary(rwc io.ReadWriteCloser) ReadWriteCloserPreservesBoundary {
|
|
||||||
return &messageBoundaryPreservedReadWriteCloser{rwc}
|
|
||||||
}
|
|
||||||
|
|
||||||
type messageBoundaryPreservedReadWriteCloser struct {
|
|
||||||
io.ReadWriteCloser
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *messageBoundaryPreservedReadWriteCloser) MessageBoundaryPreserved() {}
|
|
||||||
|
|
||||||
var errENOSYS = errors.New("not implemented")
|
var errENOSYS = errors.New("not implemented")
|
||||||
|
|
||||||
func newPacketConnWrapper(localAddr, remoteAddr net.Addr, rwc ReadWriteCloserPreservesBoundary) net.PacketConn {
|
func newPacketConnWrapper(localAddr, remoteAddr net.Addr, rwc ReadWriteCloserPreservesBoundary) net.PacketConn {
|
||||||
|
|
|
@ -344,8 +344,7 @@ func newSession(snowflakes SnowflakeCollector) (net.PacketConn, *smux.Session, e
|
||||||
log.Println("---- Handler: snowflake assigned ----")
|
log.Println("---- Handler: snowflake assigned ----")
|
||||||
|
|
||||||
packetConnWrapper := newPacketConnWrapper(dummyAddr{}, dummyAddr{},
|
packetConnWrapper := newPacketConnWrapper(dummyAddr{}, dummyAddr{},
|
||||||
packetpadding.NewPaddableConnection(
|
packetpadding.NewPaddableConnection(conn,
|
||||||
ConfirmsReadWriteCloserPreservesMessageBoundary(conn),
|
|
||||||
packetpadding.New()))
|
packetpadding.New()))
|
||||||
|
|
||||||
return packetConnWrapper, nil
|
return packetConnWrapper, nil
|
||||||
|
|
|
@ -412,3 +412,5 @@ func (c *WebRTCPeer) cleanup() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *WebRTCPeer) MessageBoundaryPreserved() {}
|
||||||
|
|
|
@ -1,23 +1,14 @@
|
||||||
package packetpadding
|
package packetpadding
|
||||||
|
|
||||||
import "io"
|
import (
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
type ReadWriteCloserPreservesBoundary interface {
|
type ReadWriteCloserPreservesBoundary interface {
|
||||||
io.ReadWriteCloser
|
io.ReadWriteCloser
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@ func (conn *Conn) SetDeadline(t time.Time) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (conn *Conn) MessageBoundaryPreserved() {}
|
||||||
|
|
||||||
func readLoop(w io.Writer, ws *websocket.Conn) error {
|
func readLoop(w io.Writer, ws *websocket.Conn) error {
|
||||||
var buf [2048]byte
|
var buf [2048]byte
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -115,7 +115,7 @@ func (handler *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *httpHandler) turboTunnelUDPLikeMode(conn net.Conn, addr net.Addr, protocol string) error {
|
func (handler *httpHandler) turboTunnelUDPLikeMode(conn *websocketconn.Conn, addr net.Addr, protocol string) error {
|
||||||
// Read the ClientID from the WebRTC data channel protocol string. Every
|
// Read the ClientID from the WebRTC data channel protocol string. Every
|
||||||
// packet received on this WebSocket connection pertains to the same
|
// packet received on this WebSocket connection pertains to the same
|
||||||
// ClientID.
|
// ClientID.
|
||||||
|
@ -143,8 +143,7 @@ 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(
|
connPaddable := packetpadding.NewPaddableConnection(conn, packetpadding.New())
|
||||||
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue