chore: clean up code

This commit is contained in:
Skyxim 2022-07-13 22:27:49 +08:00
parent 179bc6ecdf
commit 947d9d4560

View File

@ -370,9 +370,6 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) {
resolved = true
}
var processUid int32
process := ""
processPath := ""
foundProcess := false
for _, rule := range rules {
if !resolved && shouldResolveIP(rule, metadata) {
@ -392,19 +389,13 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) {
if err != nil {
log.Debugln("[Process] find process %s: %v", metadata.String(), err)
} else {
process = filepath.Base(path)
processPath = path
processUid = uid
metadata.Process = filepath.Base(path)
metadata.ProcessPath = path
metadata.Uid = &uid
foundProcess = true
}
}
if foundProcess {
metadata.Uid = &processUid
metadata.Process = process
metadata.ProcessPath = processPath
}
if rule.Match(metadata) {
adapter, ok := proxies[rule.Adapter()]
if !ok {
@ -421,21 +412,6 @@ func match(metadata *C.Metadata) (C.Proxy, C.Rule, error) {
continue
}
extra := rule.RuleExtra()
if extra != nil {
if extra.NotMatchNetwork(metadata.NetWork) {
continue
}
if extra.NotMatchSourceIP(metadata.SrcIP) {
continue
}
if extra.NotMatchProcessName(metadata.Process) {
continue
}
}
return adapter, rule, nil
}
}