Skip to content

Commit 768b6ff

Browse files
author
e1732a364fed
committed
geosite_gfw: print more err message; minor edit, improve
1 parent 7196840 commit 768b6ff

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev_res/test_clash_rules.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ rules:
3333
- DOMAIN-SUFFIX,zte.home,Direct
3434
- DOMAIN-SUFFIX,tplogin.cn,Direct
3535
- DOMAIN-SUFFIX,wifi.cmcc,Direct
36-
- DOMAIN-KEYWORD,baidu,Reject
36+
- DOMAIN-KEYWORD,afdfdasfdsa,Reject

doc/book/src/lua/route_config.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ clash_rules = "rules:\n - DOMAIN-SUFFIX,ip6-localhost,Direct"
9393
```
9494
geosite_gfw = {
9595
api_url = "http://127.0.0.1:5134/check",
96+
proxy = "127.0.0.1:10800",
97+
only_proxy = false,
9698
ok_ban_out_tag = { "Direct", "Reject"}
9799
}
98100
```
@@ -101,7 +103,14 @@ geosite_gfw 是一个 人工智能 gfw项目,它用过机器学习训练出的
101103

102104
主要用于 local 本地端进行分流。
103105

104-
目前的运行方式
106+
proxy 选项若给出,则 geosite_gfw 会在访问不到目标地址时,使用 proxy 再访问一次。
107+
而 若 only_proxy = true, 则 geosite_gfw 第一次方问目标地址就会使用 该 proxy.
108+
109+
注意,如果您配置 geosite_gfw 的 proxy 又指向回 我们的 ruci 的监听端口的话,要确保按上文的
110+
tag_route 把该端口的监听强制导向某 outbound, 避免再次进竹 geosite_gfw 环节 造成 回环。
111+
112+
113+
目前的geosite_gfw 的运行方式:
105114

106115
```sh
107116
git clone https://github.com/e1732a364fed/geosite-gfw/

rucimp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ TinyUFO = { version = "0.4", optional = true }
100100

101101

102102
netstack-smoltcp = { version = "0.1.3", optional = true }
103-
netstack-lwip = { git = "https://github.com/e1732a364fed/netstack-lwip.git", rev = "8682a98", optional = true }
103+
netstack-lwip = { git = "https://github.com/eycorsican/netstack-lwip.git", rev = "b7d9b0a", optional = true }
104104

105105

106106
[target.'cfg(windows)'.dependencies]

rucimp/src/map/tcp_ip_stack/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ where
9191
loop {
9292
let r = r.read(&mut bs).await;
9393
if let Ok(n) = r {
94+
// tracing::trace!("stack got b {}", n);
9495
let r = stack_sink.send((bs[..n]).to_vec()).await;
9596
r.unwrap();
9697
} else {

rucimp/src/route/geosite_gfw.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*! see https://github.com/e1732a364fed/geosite-gfw
22
*/
3+
use anyhow::{bail, Context};
34
use async_trait::async_trait;
45
use ruci::map::fold::DMIterBox;
56
use ruci::map::Data;
@@ -11,7 +12,6 @@ use tracing::debug;
1112

1213
use reqwest::Client;
1314
use serde::{Deserialize, Serialize};
14-
use std::error::Error;
1515

1616
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
1717
pub struct GeositeGfwConfig {
@@ -80,10 +80,7 @@ pub struct CheckResponse {
8080
}
8181

8282
/// 异步访问 API
83-
pub async fn check_api(
84-
config: &GeositeGfwConfig,
85-
domain: &str,
86-
) -> Result<CheckResponse, Box<dyn Error>> {
83+
pub async fn check_api(config: &GeositeGfwConfig, domain: &str) -> anyhow::Result<CheckResponse> {
8784
let client = Client::new();
8885

8986
let request_data = CheckRequest {
@@ -96,9 +93,22 @@ pub async fn check_api(
9693
.post(&config.api_url)
9794
.json(&request_data)
9895
.send()
99-
.await?
100-
.json::<CheckResponse>()
101-
.await?;
96+
.await
97+
.context("send failed")?;
98+
99+
let full_body = response.bytes().await?;
100+
101+
let response = serde_json::from_slice(&full_body);
102+
103+
let response = match response {
104+
Ok(r) => r,
105+
Err(e) => {
106+
bail!(
107+
"parse body err: {e}, body is {}",
108+
String::from_utf8_lossy(&full_body)
109+
)
110+
}
111+
};
102112

103113
debug!("geosite_gfw got response: {:?}", response);
104114
Ok(response)

0 commit comments

Comments
 (0)