mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Merge remote-tracking branch 'gitlab/main'
This commit is contained in:
commit
f723cf52e8
5 changed files with 127 additions and 28 deletions
|
@ -69,10 +69,10 @@ type httpHandler struct {
|
|||
|
||||
// newHTTPHandler creates a new http.Handler that exchanges encapsulated packets
|
||||
// over incoming WebSocket connections.
|
||||
func newHTTPHandler(localAddr net.Addr, numInstances int) *httpHandler {
|
||||
func newHTTPHandler(localAddr net.Addr, numInstances int, mtu int) *httpHandler {
|
||||
pconns := make([]*turbotunnel.QueuePacketConn, 0, numInstances)
|
||||
for i := 0; i < numInstances; i++ {
|
||||
pconns = append(pconns, turbotunnel.NewQueuePacketConn(localAddr, clientMapTimeout))
|
||||
pconns = append(pconns, turbotunnel.NewQueuePacketConn(localAddr, clientMapTimeout, mtu))
|
||||
}
|
||||
|
||||
clientIDLookupKey := make([]byte, 16)
|
||||
|
@ -200,6 +200,7 @@ func (handler *httpHandler) turbotunnelMode(conn net.Conn, addr net.Addr) error
|
|||
return
|
||||
}
|
||||
_, err := encapsulation.WriteData(bw, p)
|
||||
pconn.Restore(p)
|
||||
if err == nil {
|
||||
err = bw.Flush()
|
||||
}
|
||||
|
|
|
@ -79,7 +79,11 @@ func (t *Transport) Listen(addr net.Addr, numKCPInstances int) (*SnowflakeListen
|
|||
ln: make([]*kcp.Listener, 0, numKCPInstances),
|
||||
}
|
||||
|
||||
handler := newHTTPHandler(addr, numKCPInstances)
|
||||
// kcp-go doesn't provide an accessor for the current MTU setting (and
|
||||
// anyway we could not create a kcp.Listener without creating a
|
||||
// net.PacketConn for it first), so assume the default kcp.IKCP_MTU_DEF
|
||||
// (1400 bytes) and don't increase it elsewhere.
|
||||
handler := newHTTPHandler(addr, numKCPInstances, kcp.IKCP_MTU_DEF)
|
||||
server := &http.Server{
|
||||
Addr: addr.String(),
|
||||
Handler: handler,
|
||||
|
@ -125,13 +129,15 @@ func (t *Transport) Listen(addr net.Addr, numKCPInstances int) (*SnowflakeListen
|
|||
errChan <- err
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case err = <-errChan:
|
||||
break
|
||||
case <-time.After(listenAndServeErrorTimeout):
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
listener.server = server
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package main
|
||||
|
||||
// This code handled periodic statistics logging.
|
||||
// This code handles periodic statistics logging.
|
||||
//
|
||||
// The only thing it keeps track of is how many connections had the client_ip
|
||||
// parameter. Write true to statsChannel to record a connection with client_ip;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue