bittorrent.go 525 B

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