#radix-trie #clash #yaml #aho-corasick

clash_rules

a clash yaml rule parser and matching algorithms provider

20 releases

0.1.19 Feb 23, 2025
0.1.18 Feb 19, 2025

#696 in Data structures

Download history 240/week @ 2025-02-05 687/week @ 2025-02-12 486/week @ 2025-02-19 132/week @ 2025-02-26 326/week @ 2025-03-05 35/week @ 2025-03-12

513 downloads per month

MIT/Apache

74KB
2K SLoC

This project can parse the rules and rule-sets in Clash’s YAML configuration files and provides an optimized matching algorithm. The project uses functional programming.

DOMAIN-SUFFIX, IP-CIDR(6) uses radix trie ,DOMAIN-KEYWORD uses Aho-Corasick Automaton. DOMAIN-REGEX uses RegexSet. PORT uses binary search.

For examples, see the test at the end of the lib.rs and benches/algorithms.

There's a convenient struct ClashRuleMatcher and an enum Rule.

Also has feature to load and save to sqlite.

Supported rules are: RULE-SET, GEOSITE, AND, OR, NOT, DOMAIN, DOMAIN-KEYWORD, DOMAIN-SUFFIX, DOMAIN-REGEX, IP-CIDR, IP-CIDR6, GEOIP, PROCESS-NAME, NETWORK, DST-PORT, SRC-PORT, IN-PORT, MATCH

Use external crate geosite-rs to support GEOSITE.

Dependencies

~29MB
~550K SLoC