7a3f6e945d
Refactors TCP and UDP flow managers to enhance analyzer selection and flow binding accuracy, including O(1) UDP stream rebinding by 5-tuple. Introduces runtime stats tracking for engine and ruleset operations, exposing new APIs for granular performance and error metrics. Optimizes GeoMatcher with result caching and supports efficient geosite set matching, reducing redundant computation in ruleset expressions.
65 lines
2.7 KiB
Go
65 lines
2.7 KiB
Go
package mellaris
|
|
|
|
import (
|
|
"git.difuse.io/Difuse/Mellaris/analyzer"
|
|
"git.difuse.io/Difuse/Mellaris/engine"
|
|
gfwio "git.difuse.io/Difuse/Mellaris/io"
|
|
"git.difuse.io/Difuse/Mellaris/modifier"
|
|
"git.difuse.io/Difuse/Mellaris/ruleset"
|
|
)
|
|
|
|
// Config defines IO, worker, and ruleset settings for the engine.
|
|
type Config struct {
|
|
IO IOConfig `mapstructure:"io" yaml:"io"`
|
|
Workers WorkersConfig `mapstructure:"workers" yaml:"workers"`
|
|
Ruleset RulesetConfig `mapstructure:"ruleset" yaml:"ruleset"`
|
|
}
|
|
|
|
// IOConfig configures packet IO.
|
|
type IOConfig struct {
|
|
QueueSize uint32 `mapstructure:"queueSize" yaml:"queueSize"`
|
|
ReadBuffer int `mapstructure:"rcvBuf" yaml:"rcvBuf"`
|
|
WriteBuffer int `mapstructure:"sndBuf" yaml:"sndBuf"`
|
|
Local bool `mapstructure:"local" yaml:"local"`
|
|
RST bool `mapstructure:"rst" yaml:"rst"`
|
|
NumQueues int `mapstructure:"numQueues" yaml:"numQueues"`
|
|
MaxPacketLen uint32 `mapstructure:"maxPacketLen" yaml:"maxPacketLen"`
|
|
|
|
// PacketIO overrides NFQueue creation when set.
|
|
// When provided, App.Close will call PacketIO.Close.
|
|
PacketIO gfwio.PacketIO `mapstructure:"-" yaml:"-"`
|
|
}
|
|
|
|
// WorkersConfig configures engine worker behavior.
|
|
type WorkersConfig struct {
|
|
Count int `mapstructure:"count" yaml:"count"`
|
|
QueueSize int `mapstructure:"queueSize" yaml:"queueSize"`
|
|
TCPMaxBufferedPagesTotal int `mapstructure:"tcpMaxBufferedPagesTotal" yaml:"tcpMaxBufferedPagesTotal"`
|
|
TCPMaxBufferedPagesPerConn int `mapstructure:"tcpMaxBufferedPagesPerConn" yaml:"tcpMaxBufferedPagesPerConn"`
|
|
UDPMaxStreams int `mapstructure:"udpMaxStreams" yaml:"udpMaxStreams"`
|
|
OverflowPolicy engine.OverflowPolicy `mapstructure:"overflowPolicy" yaml:"overflowPolicy"`
|
|
AnalyzerSelectionMode engine.AnalyzerSelectionMode `mapstructure:"analyzerSelectionMode" yaml:"analyzerSelectionMode"`
|
|
}
|
|
|
|
// RulesetConfig configures built-in rule helpers.
|
|
type RulesetConfig struct {
|
|
GeoIp string `mapstructure:"geoip" yaml:"geoip"`
|
|
GeoSite string `mapstructure:"geosite" yaml:"geosite"`
|
|
}
|
|
|
|
// Options configures rules, analyzers, modifiers, and logging.
|
|
type Options struct {
|
|
// RulesFile is a YAML rules file on disk. Mutually exclusive with Rules.
|
|
RulesFile string
|
|
// Rules provides inline expression rules. Mutually exclusive with RulesFile.
|
|
Rules []ruleset.ExprRule
|
|
|
|
// Analyzers and Modifiers default to built-ins when nil.
|
|
Analyzers []analyzer.Analyzer
|
|
Modifiers []modifier.Modifier
|
|
|
|
// EngineLogger and RulesetLogger default to no-op loggers when nil.
|
|
EngineLogger engine.Logger
|
|
RulesetLogger ruleset.Logger
|
|
}
|