github.com/EagleQL/Xray-core@v1.4.3/common/protocol/bittorrent/bittorrent.go (about)

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