Просмотр исходного кода

Support UDP receive buffer size optimization

Rod Hynes 5 лет назад
Родитель
Сommit
b991019417
1 измененных файлов с 31 добавлено и 0 удалено
  1. 31 0
      psiphon/common/quic/quic.go

+ 31 - 0
psiphon/common/quic/quic.go

@@ -51,6 +51,7 @@ import (
 	"net/http"
 	"sync"
 	"sync/atomic"
+	"syscall"
 	"time"
 
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
@@ -861,6 +862,36 @@ func (conn *muxPacketConn) SetWriteDeadline(t time.Time) error {
 	return errors.TraceNew("not supported")
 }
 
+// SetReadBuffer and SyscallConn provide passthroughs to the underlying
+// net.UDPConn implementations, used to optimize the UDP receive buffer size.
+// See https://github.com/lucas-clemente/quic-go/wiki/UDP-Receive-Buffer-Size
+// and ietf_quic.setReceiveBuffer. Only the IETF stack will access these
+// functions.
+//
+// Limitation: due to the relayPackets/ReadFrom scheme, this simple
+// passthrough does not suffice to provide access to ReadMsgUDP for
+// https://godoc.org/github.com/lucas-clemente/quic-go#ECNCapablePacketConn.
+
+func (conn *muxPacketConn) SetReadBuffer(bytes int) error {
+	c, ok := conn.listener.conn.PacketConn.(interface {
+		SetReadBuffer(int) error
+	})
+	if !ok {
+		return errors.TraceNew("not supported")
+	}
+	return c.SetReadBuffer(bytes)
+}
+
+func (conn *muxPacketConn) SyscallConn() (syscall.RawConn, error) {
+	c, ok := conn.listener.conn.PacketConn.(interface {
+		SyscallConn() (syscall.RawConn, error)
+	})
+	if !ok {
+		return nil, errors.TraceNew("not supported")
+	}
+	return c.SyscallConn()
+}
+
 // muxListener is a multiplexing packet conn listener which relays packets to
 // multiple quic-go listeners.
 type muxListener struct {