github.com/metacubex/mihomo@v1.18.5/component/sniffer/base_sniffer.go (about) 1 package sniffer 2 3 import ( 4 "errors" 5 6 "github.com/metacubex/mihomo/common/utils" 7 "github.com/metacubex/mihomo/constant" 8 "github.com/metacubex/mihomo/constant/sniffer" 9 ) 10 11 type SnifferConfig struct { 12 OverrideDest bool 13 Ports utils.IntRanges[uint16] 14 } 15 16 type BaseSniffer struct { 17 ports utils.IntRanges[uint16] 18 supportNetworkType constant.NetWork 19 } 20 21 // Protocol implements sniffer.Sniffer 22 func (*BaseSniffer) Protocol() string { 23 return "unknown" 24 } 25 26 // SniffData implements sniffer.Sniffer 27 func (*BaseSniffer) SniffData(bytes []byte) (string, error) { 28 return "", errors.New("TODO") 29 } 30 31 // SupportNetwork implements sniffer.Sniffer 32 func (bs *BaseSniffer) SupportNetwork() constant.NetWork { 33 return bs.supportNetworkType 34 } 35 36 // SupportPort implements sniffer.Sniffer 37 func (bs *BaseSniffer) SupportPort(port uint16) bool { 38 return bs.ports.Check(port) 39 } 40 41 func NewBaseSniffer(ports utils.IntRanges[uint16], networkType constant.NetWork) *BaseSniffer { 42 return &BaseSniffer{ 43 ports: ports, 44 supportNetworkType: networkType, 45 } 46 } 47 48 var _ sniffer.Sniffer = (*BaseSniffer)(nil)