Clash.Meta/component/sniffer/base_sniffer.go

49 lines
1.1 KiB
Go
Raw Normal View History

2023-01-23 13:16:25 +08:00
package sniffer
import (
"errors"
2023-11-03 21:01:45 +08:00
"github.com/metacubex/mihomo/common/utils"
"github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/sniffer"
2023-01-23 13:16:25 +08:00
)
type SnifferConfig struct {
OverrideDest bool
Ports utils.IntRanges[uint16]
2023-01-23 13:16:25 +08:00
}
type BaseSniffer struct {
ports utils.IntRanges[uint16]
2023-01-23 13:16:25 +08:00
supportNetworkType constant.NetWork
}
// Protocol implements sniffer.Sniffer
func (*BaseSniffer) Protocol() string {
return "unknown"
}
2023-10-19 18:30:20 +08:00
// SniffData implements sniffer.Sniffer
func (*BaseSniffer) SniffData(bytes []byte) (string, error) {
2023-01-23 13:16:25 +08:00
return "", errors.New("TODO")
}
// SupportNetwork implements sniffer.Sniffer
func (bs *BaseSniffer) SupportNetwork() constant.NetWork {
return bs.supportNetworkType
}
// SupportPort implements sniffer.Sniffer
func (bs *BaseSniffer) SupportPort(port uint16) bool {
return bs.ports.Check(port)
2023-01-23 13:16:25 +08:00
}
func NewBaseSniffer(ports utils.IntRanges[uint16], networkType constant.NetWork) *BaseSniffer {
2023-01-23 13:16:25 +08:00
return &BaseSniffer{
ports: ports,
supportNetworkType: networkType,
}
}
var _ sniffer.Sniffer = (*BaseSniffer)(nil)