fix: Optimize HTTP requests, refine translations, and fix dependencies

This commit is contained in:
yuluo
2024-04-23 02:56:04 +08:00
parent c1def9e738
commit ce339d0664
23 changed files with 164 additions and 94 deletions

108
Cargo.lock generated
View File

@@ -311,9 +311,9 @@ dependencies = [
[[package]] [[package]]
name = "async-compression" name = "async-compression"
version = "0.4.5" version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc2d0cfb2a7388d34f590e76686704c494ed7aaceed62ee1ba35cbf363abc2a5" checksum = "07dbbf24db18d609b1462965249abdf49129ccad073ec257da372adc83259c60"
dependencies = [ dependencies = [
"flate2", "flate2",
"futures-core", "futures-core",
@@ -1897,9 +1897,9 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.33" version = "0.8.34"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
@@ -2933,9 +2933,9 @@ dependencies = [
[[package]] [[package]]
name = "h2" name = "h2"
version = "0.3.24" version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8"
dependencies = [ dependencies = [
"bytes", "bytes",
"fnv", "fnv",
@@ -3009,6 +3009,7 @@ dependencies = [
"rand 0.8.5", "rand 0.8.5",
"regex", "regex",
"rustls-pki-types", "rustls-pki-types",
"rustls-platform-verifier",
"serde 1.0.190", "serde 1.0.190",
"serde_derive", "serde_derive",
"serde_json 1.0.107", "serde_json 1.0.107",
@@ -3024,7 +3025,6 @@ dependencies = [
"toml 0.7.8", "toml 0.7.8",
"url", "url",
"uuid", "uuid",
"webpki-roots 0.26.1",
"winapi 0.3.9", "winapi 0.3.9",
"zstd 0.13.0", "zstd 0.13.0",
] ]
@@ -3100,9 +3100,9 @@ dependencies = [
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.9" version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1"
dependencies = [ dependencies = [
"bytes", "bytes",
"fnv", "fnv",
@@ -3111,9 +3111,9 @@ dependencies = [
[[package]] [[package]]
name = "http-body" name = "http-body"
version = "0.4.5" version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"
dependencies = [ dependencies = [
"bytes", "bytes",
"http", "http",
@@ -3153,9 +3153,9 @@ dependencies = [
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.14.27" version = "0.14.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80"
dependencies = [ dependencies = [
"bytes", "bytes",
"futures-channel", "futures-channel",
@@ -3168,7 +3168,7 @@ dependencies = [
"httpdate", "httpdate",
"itoa 1.0.9", "itoa 1.0.9",
"pin-project-lite", "pin-project-lite",
"socket2 0.4.10", "socket2 0.5.5",
"tokio", "tokio",
"tower-service", "tower-service",
"tracing", "tracing",
@@ -4979,7 +4979,7 @@ dependencies = [
"ring 0.16.20", "ring 0.16.20",
"rustc-hash", "rustc-hash",
"rustls 0.20.9", "rustls 0.20.9",
"rustls-native-certs", "rustls-native-certs 0.6.3",
"slab", "slab",
"thiserror", "thiserror",
"tinyvec", "tinyvec",
@@ -5314,7 +5314,7 @@ dependencies = [
[[package]] [[package]]
name = "reqwest" name = "reqwest"
version = "0.11.23" version = "0.11.23"
source = "git+https://github.com/rustdesk-org/reqwest" source = "git+https://github.com/rustdesk-org/reqwest#9cb758c9fb2f4edc62eb790acfd45a6a3da21ed3"
dependencies = [ dependencies = [
"async-compression", "async-compression",
"base64 0.21.5", "base64 0.21.5",
@@ -5337,8 +5337,8 @@ dependencies = [
"percent-encoding", "percent-encoding",
"pin-project-lite", "pin-project-lite",
"rustls 0.21.10", "rustls 0.21.10",
"rustls-native-certs", "rustls-native-certs 0.6.3",
"rustls-pemfile", "rustls-pemfile 1.0.3",
"serde 1.0.190", "serde 1.0.190",
"serde_json 1.0.107", "serde_json 1.0.107",
"serde_urlencoded", "serde_urlencoded",
@@ -5354,7 +5354,7 @@ dependencies = [
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"web-sys", "web-sys",
"webpki-roots 0.25.3", "webpki-roots 0.25.4",
"winreg 0.50.0", "winreg 0.50.0",
] ]
@@ -5500,7 +5500,6 @@ dependencies = [
"arboard", "arboard",
"async-process", "async-process",
"async-trait", "async-trait",
"base64 0.21.5",
"bytes", "bytes",
"cc", "cc",
"cfg-if 1.0.0", "cfg-if 1.0.0",
@@ -5687,7 +5686,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00"
dependencies = [ dependencies = [
"openssl-probe", "openssl-probe",
"rustls-pemfile", "rustls-pemfile 1.0.3",
"schannel",
"security-framework",
]
[[package]]
name = "rustls-native-certs"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f1fb85efa936c42c6d5fc28d2629bb51e4b2f4b8a5211e297d599cc5a093792"
dependencies = [
"openssl-probe",
"rustls-pemfile 2.1.2",
"rustls-pki-types",
"schannel", "schannel",
"security-framework", "security-framework",
] ]
@@ -5701,12 +5713,49 @@ dependencies = [
"base64 0.21.5", "base64 0.21.5",
] ]
[[package]]
name = "rustls-pemfile"
version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d"
dependencies = [
"base64 0.22.0",
"rustls-pki-types",
]
[[package]] [[package]]
name = "rustls-pki-types" name = "rustls-pki-types"
version = "1.4.1" version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247" checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247"
[[package]]
name = "rustls-platform-verifier"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5f0d26fa1ce3c790f9590868f0109289a044acb954525f933e2aa3b871c157d"
dependencies = [
"core-foundation 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation-sys 0.8.4",
"jni 0.19.0",
"log",
"once_cell",
"rustls 0.23.4",
"rustls-native-certs 0.7.0",
"rustls-platform-verifier-android",
"rustls-webpki 0.102.2",
"security-framework",
"security-framework-sys",
"webpki-roots 0.26.1",
"winapi 0.3.9",
]
[[package]]
name = "rustls-platform-verifier-android"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84e217e7fdc8466b5b35d30f8c0a30febd29173df4a3a0c2115d306b9c4117ad"
[[package]] [[package]]
name = "rustls-webpki" name = "rustls-webpki"
version = "0.101.7" version = "0.101.7"
@@ -5842,22 +5891,23 @@ dependencies = [
[[package]] [[package]]
name = "security-framework" name = "security-framework"
version = "2.9.2" version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"core-foundation 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation-sys 0.8.4", "core-foundation-sys 0.8.4",
"libc", "libc",
"num-bigint",
"security-framework-sys", "security-framework-sys",
] ]
[[package]] [[package]]
name = "security-framework-sys" name = "security-framework-sys"
version = "2.9.1" version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef"
dependencies = [ dependencies = [
"core-foundation-sys 0.8.4", "core-foundation-sys 0.8.4",
"libc", "libc",
@@ -6836,9 +6886,9 @@ dependencies = [
[[package]] [[package]]
name = "try-lock" name = "try-lock"
version = "0.2.4" version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]] [[package]]
name = "typenum" name = "typenum"
@@ -7291,9 +7341,9 @@ dependencies = [
[[package]] [[package]]
name = "webpki-roots" name = "webpki-roots"
version = "0.25.3" version = "0.25.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
[[package]] [[package]]
name = "webpki-roots" name = "webpki-roots"

View File

@@ -65,7 +65,6 @@ samplerate = { version = "0.2", optional = true }
uuid = { version = "1.3", features = ["v4"] } uuid = { version = "1.3", features = ["v4"] }
clap = "4.2" clap = "4.2"
rpassword = "7.2" rpassword = "7.2"
base64 = "0.21"
num_cpus = "1.15" num_cpus = "1.15"
bytes = { version = "1.4", features = ["serde"] } bytes = { version = "1.4", features = ["serde"] }
default-net = "0.14" default-net = "0.14"

View File

@@ -1104,7 +1104,7 @@ class _NetworkState extends State<_Network> with AutomaticKeepAliveClientMixin {
child: Column(children: [ child: Column(children: [
server(enabled), server(enabled),
_Card(title: 'Proxy', children: [ _Card(title: 'Proxy', children: [
_Button("Socks5/Http(s) Proxy", changeSocks5Proxy, _Button('Socks5/Http(s) Proxy', changeSocks5Proxy,
enabled: enabled), enabled: enabled),
]), ]),
]), ]),
@@ -2034,7 +2034,7 @@ void changeSocks5Proxy() async {
} }
return CustomAlertDialog( return CustomAlertDialog(
title: Text(translate("Socks5/Http(s) Proxy")), title: Text(translate('Socks5/Http(s) Proxy')),
content: ConstrainedBox( content: ConstrainedBox(
constraints: const BoxConstraints(minWidth: 500), constraints: const BoxConstraints(minWidth: 500),
child: Column( child: Column(
@@ -2052,7 +2052,7 @@ void changeSocks5Proxy() async {
child: TextField( child: TextField(
decoration: InputDecoration( decoration: InputDecoration(
errorText: proxyMsg.isNotEmpty ? proxyMsg : null, errorText: proxyMsg.isNotEmpty ? proxyMsg : null,
hintText: translate("Default proxy protocol is socks5"), hintText: translate('Default protocol and port are Socks5 and 1080'),
), ),
controller: proxyController, controller: proxyController,
autofocus: true, autofocus: true,

View File

@@ -17,7 +17,6 @@ bool refreshingUser = false;
class UserModel { class UserModel {
final RxString userName = ''.obs; final RxString userName = ''.obs;
final RxBool isAdmin = false.obs; final RxBool isAdmin = false.obs;
bool get isLogin => userName.isNotEmpty; bool get isLogin => userName.isNotEmpty;
WeakReference<FFI> parent; WeakReference<FFI> parent;

View File

@@ -13,9 +13,6 @@ class HttpService {
dynamic body, dynamic body,
}) async { }) async {
headers ??= {'Content-Type': 'application/json'}; headers ??= {'Content-Type': 'application/json'};
String headersJson = jsonEncode(headers);
String methodName = method.toString().split('.').last;
// Determine if there is currently a proxy setting, and if so, use FFI to call the Rust HTTP method. // Determine if there is currently a proxy setting, and if so, use FFI to call the Rust HTTP method.
final isProxy = await bind.mainGetProxyStatus(); final isProxy = await bind.mainGetProxyStatus();
@@ -23,13 +20,15 @@ class HttpService {
return await _pollFultterHttp(url, method, headers: headers, body: body); return await _pollFultterHttp(url, method, headers: headers, body: body);
} }
String headersJson = jsonEncode(headers);
String methodName = method.toString().split('.').last;
await bind.mainHttpRequest( await bind.mainHttpRequest(
url: url.toString(), url: url.toString(),
method: methodName.toLowerCase(), method: methodName.toLowerCase(),
body: body, body: body,
header: headersJson); header: headersJson);
var resJson = await _pollForResponse(); var resJson = await _pollForResponse(url.toString());
return _parseHttpResponse(resJson); return _parseHttpResponse(resJson);
} }
@@ -39,7 +38,7 @@ class HttpService {
Map<String, String>? headers, Map<String, String>? headers,
dynamic body, dynamic body,
}) async { }) async {
var response = http.Response('', 400); // 默认响应 var response = http.Response('', 400);
switch (method) { switch (method) {
case HttpMethod.get: case HttpMethod.get:
@@ -61,13 +60,18 @@ class HttpService {
return response; return response;
} }
Future<String> _pollForResponse() async { Future<String> _pollForResponse(String url) async {
String responseJson = await bind.mainGetAsyncStatus(); String? responseJson = " ";
while (responseJson == " ") { while (responseJson == " ") {
await Future.delayed(const Duration(milliseconds: 100)); responseJson = await bind.mainGetHttpStatus(url: url);
responseJson = await bind.mainGetAsyncStatus(); if (responseJson == null) {
throw Exception('The HTTP request failed');
}
if (responseJson == " ") {
await Future.delayed(const Duration(milliseconds: 100));
}
} }
return responseJson; return responseJson!;
} }
http.Response _parseHttpResponse(String responseJson) { http.Response _parseHttpResponse(String responseJson) {

View File

@@ -49,7 +49,7 @@ mac_address = "1.1"
machine-uid = { git = "https://github.com/21pages/machine-uid" } machine-uid = { git = "https://github.com/21pages/machine-uid" }
[target.'cfg(not(any(target_os = "macos", target_os = "windows")))'.dependencies] [target.'cfg(not(any(target_os = "macos", target_os = "windows")))'.dependencies]
tokio-rustls = "0.26" tokio-rustls = "0.26"
webpki-roots = "0.26" rustls-platform-verifier = "0.3"
rustls-pki-types = "1.4" rustls-pki-types = "1.4"
[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies] [target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
tokio-native-tls ="0.3" tokio-native-tls ="0.3"

View File

@@ -50,6 +50,7 @@ pub use machine_uid;
pub use sysinfo; pub use sysinfo;
pub use toml; pub use toml;
pub use uuid; pub use uuid;
pub use base64;
#[cfg(feature = "quic")] #[cfg(feature = "quic")]
pub type Stream = quic::Connection; pub type Stream = quic::Connection;

View File

@@ -1,27 +1,31 @@
use crate::bytes_codec::BytesCodec; use std::{
use crate::config::Socks5Server; convert::TryFrom,
use crate::tcp::{DynTcpStream, FramedStream}; io::Error as IoError,
use crate::ResultType; net::{SocketAddr, ToSocketAddrs},
use base64::engine::general_purpose; sync::Arc,
use base64::Engine; };
use base64::{engine::general_purpose, Engine};
use httparse::{Error as HttpParseError, Response, EMPTY_HEADER}; use httparse::{Error as HttpParseError, Response, EMPTY_HEADER};
use log::info; use log::info;
use rustls_pki_types; use rustls_pki_types;
use std::convert::TryFrom;
use std::io::Error as IoError;
use std::net::{SocketAddr, ToSocketAddrs};
use std::sync::Arc;
use thiserror::Error as ThisError; use thiserror::Error as ThisError;
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, BufStream}; use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, BufStream};
#[cfg(any(target_os = "windows", target_os = "macos"))] #[cfg(any(target_os = "windows", target_os = "macos"))]
use tokio_native_tls::{native_tls, TlsConnector, TlsStream}; use tokio_native_tls::{native_tls, TlsConnector, TlsStream};
#[cfg(not(any(target_os = "windows", target_os = "macos")))] #[cfg(not(any(target_os = "windows", target_os = "macos")))]
use tokio_rustls::{client::TlsStream, rustls, TlsConnector}; use tokio_rustls::{client::TlsStream, rustls, TlsConnector};
use tokio_socks::tcp::Socks5Stream; use tokio_socks::{tcp::Socks5Stream, IntoTargetAddr};
use tokio_socks::IntoTargetAddr;
use tokio_util::codec::Framed; use tokio_util::codec::Framed;
use url::Url; use url::Url;
use crate::{
bytes_codec::BytesCodec,
config::Socks5Server,
tcp::{DynTcpStream, FramedStream},
ResultType,
};
#[derive(Debug, ThisError)] #[derive(Debug, ThisError)]
pub enum ProxyError { pub enum ProxyError {
#[error("IO Error: {0}")] #[error("IO Error: {0}")]
@@ -450,20 +454,14 @@ impl Proxy {
Input: AsyncRead + AsyncWrite + Unpin, Input: AsyncRead + AsyncWrite + Unpin,
T: IntoTargetAddr<'a>, T: IntoTargetAddr<'a>,
{ {
let root_store = rustls::RootCertStore { let verifier = rustls_platform_verifier::tls_config();
roots: webpki_roots::TLS_SERVER_ROOTS.into(),
};
let config = rustls::ClientConfig::builder()
.with_root_certificates(root_store)
.with_no_client_auth();
let url_domain = self.intercept.get_domain()?; let url_domain = self.intercept.get_domain()?;
let domain = rustls_pki_types::ServerName::try_from(url_domain.as_str()) let domain = rustls_pki_types::ServerName::try_from(url_domain.as_str())
.map_err(|e| ProxyError::AddressResolutionFailed(e.to_string()))? .map_err(|e| ProxyError::AddressResolutionFailed(e.to_string()))?
.to_owned(); .to_owned();
let tls_connector = TlsConnector::from(Arc::new(config)); let tls_connector = TlsConnector::from(Arc::new(verifier));
let stream = tls_connector.connect(domain, io).await?; let stream = tls_connector.connect(domain, io).await?;
self.http_connect(stream, target).await self.http_connect(stream, target).await
} }

View File

@@ -1,6 +1,6 @@
use crate::proxy::IntoProxyScheme;
use crate::{ use crate::{
config::{Config, NetworkType}, config::{Config, NetworkType},
proxy::IntoProxyScheme,
tcp::FramedStream, tcp::FramedStream,
udp::FramedSocket, udp::FramedSocket,
ResultType, ResultType,

View File

@@ -1,6 +1,4 @@
use crate::config::Socks5Server; use crate::{bail, bytes_codec::BytesCodec, ResultType, config::Socks5Server, proxy::Proxy};
use crate::proxy::Proxy;
use crate::{bail, bytes_codec::BytesCodec, ResultType};
use anyhow::Context as AnyhowCtx; use anyhow::Context as AnyhowCtx;
use bytes::{BufMut, Bytes, BytesMut}; use bytes::{BufMut, Bytes, BytesMut};
use futures::{SinkExt, StreamExt}; use futures::{SinkExt, StreamExt};

View File

@@ -31,7 +31,7 @@ use hbb_common::tokio::sync::mpsc::UnboundedSender;
use hbb_common::tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver}; use hbb_common::tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
use hbb_common::{ use hbb_common::{
allow_err, allow_err,
anyhow::{anyhow, Context}, anyhow::Context,
bail, bail,
config::{ config::{
self, Config, LocalConfig, PeerConfig, PeerInfoSerde, Resolution, CONNECT_TIMEOUT, self, Config, LocalConfig, PeerConfig, PeerInfoSerde, Resolution, CONNECT_TIMEOUT,

View File

@@ -1,4 +1,3 @@
use serde_json::Value;
use std::{ use std::{
borrow::Cow, borrow::Cow,
future::Future, future::Future,
@@ -6,6 +5,8 @@ use std::{
task::Poll, task::Poll,
}; };
use serde_json::Value;
#[derive(Debug, Eq, PartialEq)] #[derive(Debug, Eq, PartialEq)]
pub enum GrabState { pub enum GrabState {
Ready, Ready,
@@ -124,7 +125,7 @@ use hbb_common::compress::decompress;
use hbb_common::{ use hbb_common::{
allow_err, allow_err,
anyhow::{anyhow, Context}, anyhow::{anyhow, Context},
bail, bail, base64,
bytes::Bytes, bytes::Bytes,
compress::compress as compress_func, compress::compress as compress_func,
config::{self, Config, CONNECT_TIMEOUT, READ_TIMEOUT}, config::{self, Config, CONNECT_TIMEOUT, READ_TIMEOUT},
@@ -145,10 +146,11 @@ use hbb_common::{
}; };
// #[cfg(any(target_os = "android", target_os = "ios", feature = "cli"))] // #[cfg(any(target_os = "android", target_os = "ios", feature = "cli"))]
use hbb_common::{config::RENDEZVOUS_PORT, futures::future::join_all}; use hbb_common::{config::RENDEZVOUS_PORT, futures::future::join_all};
use hbb_common::log::debug;
use crate::hbbs_http::create_http_client_async; use crate::{
use crate::ui_interface::{get_option, set_option}; hbbs_http::create_http_client_async,
ui_interface::{get_option, set_option},
};
pub type NotifyMessageBox = fn(String, String, String, String) -> dyn Future<Output = ()>; pub type NotifyMessageBox = fn(String, String, String, String) -> dyn Future<Output = ()>;
@@ -1095,7 +1097,6 @@ pub async fn http_request_sync(
header: String, header: String,
) -> ResultType<String> { ) -> ResultType<String> {
let http_client = create_http_client_async(); let http_client = create_http_client_async();
debug!("url: {}, method: {}, body: {:?}, header: {}", url, method, body,header);
let mut http_client = match method.as_str() { let mut http_client = match method.as_str() {
"get" => http_client.get(url), "get" => http_client.get(url),
"post" => http_client.post(url), "post" => http_client.post(url),

View File

@@ -1,5 +1,9 @@
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _}; use hbb_common::{
use hbb_common::{bail, sodiumoxide::crypto::sign, ResultType}; bail,
base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _},
sodiumoxide::crypto::sign,
ResultType,
};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)] #[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]

View File

@@ -745,6 +745,10 @@ pub fn main_get_async_status() -> String {
get_async_job_status() get_async_job_status()
} }
pub fn main_get_http_status(url: String) -> Option<String> {
get_async_http_status(url)
}
pub fn main_get_option(key: String) -> String { pub fn main_get_option(key: String) -> String {
get_option(key) get_option(key)
} }

View File

@@ -8,7 +8,6 @@ macro_rules! configure_http_client {
($builder:expr, $Client: ty) => {{ ($builder:expr, $Client: ty) => {{
let mut builder = $builder; let mut builder = $builder;
let client = if let Some(conf) = Config::get_socks() { let client = if let Some(conf) = Config::get_socks() {
info!("Create an http request client with proxy forwarding");
let proxy_result = Proxy::from_conf(&conf, None); let proxy_result = Proxy::from_conf(&conf, None);
match proxy_result { match proxy_result {

View File

@@ -240,7 +240,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Invalid folder name", "无效文件夹名称"), ("Invalid folder name", "无效文件夹名称"),
("Socks5 Proxy", "Socks5 代理"), ("Socks5 Proxy", "Socks5 代理"),
("Socks5/Http(s) Proxy", "Socks5/Http(s) 代理"), ("Socks5/Http(s) Proxy", "Socks5/Http(s) 代理"),
("Default proxy protocol is socks5", "默认代理协议为socks5"), ("Default protocol and port are Socks5 and 1080", "默认代理协议及端口为Socks5和1080"),
("Discovered", "已发现"), ("Discovered", "已发现"),
("install_daemon_tip", "为了开机启动,请安装系统服务。"), ("install_daemon_tip", "为了开机启动,请安装系统服务。"),
("Remote ID", "远程 ID"), ("Remote ID", "远程 ID"),

View File

@@ -61,7 +61,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Remove from Favorites", "Remove from favorites"), ("Remove from Favorites", "Remove from favorites"),
("Socks5 Proxy", "Socks5 proxy"), ("Socks5 Proxy", "Socks5 proxy"),
("Socks5/Http(s) Proxy", "Socks5/Http(s) proxy"), ("Socks5/Http(s) Proxy", "Socks5/Http(s) proxy"),
("Default proxy protocol is socks5", "Default proxy protocol is socks5"), ("Default protocol and port are Socks5 and 1080", "Default protocol and port are Socks5 and 1080"),
("install_daemon_tip", "For starting on boot, you need to install system service."), ("install_daemon_tip", "For starting on boot, you need to install system service."),
("Are you sure to close the connection?", "Are you sure you want to close the connection?"), ("Are you sure to close the connection?", "Are you sure you want to close the connection?"),
("One-Finger Tap", "One-finger tap"), ("One-Finger Tap", "One-finger tap"),

View File

@@ -239,7 +239,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Empty", "空空如也"), ("Empty", "空空如也"),
("Invalid folder name", "資料夾名稱無效"), ("Invalid folder name", "資料夾名稱無效"),
("Socks5 Proxy", "Socks5 代理伺服器"), ("Socks5 Proxy", "Socks5 代理伺服器"),
("Socks5/Http(s) Proxy", "Socks5/Http(s) 代理伺服器"), ("Socks5/Http(s) Proxy", "Socks5/Http(s) 代理伺服器"),
("Discovered", "已探索"), ("Discovered", "已探索"),
("install_daemon_tip", "若要在開機時啟動,您需要安裝系統服務。"), ("install_daemon_tip", "若要在開機時啟動,您需要安裝系統服務。"),
("Remote ID", "遠端 ID"), ("Remote ID", "遠端 ID"),

View File

@@ -1,6 +1,5 @@
mod custom_server; mod custom_server;
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _}; use hbb_common::{ResultType, base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _}};
use hbb_common::ResultType;
use custom_server::*; use custom_server::*;
fn gen_name(lic: &CustomServer) -> ResultType<String> { fn gen_name(lic: &CustomServer) -> ResultType<String> {

View File

@@ -5,7 +5,6 @@ use crate::{
ui_interface::get_api_server, ui_interface::get_api_server,
}; };
use hbb_common::{lazy_static, log, message_proto::PluginRequest}; use hbb_common::{lazy_static, log, message_proto::PluginRequest};
use reqwest::blocking::Client;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use serde_json; use serde_json;
use std::{ use std::{

View File

@@ -9,14 +9,13 @@ use std::{
use uuid::Uuid; use uuid::Uuid;
use hbb_common::log::info;
use hbb_common::proxy::Proxy;
use hbb_common::{ use hbb_common::{
allow_err, allow_err,
anyhow::{self, bail}, anyhow::{self, bail},
config::{self, Config, CONNECT_TIMEOUT, READ_TIMEOUT, REG_INTERVAL, RENDEZVOUS_PORT}, config::{self, Config, CONNECT_TIMEOUT, READ_TIMEOUT, REG_INTERVAL, RENDEZVOUS_PORT},
futures::future::join_all, futures::future::join_all,
log, log,
proxy::Proxy,
protobuf::Message as _, protobuf::Message as _,
rendezvous_proto::*, rendezvous_proto::*,
sleep, sleep,
@@ -389,7 +388,7 @@ impl RendezvousMediator {
} }
pub async fn start(server: ServerPtr, host: String) -> ResultType<()> { pub async fn start(server: ServerPtr, host: String) -> ResultType<()> {
info!("start rendezvous mediator of {}", host); log::info!("start rendezvous mediator of {}", host);
//If the investment agent type is http or https, then tcp forwarding is enabled. //If the investment agent type is http or https, then tcp forwarding is enabled.
let is_http_proxy = if let Some(conf) = Config::get_socks() { let is_http_proxy = if let Some(conf) = Config::get_socks() {
let proxy = Proxy::from_conf(&conf, None)?; let proxy = Proxy::from_conf(&conf, None)?;

View File

@@ -564,6 +564,10 @@ impl UI {
get_async_job_status() get_async_job_status()
} }
fn get_http_status(&self, url: String) -> Option<String> {
get_async_http_status(url)
}
fn t(&self, name: String) -> String { fn t(&self, name: String) -> String {
crate::client::translate(name) crate::client::translate(name)
} }

View File

@@ -4,7 +4,7 @@ use hbb_common::{
allow_err, allow_err,
bytes::Bytes, bytes::Bytes,
config::{ config::{
self, Config, LocalConfig, PeerConfig, CONNECT_TIMEOUT, HARD_SETTINGS, RENDEZVOUS_PORT, self, Config, LocalConfig, PeerConfig, CONNECT_TIMEOUT, RENDEZVOUS_PORT,
}, },
directories_next, directories_next,
futures::future::join_all, futures::future::join_all,
@@ -24,7 +24,6 @@ use std::{
collections::HashMap, collections::HashMap,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
use hbb_common::log::error;
use crate::common::SOFTWARE_UPDATE_URL; use crate::common::SOFTWARE_UPDATE_URL;
#[cfg(feature = "flutter")] #[cfg(feature = "flutter")]
@@ -66,6 +65,7 @@ lazy_static::lazy_static! {
id: "".to_owned(), id: "".to_owned(),
})); }));
static ref ASYNC_JOB_STATUS : Arc<Mutex<String>> = Default::default(); static ref ASYNC_JOB_STATUS : Arc<Mutex<String>> = Default::default();
static ref ASYNC_HTTP_STATUS : Arc<Mutex<HashMap<String, String>>> = Arc::new(Mutex::new(HashMap::new()));
static ref TEMPORARY_PASSWD : Arc<Mutex<String>> = Arc::new(Mutex::new("".to_owned())); static ref TEMPORARY_PASSWD : Arc<Mutex<String>> = Arc::new(Mutex::new("".to_owned()));
} }
@@ -426,6 +426,8 @@ pub fn set_socks(proxy: String, username: String, password: String) {
pub fn get_proxy_status() -> bool { pub fn get_proxy_status() -> bool {
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
return ipc::get_proxy_status(); return ipc::get_proxy_status();
// Currently, only the desktop version has proxy settings.
#[cfg(any(target_os = "android", target_os = "ios"))] #[cfg(any(target_os = "android", target_os = "ios"))]
return false; return false;
} }
@@ -719,15 +721,25 @@ pub fn change_id(id: String) {
#[inline] #[inline]
pub fn http_request(url: String, method: String, body: Option<String>, header: String) { pub fn http_request(url: String, method: String, body: Option<String>, header: String) {
*ASYNC_JOB_STATUS.lock().unwrap() = " ".to_owned(); // Respond to concurrent requests for resources
let current_request = ASYNC_HTTP_STATUS.clone();
current_request.lock().unwrap().insert(url.clone()," ".to_owned());
std::thread::spawn(move || { std::thread::spawn(move || {
*ASYNC_JOB_STATUS.lock().unwrap() = let res = match crate::http_request_sync(url.clone(), method, body, header) {
match crate::http_request_sync(url, method, body, header) { Err(err) => { log::error!("{}", err); err.to_string() },
Err(err) => { error!("{}", err); err.to_string() },
Ok(text) => text, Ok(text) => text,
}; };
current_request.lock().unwrap().insert(url,res);
}); });
} }
#[inline]
pub fn get_async_http_status(url: String) -> Option<String> {
match ASYNC_HTTP_STATUS.lock().unwrap().get(&url) {
None => {None}
Some(_str) => {Some(_str.to_string())}
}
}
#[inline] #[inline]
pub fn post_request(url: String, body: String, header: String) { pub fn post_request(url: String, body: String, header: String) {