diff --git a/common/mux/client.go b/common/mux/client.go index 2f523f70..c66dd7ae 100644 --- a/common/mux/client.go +++ b/common/mux/client.go @@ -249,6 +249,10 @@ func (c *ClientConn) WriterReplaceable() bool { return c.requestWrite } +func (c *ClientConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *ClientConn) Upstream() any { return c.Conn } @@ -377,6 +381,10 @@ func (c *ClientPacketConn) RemoteAddr() net.Addr { return c.destination.UDPAddr() } +func (c *ClientPacketConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *ClientPacketConn) Upstream() any { return c.ExtendedConn } @@ -518,6 +526,10 @@ func (c *ClientPacketAddrConn) FrontHeadroom() int { return 2 + M.MaxSocksaddrLength } +func (c *ClientPacketAddrConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *ClientPacketAddrConn) Upstream() any { return c.ExtendedConn } diff --git a/common/mux/service.go b/common/mux/service.go index 3dfae46c..19ec5bf0 100644 --- a/common/mux/service.go +++ b/common/mux/service.go @@ -131,6 +131,10 @@ func (c *ServerConn) FrontHeadroom() int { return 0 } +func (c *ServerConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *ServerConn) Upstream() any { return c.ExtendedConn } @@ -183,6 +187,10 @@ func (c *ServerPacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksad return c.ExtendedConn.WriteBuffer(buffer) } +func (c *ServerPacketConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *ServerPacketConn) Upstream() any { return c.ExtendedConn } @@ -245,6 +253,10 @@ func (c *ServerPacketAddrConn) WritePacket(buffer *buf.Buffer, destination M.Soc return c.ExtendedConn.WriteBuffer(buffer) } +func (c *ServerPacketAddrConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *ServerPacketAddrConn) Upstream() any { return c.ExtendedConn } diff --git a/go.mod b/go.mod index 4fd6cc37..9c3c6a4c 100644 --- a/go.mod +++ b/go.mod @@ -29,9 +29,9 @@ require ( github.com/sagernet/sing v0.2.4-0.20230418095640-3b5e6c1812d3 github.com/sagernet/sing-dns v0.1.5-0.20230418025317-8a132998b322 github.com/sagernet/sing-shadowsocks v0.2.2-0.20230418025154-6114beeeba6d - github.com/sagernet/sing-shadowtls v0.1.0 + github.com/sagernet/sing-shadowtls v0.1.2-0.20230417103049-4f682e05f19b github.com/sagernet/sing-tun v0.1.4-0.20230419061614-d744d03d9302 - github.com/sagernet/sing-vmess v0.1.3 + github.com/sagernet/sing-vmess v0.1.5-0.20230417103030-8c3070ae3fb3 github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37 github.com/sagernet/tfo-go v0.0.0-20230303015439-ffcfd8c41cf9 github.com/sagernet/utls v0.0.0-20230309024959-6732c2ab36f2 diff --git a/go.sum b/go.sum index ed182b3b..8a4993a2 100644 --- a/go.sum +++ b/go.sum @@ -119,12 +119,12 @@ github.com/sagernet/sing-dns v0.1.5-0.20230418025317-8a132998b322 h1:UDSeJZ2xB3d github.com/sagernet/sing-dns v0.1.5-0.20230418025317-8a132998b322/go.mod h1:2wjxSr1Gbecq9A0ESA9cnR399tQTcpCZEOGytekb+qI= github.com/sagernet/sing-shadowsocks v0.2.2-0.20230418025154-6114beeeba6d h1:UUxtLujzp5jmtOXqXpSOGvHwHSZcBveKVDzRJ4GlnFU= github.com/sagernet/sing-shadowsocks v0.2.2-0.20230418025154-6114beeeba6d/go.mod h1:Co3PJXcaZoLwHGBfT0rbSnn9C7ywc41zVYWtDeoeI/Q= -github.com/sagernet/sing-shadowtls v0.1.0 h1:05MYce8aR5xfKIn+y7xRFsdKhKt44QZTSEQW+lG5IWQ= -github.com/sagernet/sing-shadowtls v0.1.0/go.mod h1:Kn1VUIprdkwCgkS6SXYaLmIpKzQbqBIKJBMY+RvBhYc= +github.com/sagernet/sing-shadowtls v0.1.2-0.20230417103049-4f682e05f19b h1:ouW/6IDCrxkBe19YSbdCd7buHix7b+UZ6BM4Zz74XF4= +github.com/sagernet/sing-shadowtls v0.1.2-0.20230417103049-4f682e05f19b/go.mod h1:oG8bPerYI6cZ74KquY3DvA7ynECyrILPBnce6wtBqeI= github.com/sagernet/sing-tun v0.1.4-0.20230419061614-d744d03d9302 h1:aPb0T2HQRTG2t7fEwLvFLZSXmhmnBh+SMs2NufhmrsI= github.com/sagernet/sing-tun v0.1.4-0.20230419061614-d744d03d9302/go.mod h1:bvcVzlf9q9dgxt8qKluW+zOXCFoN1+SpBG3sHTq8/9Q= -github.com/sagernet/sing-vmess v0.1.3 h1:q/+tsF46dvvapL6CpQBgPHJ6nQrDUZqEtLHCbsjO7iM= -github.com/sagernet/sing-vmess v0.1.3/go.mod h1:GVXqAHwe9U21uS+Voh4YBIrADQyE4F9v0ayGSixSQAE= +github.com/sagernet/sing-vmess v0.1.5-0.20230417103030-8c3070ae3fb3 h1:BHOnxrbC929JonuKqFdJ7ZbDp7zs4oTlH5KFvKtWu9U= +github.com/sagernet/sing-vmess v0.1.5-0.20230417103030-8c3070ae3fb3/go.mod h1:yKrAr+dqZd64DxBXCHWrYicp+n4qbqO73mtwv3dck8U= github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37 h1:HuE6xSwco/Xed8ajZ+coeYLmioq0Qp1/Z2zczFaV8as= github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37/go.mod h1:3skNSftZDJWTGVtVaM2jfbce8qHnmH/AGDRe62iNOg0= github.com/sagernet/tfo-go v0.0.0-20230303015439-ffcfd8c41cf9 h1:2ItpW1nMNkPzmBTxV0/eClCklHrFSQMnUGcpUmJxVeE= diff --git a/inbound/naive.go b/inbound/naive.go index d823ae02..a506ecd4 100644 --- a/inbound/naive.go +++ b/inbound/naive.go @@ -606,6 +606,10 @@ func (c *naiveH2Conn) SetWriteDeadline(t time.Time) error { return os.ErrInvalid } +func (c *naiveH2Conn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *naiveH2Conn) UpstreamReader() any { return c.reader } diff --git a/transport/hysteria/protocol.go b/transport/hysteria/protocol.go index 179dad34..67ae4d01 100644 --- a/transport/hysteria/protocol.go +++ b/transport/hysteria/protocol.go @@ -535,6 +535,10 @@ func (c *PacketConn) SetWriteDeadline(t time.Time) error { return os.ErrInvalid } +func (c *PacketConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *PacketConn) Read(b []byte) (n int, err error) { return 0, os.ErrInvalid } diff --git a/transport/trojan/service.go b/transport/trojan/service.go index 453423d2..61d5ae36 100644 --- a/transport/trojan/service.go +++ b/transport/trojan/service.go @@ -136,3 +136,11 @@ func (c *PacketConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) er func (c *PacketConn) FrontHeadroom() int { return M.MaxSocksaddrLength + 4 } + +func (c *PacketConn) NeedAdditionalReadDeadline() bool { + return true +} + +func (c *PacketConn) Upstream() any { + return c.Conn +} diff --git a/transport/v2raygrpc/conn.go b/transport/v2raygrpc/conn.go index ec31e298..b437f04c 100644 --- a/transport/v2raygrpc/conn.go +++ b/transport/v2raygrpc/conn.go @@ -81,6 +81,10 @@ func (c *GRPCConn) SetWriteDeadline(t time.Time) error { return os.ErrInvalid } +func (c *GRPCConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *GRPCConn) Upstream() any { return c.GunService } diff --git a/transport/v2raygrpclite/conn.go b/transport/v2raygrpclite/conn.go index 7906fcdb..58bc2add 100644 --- a/transport/v2raygrpclite/conn.go +++ b/transport/v2raygrpclite/conn.go @@ -145,28 +145,17 @@ func (c *GunConn) RemoteAddr() net.Addr { } func (c *GunConn) SetDeadline(t time.Time) error { - if responseWriter, loaded := c.writer.(interface { - SetWriteDeadline(time.Time) error - }); loaded { - return responseWriter.SetWriteDeadline(t) - } return os.ErrInvalid } func (c *GunConn) SetReadDeadline(t time.Time) error { - if responseWriter, loaded := c.writer.(interface { - SetReadDeadline(time.Time) error - }); loaded { - return responseWriter.SetReadDeadline(t) - } return os.ErrInvalid } func (c *GunConn) SetWriteDeadline(t time.Time) error { - if responseWriter, loaded := c.writer.(interface { - SetWriteDeadline(time.Time) error - }); loaded { - return responseWriter.SetWriteDeadline(t) - } return os.ErrInvalid } + +func (c *GunConn) NeedAdditionalReadDeadline() bool { + return true +} diff --git a/transport/v2rayhttp/conn.go b/transport/v2rayhttp/conn.go index ca97a520..fc0f6501 100644 --- a/transport/v2rayhttp/conn.go +++ b/transport/v2rayhttp/conn.go @@ -182,32 +182,21 @@ func (c *HTTP2Conn) RemoteAddr() net.Addr { } func (c *HTTP2Conn) SetDeadline(t time.Time) error { - if responseWriter, loaded := c.writer.(interface { - SetWriteDeadline(time.Time) error - }); loaded { - return responseWriter.SetWriteDeadline(t) - } return os.ErrInvalid } func (c *HTTP2Conn) SetReadDeadline(t time.Time) error { - if responseWriter, loaded := c.writer.(interface { - SetReadDeadline(time.Time) error - }); loaded { - return responseWriter.SetReadDeadline(t) - } return os.ErrInvalid } func (c *HTTP2Conn) SetWriteDeadline(t time.Time) error { - if responseWriter, loaded := c.writer.(interface { - SetWriteDeadline(time.Time) error - }); loaded { - return responseWriter.SetWriteDeadline(t) - } return os.ErrInvalid } +func (c *HTTP2Conn) NeedAdditionalReadDeadline() bool { + return true +} + type ServerHTTPConn struct { HTTP2Conn flusher http.Flusher diff --git a/transport/v2raywebsocket/conn.go b/transport/v2raywebsocket/conn.go index e7571c84..dc3f4b52 100644 --- a/transport/v2raywebsocket/conn.go +++ b/transport/v2raywebsocket/conn.go @@ -77,6 +77,10 @@ func (c *WebsocketConn) SetWriteDeadline(t time.Time) error { return os.ErrInvalid } +func (c *WebsocketConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *WebsocketConn) Upstream() any { return c.Conn.NetConn() } @@ -214,6 +218,10 @@ func (c *EarlyWebsocketConn) SetWriteDeadline(t time.Time) error { return os.ErrInvalid } +func (c *EarlyWebsocketConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *EarlyWebsocketConn) Upstream() any { return common.PtrOrNil(c.conn) } diff --git a/transport/vless/client.go b/transport/vless/client.go index 1a5885b7..dd499624 100644 --- a/transport/vless/client.go +++ b/transport/vless/client.go @@ -132,6 +132,10 @@ func (c *Conn) Write(b []byte) (n int, err error) { return c.protocolConn.Write(b) } +func (c *Conn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *Conn) Upstream() any { return c.Conn } @@ -212,6 +216,10 @@ func (c *PacketConn) FrontHeadroom() int { return 2 } +func (c *PacketConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *PacketConn) Upstream() any { return c.Conn } diff --git a/transport/vless/service.go b/transport/vless/service.go index 878feeec..4a00db47 100644 --- a/transport/vless/service.go +++ b/transport/vless/service.go @@ -134,6 +134,14 @@ func (c *serverConn) Write(b []byte) (n int, err error) { return c.Conn.Write(b) } +func (c *serverConn) NeedAdditionalReadDeadline() bool { + return true +} + +func (c *serverConn) Upstream() any { + return c.Conn +} + type serverPacketConn struct { N.ExtendedConn responseWriter io.Writer diff --git a/transport/vless/vision.go b/transport/vless/vision.go index 7dc78cc9..cd323f5f 100644 --- a/transport/vless/vision.go +++ b/transport/vless/vision.go @@ -360,6 +360,10 @@ func (c *VisionConn) unPadding(buffer []byte) [][]byte { return buffers } +func (c *VisionConn) NeedAdditionalReadDeadline() bool { + return true +} + func (c *VisionConn) Upstream() any { return c.Conn }