mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 04:43:44 +08:00
feat: increase the concurrency of latency test
This commit is contained in:
parent
37f35e8b2d
commit
69b9944b8e
@ -229,6 +229,17 @@ pub fn open_web_url(url: String) -> CmdResult<()> {
|
|||||||
wrap_err!(open::that(url))
|
wrap_err!(open::that(url))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn clash_api_get_proxy_delay(
|
||||||
|
name: String,
|
||||||
|
url: Option<String>,
|
||||||
|
) -> CmdResult<clash_api::DelayRes> {
|
||||||
|
match clash_api::get_proxy_delay(name, url).await {
|
||||||
|
Ok(res) => Ok(res),
|
||||||
|
Err(err) => Err(format!("{}", err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub mod service {
|
pub mod service {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
use reqwest::header::HeaderMap;
|
use reqwest::header::HeaderMap;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_yaml::Mapping;
|
use serde_yaml::Mapping;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
@ -36,6 +37,28 @@ pub async fn patch_configs(config: &Mapping) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Debug, Clone, Deserialize, Serialize)]
|
||||||
|
pub struct DelayRes {
|
||||||
|
delay: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// GET /proxies/{name}/delay
|
||||||
|
/// 获取代理延迟
|
||||||
|
pub async fn get_proxy_delay(name: String, test_url: Option<String>) -> Result<DelayRes> {
|
||||||
|
let (url, headers) = clash_client_info()?;
|
||||||
|
let url = format!("{url}/proxies/{name}/delay");
|
||||||
|
let test_url = test_url.unwrap_or("http://www.gstatic.com/generate_204".into());
|
||||||
|
|
||||||
|
let client = reqwest::ClientBuilder::new().no_proxy().build()?;
|
||||||
|
let builder = client
|
||||||
|
.get(&url)
|
||||||
|
.headers(headers)
|
||||||
|
.query(&[("timeout", "10000"), ("url", &test_url)]);
|
||||||
|
let response = builder.send().await?;
|
||||||
|
|
||||||
|
Ok(response.json::<DelayRes>().await?)
|
||||||
|
}
|
||||||
|
|
||||||
/// 根据clash info获取clash服务地址和请求头
|
/// 根据clash info获取clash服务地址和请求头
|
||||||
fn clash_client_info() -> Result<(String, HeaderMap)> {
|
fn clash_client_info() -> Result<(String, HeaderMap)> {
|
||||||
let client = { Config::clash().data().get_client_info() };
|
let client = { Config::clash().data().get_client_info() };
|
||||||
|
@ -66,6 +66,8 @@ fn main() -> std::io::Result<()> {
|
|||||||
cmds::service::check_service,
|
cmds::service::check_service,
|
||||||
cmds::service::install_service,
|
cmds::service::install_service,
|
||||||
cmds::service::uninstall_service,
|
cmds::service::uninstall_service,
|
||||||
|
// clash api
|
||||||
|
cmds::clash_api_get_proxy_delay
|
||||||
]);
|
]);
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
|
@ -65,7 +65,7 @@ export const getRules = async () => {
|
|||||||
/// Get Proxy delay
|
/// Get Proxy delay
|
||||||
export const getProxyDelay = async (name: string, url?: string) => {
|
export const getProxyDelay = async (name: string, url?: string) => {
|
||||||
const params = {
|
const params = {
|
||||||
timeout: 5000,
|
timeout: 10000,
|
||||||
url: url || "http://www.gstatic.com/generate_204",
|
url: url || "http://www.gstatic.com/generate_204",
|
||||||
};
|
};
|
||||||
const instance = await getAxios();
|
const instance = await getAxios();
|
||||||
|
@ -153,6 +153,11 @@ export async function openWebUrl(url: string) {
|
|||||||
return invoke<void>("open_web_url", { url });
|
return invoke<void>("open_web_url", { url });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function cmdGetProxyDelay(name: string, url?: string) {
|
||||||
|
name = encodeURIComponent(name);
|
||||||
|
return invoke<{ delay: number }>("clash_api_get_proxy_delay", { name, url });
|
||||||
|
}
|
||||||
|
|
||||||
/// service mode
|
/// service mode
|
||||||
|
|
||||||
export async function checkService() {
|
export async function checkService() {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { getProxyDelay } from "./api";
|
import { cmdGetProxyDelay } from "./cmds";
|
||||||
|
|
||||||
const hashKey = (name: string, group: string) => `${group ?? ""}::${name}`;
|
const hashKey = (name: string, group: string) => `${group ?? ""}::${name}`;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ class DelayManager {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const url = this.getUrl(group);
|
const url = this.getUrl(group);
|
||||||
const result = await getProxyDelay(name, url);
|
const result = await cmdGetProxyDelay(name, url);
|
||||||
delay = result.delay;
|
delay = result.delay;
|
||||||
} catch {
|
} catch {
|
||||||
delay = 1e6; // error
|
delay = 1e6; // error
|
||||||
@ -84,7 +84,7 @@ class DelayManager {
|
|||||||
return delay;
|
return delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
async checkListDelay(nameList: string[], group: string, concurrency = 6) {
|
async checkListDelay(nameList: string[], group: string, concurrency = 36) {
|
||||||
const names = nameList.filter(Boolean);
|
const names = nameList.filter(Boolean);
|
||||||
// 设置正在延迟测试中
|
// 设置正在延迟测试中
|
||||||
names.forEach((name) => this.setDelay(name, group, -2));
|
names.forEach((name) => this.setDelay(name, group, -2));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user