1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-17 13:05:24 +00:00
v2fly/common/protocol/bittorrent/bittorrent.go

33 lines
511 B
Go
Raw Normal View History

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