bittorrent.go 502 B

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