From b172745be0ffc5fb9f402a9067554e7b63274cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 27 May 2024 19:23:00 +0800 Subject: [PATCH] Merge protocols --- common/sniff/bittorrent.go | 8 ++++---- common/sniff/bittorrent_test.go | 8 ++++---- constant/protocol.go | 2 -- docs/configuration/route/sniff.md | 6 ++---- docs/configuration/route/sniff.zh.md | 8 +++----- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/common/sniff/bittorrent.go b/common/sniff/bittorrent.go index 491daa2e..7885f662 100644 --- a/common/sniff/bittorrent.go +++ b/common/sniff/bittorrent.go @@ -8,7 +8,7 @@ import ( "os" "github.com/sagernet/sing-box/adapter" - "github.com/sagernet/sing-box/constant" + C "github.com/sagernet/sing-box/constant" ) const ( @@ -46,7 +46,7 @@ func BitTorrent(_ context.Context, reader io.Reader) (*adapter.InboundContext, e } return &adapter.InboundContext{ - Protocol: constant.ProtocolBitTorrent, + Protocol: C.ProtocolBitTorrent, }, nil } @@ -87,7 +87,7 @@ func UTP(_ context.Context, packet []byte) (*adapter.InboundContext, error) { } return &adapter.InboundContext{ - Protocol: constant.ProtocolUTP, + Protocol: C.ProtocolBitTorrent, }, nil } @@ -105,7 +105,7 @@ func UDPTracker(_ context.Context, packet []byte) (*adapter.InboundContext, erro case len(packet) >= trackerScrapeMinSize && binary.BigEndian.Uint32(packet[8:12]) == trackerScrapeFlag: return &adapter.InboundContext{ - Protocol: constant.ProtocolUDPTracker, + Protocol: C.ProtocolBitTorrent, }, nil default: return nil, os.ErrInvalid diff --git a/common/sniff/bittorrent_test.go b/common/sniff/bittorrent_test.go index 6cb1854d..8d4cdeac 100644 --- a/common/sniff/bittorrent_test.go +++ b/common/sniff/bittorrent_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/sagernet/sing-box/common/sniff" - "github.com/sagernet/sing-box/constant" + C "github.com/sagernet/sing-box/constant" "github.com/stretchr/testify/require" ) @@ -26,7 +26,7 @@ func TestSniffBittorrent(t *testing.T) { require.NoError(t, err) metadata, err := sniff.BitTorrent(context.TODO(), bytes.NewReader(pkt)) require.NoError(t, err) - require.Equal(t, constant.ProtocolBitTorrent, metadata.Protocol) + require.Equal(t, C.ProtocolBitTorrent, metadata.Protocol) } } @@ -46,7 +46,7 @@ func TestSniffUTP(t *testing.T) { metadata, err := sniff.UTP(context.TODO(), pkt) require.NoError(t, err) - require.Equal(t, constant.ProtocolUTP, metadata.Protocol) + require.Equal(t, C.ProtocolBitTorrent, metadata.Protocol) } } @@ -76,6 +76,6 @@ func TestSniffUDPTracker(t *testing.T) { metadata, err := sniff.UDPTracker(context.TODO(), pkt) require.NoError(t, err) - require.Equal(t, constant.ProtocolUDPTracker, metadata.Protocol) + require.Equal(t, C.ProtocolBitTorrent, metadata.Protocol) } } diff --git a/constant/protocol.go b/constant/protocol.go index f1d753c6..2b7a9e0f 100644 --- a/constant/protocol.go +++ b/constant/protocol.go @@ -7,6 +7,4 @@ const ( ProtocolDNS = "dns" ProtocolSTUN = "stun" ProtocolBitTorrent = "bittorrent" - ProtocolUTP = "utp" - ProtocolUDPTracker = "udp-tracker" ) diff --git a/docs/configuration/route/sniff.md b/docs/configuration/route/sniff.md index 53a199fc..7a3de02b 100644 --- a/docs/configuration/route/sniff.md +++ b/docs/configuration/route/sniff.md @@ -3,12 +3,10 @@ If enabled in the inbound, the protocol and domain name (if present) of by the c #### Supported Protocols | Network | Protocol | Domain Name | -| :-----: | :---------: | :---------: | +|:-------:|:-----------:|:-----------:| | TCP | HTTP | Host | | TCP | TLS | Server Name | | UDP | QUIC | Server Name | | UDP | STUN | / | | TCP/UDP | DNS | / | -| TCP | BitTorrent | / | -| UDP | UTP/µTP | / | -| UDP | UDP Tracker | / | +| TCP/UDP | BitTorrent | / | \ No newline at end of file diff --git a/docs/configuration/route/sniff.zh.md b/docs/configuration/route/sniff.zh.md index ee7b2d70..553c6ed7 100644 --- a/docs/configuration/route/sniff.zh.md +++ b/docs/configuration/route/sniff.zh.md @@ -2,13 +2,11 @@ #### 支持的协议 -| 网络 | 协议 | 域名 | -| :-----: | :---------: | :---------: | +| 网络 | 协议 | 域名 | +|:-------:|:-----------:|:-----------:| | TCP | HTTP | Host | | TCP | TLS | Server Name | | UDP | QUIC | Server Name | | UDP | STUN | / | | TCP/UDP | DNS | / | -| TCP | BitTorrent | / | -| UDP | UTP/µTP | / | -| UDP | UDP Tracker | / | \ No newline at end of file +| TCP/UDP | BitTorrent | / | \ No newline at end of file