mirror of https://github.com/v2ray/v2ray-core
tweak quic parameters
parent
e26ae20065
commit
010964f272
|
@ -3,6 +3,7 @@ package quic
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"v2ray.com/core/transport/internet/tls"
|
"v2ray.com/core/transport/internet/tls"
|
||||||
|
|
||||||
|
@ -29,7 +30,12 @@ func (s *clientSessions) getSession(destAddr net.Addr, config *Config, tlsConfig
|
||||||
dest := net.DestinationFromAddr(destAddr)
|
dest := net.DestinationFromAddr(destAddr)
|
||||||
|
|
||||||
if session, found := s.sessions[dest]; found {
|
if session, found := s.sessions[dest]; found {
|
||||||
return session, nil
|
select {
|
||||||
|
case <-session.Context().Done():
|
||||||
|
// Session has been closed. Creating a new one.
|
||||||
|
default:
|
||||||
|
return session, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rawConn, err := internet.ListenSystemPacket(context.Background(), &net.UDPAddr{
|
rawConn, err := internet.ListenSystemPacket(context.Background(), &net.UDPAddr{
|
||||||
|
@ -41,9 +47,14 @@ func (s *clientSessions) getSession(destAddr net.Addr, config *Config, tlsConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
quicConfig := &quic.Config{
|
quicConfig := &quic.Config{
|
||||||
Versions: []quic.VersionNumber{quic.VersionMilestone0_10_0},
|
Versions: []quic.VersionNumber{quic.VersionMilestone0_10_0},
|
||||||
ConnectionIDLength: 12,
|
ConnectionIDLength: 12,
|
||||||
KeepAlive: true,
|
KeepAlive: true,
|
||||||
|
HandshakeTimeout: time.Second * 4,
|
||||||
|
IdleTimeout: time.Second * 300,
|
||||||
|
MaxReceiveStreamFlowControlWindow: 128 * 1024,
|
||||||
|
MaxReceiveConnectionFlowControlWindow: 512 * 1024,
|
||||||
|
MaxIncomingUniStreams: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := wrapSysConn(rawConn, config)
|
conn, err := wrapSysConn(rawConn, config)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package quic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
quic "github.com/lucas-clemente/quic-go"
|
quic "github.com/lucas-clemente/quic-go"
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
|
@ -50,13 +51,13 @@ func (l *Listener) keepAccepting() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Addr implements internet.Listener.Addr.
|
// Addr implements internet.Listener.Addr.
|
||||||
func (v *Listener) Addr() net.Addr {
|
func (l *Listener) Addr() net.Addr {
|
||||||
return v.listener.Addr()
|
return l.listener.Addr()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close implements internet.Listener.Close.
|
// Close implements internet.Listener.Close.
|
||||||
func (v *Listener) Close() error {
|
func (l *Listener) Close() error {
|
||||||
return v.listener.Close()
|
return l.listener.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen creates a new Listener based on configurations.
|
// Listen creates a new Listener based on configurations.
|
||||||
|
@ -83,10 +84,15 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti
|
||||||
}
|
}
|
||||||
|
|
||||||
quicConfig := &quic.Config{
|
quicConfig := &quic.Config{
|
||||||
Versions: []quic.VersionNumber{quic.VersionMilestone0_10_0},
|
Versions: []quic.VersionNumber{quic.VersionMilestone0_10_0},
|
||||||
ConnectionIDLength: 12,
|
ConnectionIDLength: 12,
|
||||||
KeepAlive: true,
|
KeepAlive: true,
|
||||||
AcceptCookie: func(net.Addr, *quic.Cookie) bool { return true },
|
HandshakeTimeout: time.Second * 4,
|
||||||
|
IdleTimeout: time.Second * 300,
|
||||||
|
MaxReceiveStreamFlowControlWindow: 128 * 1024,
|
||||||
|
MaxReceiveConnectionFlowControlWindow: 512 * 1024,
|
||||||
|
MaxIncomingStreams: 256,
|
||||||
|
MaxIncomingUniStreams: -1,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := wrapSysConn(rawConn, config)
|
conn, err := wrapSysConn(rawConn, config)
|
||||||
|
|
Loading…
Reference in New Issue