mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-25 10:01:28 +00:00
32 lines
520 B
Go
32 lines
520 B
Go
package bittorrent
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
)
|
|
|
|
type SniffHeader struct{}
|
|
|
|
func (h *SniffHeader) Protocol() string {
|
|
return "bittorrent"
|
|
}
|
|
|
|
func (h *SniffHeader) Domain() string {
|
|
return ""
|
|
}
|
|
|
|
var errNotBittorrent = errors.New("not bittorrent header")
|
|
|
|
func SniffBittorrent(b []byte) (*SniffHeader, error) {
|
|
if len(b) < 20 {
|
|
return nil, common.ErrNoClue
|
|
}
|
|
|
|
if b[0] == 19 && string(b[1:20]) == "BitTorrent protocol" {
|
|
return &SniffHeader{}, nil
|
|
}
|
|
|
|
return nil, errNotBittorrent
|
|
}
|