Merge protocols

This commit is contained in:
世界 2024-05-27 19:23:00 +08:00
parent 71e10439c8
commit b172745be0
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
5 changed files with 13 additions and 19 deletions

View File

@ -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

View File

@ -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)
}
}

View File

@ -7,6 +7,4 @@ const (
ProtocolDNS = "dns"
ProtocolSTUN = "stun"
ProtocolBitTorrent = "bittorrent"
ProtocolUTP = "utp"
ProtocolUDPTracker = "udp-tracker"
)

View File

@ -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 | / |

View File

@ -3,12 +3,10 @@
#### 支持的协议
| 网络 | 协议 | 域名 |
| :-----: | :---------: | :---------: |
|:-------:|:-----------:|:-----------:|
| 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 | / |