Skip to content

Commit

Permalink
chore: better converter
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Jul 27, 2024
1 parent 4f8a5a5 commit 1db3e45
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,12 @@ rule-providers:
interval: 259200
path: /path/to/save/file.yaml
type: file
rule3: # mrs类型ruleset,目前仅支持domain和ipcidr,可以通过“mihomo convert-ruleset domain yaml XXX.yaml XXX.mrs”转换得到
rule3:
# mrs类型ruleset,目前仅支持domain和ipcidr(即不支持classical),
# behavior=domain,format=yaml 可以通过“mihomo convert-ruleset domain yaml XXX.yaml XXX.mrs”转换得到
# behavior=domain,format=text 可以通过“mihomo convert-ruleset domain text XXX.text XXX.mrs”转换得到
# behavior=ipcidr,format=yaml 可以通过“mihomo convert-ruleset ipcidr yaml XXX.yaml XXX.mrs”转换得到
# behavior=ipcidr,format=text 可以通过“mihomo convert-ruleset ipcidr text XXX.text XXX.mrs”转换得到
type: http
url: "url"
format: mrs
Expand Down
5 changes: 5 additions & 0 deletions rules/provider/domain_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"errors"
"io"
"strings"

"github.com/metacubex/mihomo/component/trie"
C "github.com/metacubex/mihomo/constant"
Expand Down Expand Up @@ -43,6 +44,10 @@ func (d *domainStrategy) Reset() {
}

func (d *domainStrategy) Insert(rule string) {
if strings.ContainsRune(rule, '/') {
log.Warnln("invalid domain:[%s]", rule)
return
}
err := d.domainTrie.Insert(rule, struct{}{})
if err != nil {
log.Warnln("invalid domain:[%s]", rule)
Expand Down
4 changes: 4 additions & 0 deletions rules/provider/mrs_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package provider

import (
"encoding/binary"
"errors"
"io"
"os"

Expand All @@ -16,6 +17,9 @@ func ConvertToMrs(buf []byte, behavior P.RuleBehavior, format P.RuleFormat, w io
if err != nil {
return err
}
if strategy.Count() == 0 {
return errors.New("empty rule")
}
if _strategy, ok := strategy.(mrsRuleStrategy); ok {
var encoder *zstd.Encoder
encoder, err = zstd.NewWriter(w)
Expand Down

0 comments on commit 1db3e45

Please sign in to comment.