2020-11-25 11:01:53 +00:00
|
|
|
package bittorrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2020-12-04 01:36:16 +00:00
|
|
|
"github.com/xtls/xray-core/common"
|
2020-11-25 11:01:53 +00:00
|
|
|
)
|
|
|
|
|
2021-10-19 16:57:14 +00:00
|
|
|
type SniffHeader struct{}
|
2020-11-25 11:01:53 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|