2018-07-16 06:56:50 -04:00
|
|
|
package bittorrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2018-10-11 14:43:37 -04:00
|
|
|
"v2ray.com/core/common"
|
2018-07-16 06:56:50 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2018-10-11 14:43:37 -04:00
|
|
|
return nil, common.ErrNoClue
|
2018-07-16 06:56:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if b[0] == 19 && string(b[1:20]) == "BitTorrent protocol" {
|
|
|
|
return &SniffHeader{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, errNotBittorrent
|
|
|
|
}
|