mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-25 19:55:38 +08:00
3ef81afc76
Co-authored-by: Larvan2 <78135608+Larvan2@users.noreply.github.com> Co-authored-by: wwqgtxx <wwqgtxx@gmail.com>
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package sniffer
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/Dreamacro/clash/common/utils"
|
|
"github.com/Dreamacro/clash/constant"
|
|
"github.com/Dreamacro/clash/constant/sniffer"
|
|
)
|
|
|
|
type SnifferConfig struct {
|
|
OverrideDest bool
|
|
Ports utils.IntRanges[uint16]
|
|
}
|
|
|
|
type BaseSniffer struct {
|
|
ports utils.IntRanges[uint16]
|
|
supportNetworkType constant.NetWork
|
|
}
|
|
|
|
// Protocol implements sniffer.Sniffer
|
|
func (*BaseSniffer) Protocol() string {
|
|
return "unknown"
|
|
}
|
|
|
|
// SniffTCP implements sniffer.Sniffer
|
|
func (*BaseSniffer) SniffTCP(bytes []byte) (string, error) {
|
|
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)
|
|
}
|
|
|
|
func NewBaseSniffer(ports utils.IntRanges[uint16], networkType constant.NetWork) *BaseSniffer {
|
|
return &BaseSniffer{
|
|
ports: ports,
|
|
supportNetworkType: networkType,
|
|
}
|
|
}
|
|
|
|
var _ sniffer.Sniffer = (*BaseSniffer)(nil)
|