mirror of https://github.com/XTLS/Xray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
525 B
33 lines
525 B
4 years ago
|
package bittorrent
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
|
||
|
"github.com/xtls/xray-core/v1/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
|
||
|
}
|