github.com/v2fly/v2ray-core/v4@v4.45.2/common/protocol/bittorrent/bittorrent.go (about) 1 package bittorrent 2 3 import ( 4 "errors" 5 6 "github.com/v2fly/v2ray-core/v4/common" 7 ) 8 9 type SniffHeader struct{} 10 11 func (h *SniffHeader) Protocol() string { 12 return "bittorrent" 13 } 14 15 func (h *SniffHeader) Domain() string { 16 return "" 17 } 18 19 var errNotBittorrent = errors.New("not bittorrent header") 20 21 func SniffBittorrent(b []byte) (*SniffHeader, error) { 22 if len(b) < 20 { 23 return nil, common.ErrNoClue 24 } 25 26 if b[0] == 19 && string(b[1:20]) == "BitTorrent protocol" { 27 return &SniffHeader{}, nil 28 } 29 30 return nil, errNotBittorrent 31 }