mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 18:11:28 +00:00
Fix tcp keep alive
This commit is contained in:
parent
0eed0ca11a
commit
d06fd03dd8
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/sagernet/sing-box/common/warning"
|
"github.com/sagernet/sing-box/common/warning"
|
||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
"github.com/sagernet/sing/common"
|
|
||||||
"github.com/sagernet/sing/common/control"
|
"github.com/sagernet/sing/common/control"
|
||||||
M "github.com/sagernet/sing/common/metadata"
|
M "github.com/sagernet/sing/common/metadata"
|
||||||
N "github.com/sagernet/sing/common/network"
|
N "github.com/sagernet/sing/common/network"
|
||||||
|
@ -113,15 +112,7 @@ func NewDefault(router adapter.Router, options option.DialerOptions) *DefaultDia
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DefaultDialer) DialContext(ctx context.Context, network string, address M.Socksaddr) (net.Conn, error) {
|
func (d *DefaultDialer) DialContext(ctx context.Context, network string, address M.Socksaddr) (net.Conn, error) {
|
||||||
conn, err := d.Dialer.DialContext(ctx, network, address.Unwrap().String())
|
return d.Dialer.DialContext(ctx, network, address.Unwrap().String())
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if tcpConn, isTCP := common.Cast[*net.TCPConn](conn); isTCP {
|
|
||||||
tcpConn.SetKeepAlive(true)
|
|
||||||
tcpConn.SetKeepAlivePeriod(C.TCPKeepAlivePeriod)
|
|
||||||
}
|
|
||||||
return conn, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DefaultDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
func (d *DefaultDialer) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||||
|
|
|
@ -38,8 +38,8 @@ func NewConnection(ctx context.Context, router adapter.Router, errorHandler E.Ha
|
||||||
go func() {
|
go func() {
|
||||||
logger.InfoContext(ctx, "inbound multiplex connection to ", metadata.Destination)
|
logger.InfoContext(ctx, "inbound multiplex connection to ", metadata.Destination)
|
||||||
hErr := router.RouteConnection(ctx, &ServerConn{ExtendedConn: bufio.NewExtendedConn(stream)}, metadata)
|
hErr := router.RouteConnection(ctx, &ServerConn{ExtendedConn: bufio.NewExtendedConn(stream)}, metadata)
|
||||||
|
stream.Close()
|
||||||
if hErr != nil {
|
if hErr != nil {
|
||||||
stream.Close()
|
|
||||||
errorHandler.NewError(ctx, hErr)
|
errorHandler.NewError(ctx, hErr)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -54,8 +54,8 @@ func NewConnection(ctx context.Context, router adapter.Router, errorHandler E.Ha
|
||||||
packetConn = &ServerPacketAddrConn{ExtendedConn: bufio.NewExtendedConn(stream)}
|
packetConn = &ServerPacketAddrConn{ExtendedConn: bufio.NewExtendedConn(stream)}
|
||||||
}
|
}
|
||||||
hErr := router.RoutePacketConnection(ctx, packetConn, metadata)
|
hErr := router.RoutePacketConnection(ctx, packetConn, metadata)
|
||||||
|
stream.Close()
|
||||||
if hErr != nil {
|
if hErr != nil {
|
||||||
stream.Close()
|
|
||||||
errorHandler.NewError(ctx, hErr)
|
errorHandler.NewError(ctx, hErr)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -4,7 +4,6 @@ import "time"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TCPTimeout = 5 * time.Second
|
TCPTimeout = 5 * time.Second
|
||||||
TCPKeepAlivePeriod = 30 * time.Second
|
|
||||||
ReadPayloadTimeout = 300 * time.Millisecond
|
ReadPayloadTimeout = 300 * time.Millisecond
|
||||||
DNSTimeout = 10 * time.Second
|
DNSTimeout = 10 * time.Second
|
||||||
QUICTimeout = 30 * time.Second
|
QUICTimeout = 30 * time.Second
|
||||||
|
|
|
@ -154,8 +154,6 @@ func (a *myInboundAdapter) loopTCPIn() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
conn.SetKeepAlive(true)
|
|
||||||
conn.SetKeepAlivePeriod(C.TCPKeepAlivePeriod)
|
|
||||||
go func() {
|
go func() {
|
||||||
ctx := log.ContextWithNewID(a.ctx)
|
ctx := log.ContextWithNewID(a.ctx)
|
||||||
var metadata adapter.InboundContext
|
var metadata adapter.InboundContext
|
||||||
|
|
Loading…
Reference in a new issue