mirror of
https://github.com/SagerNet/sing-quic.git
synced 2025-04-03 03:47:39 +03:00
Fix initial MTU
This commit is contained in:
parent
5eccd25e3c
commit
bd48f62a7b
3 changed files with 5 additions and 19 deletions
|
@ -139,7 +139,7 @@ func newUDPPacketConn(ctx context.Context, quicConn quic.Connection, onDestroy f
|
|||
cancel: cancel,
|
||||
quicConn: quicConn,
|
||||
data: make(chan *udpMessage, 64),
|
||||
udpMTU: 1200,
|
||||
udpMTU: 1200 - 3,
|
||||
defragger: newUDPDefragger(),
|
||||
onDestroy: onDestroy,
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ func newUDPPacketConn(ctx context.Context, quicConn quic.Connection, onDestroy f
|
|||
cancel: cancel,
|
||||
quicConn: quicConn,
|
||||
data: make(chan *udpMessage, 64),
|
||||
udpMTU: 1200,
|
||||
udpMTU: 1200 - 3,
|
||||
defragger: newUDPDefragger(),
|
||||
onDestroy: onDestroy,
|
||||
}
|
||||
|
|
|
@ -128,7 +128,6 @@ type udpPacketConn struct {
|
|||
data chan *udpMessage
|
||||
udpStream bool
|
||||
udpMTU int
|
||||
udpMTUTime time.Time
|
||||
packetId atomic.Uint32
|
||||
closeOnce sync.Once
|
||||
isServer bool
|
||||
|
@ -148,6 +147,7 @@ func newUDPPacketConn(ctx context.Context, quicConn quic.Connection, udpStream b
|
|||
isServer: isServer,
|
||||
defragger: newUDPDefragger(),
|
||||
onDestroy: onDestroy,
|
||||
udpMTU: 1200 - 3,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,18 +179,6 @@ func (c *udpPacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (c *udpPacketConn) needFragment() bool {
|
||||
if c.udpMTU == 0 {
|
||||
return false
|
||||
}
|
||||
nowTime := time.Now()
|
||||
if nowTime.Sub(c.udpMTUTime) < 5*time.Second {
|
||||
c.udpMTUTime = nowTime
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *udpPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
|
||||
defer buffer.Release()
|
||||
select {
|
||||
|
@ -215,7 +203,7 @@ func (c *udpPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr)
|
|||
}
|
||||
defer message.releaseMessage()
|
||||
var err error
|
||||
if !c.udpStream && c.needFragment() && buffer.Len() > c.udpMTU-message.headerSize() {
|
||||
if !c.udpStream && buffer.Len() > c.udpMTU-message.headerSize() {
|
||||
err = c.writePackets(fragUDPMessage(message, c.udpMTU))
|
||||
} else {
|
||||
err = c.writePacket(message)
|
||||
|
@ -228,7 +216,6 @@ func (c *udpPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr)
|
|||
return err
|
||||
}
|
||||
c.udpMTU = int(tooLargeErr) - 3
|
||||
c.udpMTUTime = time.Now()
|
||||
return c.writePackets(fragUDPMessage(message, c.udpMTU))
|
||||
}
|
||||
|
||||
|
@ -254,7 +241,7 @@ func (c *udpPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
|||
destination: destination,
|
||||
data: buf.As(p),
|
||||
}
|
||||
if !c.udpStream && c.needFragment() && len(p) > c.udpMTU-message.headerSize() {
|
||||
if !c.udpStream && len(p) > c.udpMTU-message.headerSize() {
|
||||
err = c.writePackets(fragUDPMessage(message, c.udpMTU))
|
||||
if err == nil {
|
||||
return len(p), nil
|
||||
|
@ -270,7 +257,6 @@ func (c *udpPacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error) {
|
|||
return
|
||||
}
|
||||
c.udpMTU = int(tooLargeErr) - 3
|
||||
c.udpMTUTime = time.Now()
|
||||
err = c.writePackets(fragUDPMessage(message, c.udpMTU))
|
||||
if err == nil {
|
||||
return len(p), nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue