Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support geosite #466

Merged
merged 20 commits into from
Jul 3, 2024
Merged

feat: support geosite #466

merged 20 commits into from
Jul 3, 2024

Conversation

VendettaReborn
Copy link
Contributor

🤔 This is a ...

  • New feature

🔗 Related issue link

#441

💡 Background and solution

migrate clash meta's geosite rule matching logc here

📝 Changelog

support geosite(succinct)

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Changelog is provided or not needed

todos

  1. rule parsing may lead to error, should we collect the the wrong rules and propagate the error or unwrap and let it panic
  2. i've only implemented succinct geosite matcher, but there are other matchers like 'mph', there are slight differences between them, and we can support the later one when needed.


impl GeoSiteMatcher {
pub fn new(country_code: String, target: String, loader: &GeoData) -> anyhow::Result<Self> {
let (not, code, attr_matcher) = parse(&country_code).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably shouldn't crash or print en error if the country_code is empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}
}

// work around of SIGSEGV error on Linux
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is interesting, any idea what this could be?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/Watfaq/clash-rs/pull/466/files#diff-b803fcb7f17ed9235f1e5cb1fcd2f5d3b2838429d4368ae4c57ce4436577f03fR150

i installed this, will take a look and see if i can find something.

it's quite insteresting that safe rust haas segment fault

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to be an annoying bug, but i cannot reproduce the error, so have no clue

clash_lib/src/common/geodata/geodata_proto.rs Show resolved Hide resolved
Signed-off-by: Yuwei Ba <dev@watfaq.com>
ibigbug added 7 commits June 20, 2024 20:45
Signed-off-by: Yuwei Ba <contact@yba.dev>
Signed-off-by: Yuwei Ba <dev@watfaq.com>
Signed-off-by: Yuwei Ba <dev@watfaq.com>
Signed-off-by: Yuwei Ba <dev@watfaq.com>
@ibigbug
Copy link
Member

ibigbug commented Jul 3, 2024

the segv is likely to be a libc bug

https://sourceware.org/bugzilla/show_bug.cgi?id=10652

runner@fv-az1245-61:~/work/clash-rs/clash-rs$ ldd --version
ldd (Ubuntu GLIBC 2.35-0ubuntu3.8) 2.35
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
* thread #5, name = 'tokio-runtime-w', stop reason = signal SIGSEGV: address access protected (fault address: 0x7ffff7ff6072)
  * frame #0: 0x00007ffff74909ff libc.so.6`___lldb_unnamed_symbol3444 + 15
    frame #1: 0x00007ffff7446ca7 libc.so.6`getrandom + 55
    frame #2: 0x00007ffff74a19e6 libc.so.6`___lldb_unnamed_symbol3562 + 54
    frame #3: 0x00007ffff74a52d5 libc.so.6`malloc + 565
    frame #4: 0x00007ffff747f64e libc.so.6`fopen + 30
    frame #5: 0x00007ffff7554c62 libc.so.6`__nss_files_fopen + 18
    frame #6: 0x00007ffff7559576 libc.so.6`_nss_files_gethostbyname4_r + 70
    frame #7: 0x000000000432d032 clash_lib-13ff65be0259b17a`gaih_inet + 3730
    frame #8: 0x000000000432ffee clash_lib-13ff65be0259b17a`getaddrinfo + 238
    frame #9: 0x00000000042b590d clash_lib-13ff65be0259b17a`_$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$LP$$RF$str$C$u16$RP$$GT$$GT$::try_from::_$u7b$$u7b$closure$u7d$$u7d$::h9a8c412bdf50b346 at net.rs:214:25
    frame #10: 0x00000000042b5891 clash_lib-13ff65be0259b17a`_$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$RF$str$GT$$GT$::try_from::h0908d8741ee84690 [inlined] std::sys::pal::common::small_c_string::run_with_cstr_stack::hedfa392433a772e6 at small_c_string.rs:49:18
    frame #11: 0x00000000042b5881 clash_lib-13ff65be0259b17a`_$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$RF$str$GT$$GT$::try_from::h0908d8741ee84690 [inlined] std::sys::pal::common::small_c_string::run_with_cstr::hec9054c781c17940 at small_c_string.rs:29:18
    frame #12: 0x00000000042b5881 clash_lib-13ff65be0259b17a`_$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$RF$str$GT$$GT$::try_from::h0908d8741ee84690 [inlined] _$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$LP$$RF$str$C$u16$RP$$GT$$GT$::try_from::ha4f80255ee8fa71b at net.rs:209:9
    frame #13: 0x00000000042b5881 clash_lib-13ff65be0259b17a`_$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$RF$str$GT$$GT$::try_from::h0908d8741ee84690 [inlined] _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::hd6a240b2b32fda6c at mod.rs:798:9
    frame #14: 0x00000000042b5881 clash_lib-13ff65be0259b17a`_$LT$std..sys_common..net..LookupHost$u20$as$u20$core..convert..TryFrom$LT$$RF$str$GT$$GT$::try_from::h0908d8741ee84690 at net.rs:199:22
    frame #15: 0x00000000042a7887 clash_lib-13ff65be0259b17a`_$LT$str$u20$as$u20$std..net..socket_addr..ToSocketAddrs$GT$::to_socket_addrs::h555087dafee2e74a [inlined] _$LT$T$u20$as$u20$core..convert..TryInto$LT$U$GT$$GT$::try_into::h967bbc5c67e4b400 at mod.rs:798:9
    frame #16: 0x00000000042a787b clash_lib-13ff65be0259b17a`_$LT$str$u20$as$u20$std..net..socket_addr..ToSocketAddrs$GT$::to_socket_addrs::h555087dafee2e74a at socket_addr.rs:288:34
    frame #17: 0x00000000042a793a clash_lib-13ff65be0259b17a`_$LT$alloc..string..String$u20$as$u20$std..net..socket_addr..ToSocketAddrs$GT$::to_socket_addrs::h6b07b06b296839db at socket_addr.rs:313:9
    frame #18: 0x00000000041fb5fa clash_lib-13ff65be0259b17a`tokio::net::addr::_$LT$impl$u20$tokio..net..addr..sealed..ToSocketAddrsPriv$u20$for$u20$str$GT$::to_socket_addrs::_$u7b$$u7b$closure$u7d$$u7d$::he2bbf60021e64dda at addr.rs:183:17
    frame #19: 0x0000000004100d71 clash_lib-13ff65be0259b17a`_$LT$tokio..runtime..blocking..task..BlockingTask$LT$T$GT$$u20$as$u20$core..future..future..Future$GT$::poll::h511f284e5c14f0e3(self=Pin<&mut tokio::runtime::blocking::task::BlockingTask<tokio::net::addr::{impl#17}::to_socket_addrs::{closure_env#0}>> @ 0x00007ffff7ff39d8, _cx=0x00007ffff7ff3d70) at task.rs:42:21

Copy link
Member

@ibigbug ibigbug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@ibigbug ibigbug enabled auto-merge (squash) July 3, 2024 23:06
@ibigbug ibigbug merged commit 9d9c3f2 into master Jul 3, 2024
20 checks passed
@ibigbug ibigbug deleted the feat/geosite branch July 3, 2024 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants