fix: Optimize HTTP requests, refine translations, and fix dependencies
This commit is contained in:
108
Cargo.lock
generated
108
Cargo.lock
generated
@@ -311,9 +311,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "async-compression"
|
||||
version = "0.4.5"
|
||||
version = "0.4.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc2d0cfb2a7388d34f590e76686704c494ed7aaceed62ee1ba35cbf363abc2a5"
|
||||
checksum = "07dbbf24db18d609b1462965249abdf49129ccad073ec257da372adc83259c60"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"futures-core",
|
||||
@@ -1897,9 +1897,9 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.33"
|
||||
version = "0.8.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1"
|
||||
checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
@@ -2933,9 +2933,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "h2"
|
||||
version = "0.3.24"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9"
|
||||
checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
@@ -3009,6 +3009,7 @@ dependencies = [
|
||||
"rand 0.8.5",
|
||||
"regex",
|
||||
"rustls-pki-types",
|
||||
"rustls-platform-verifier",
|
||||
"serde 1.0.190",
|
||||
"serde_derive",
|
||||
"serde_json 1.0.107",
|
||||
@@ -3024,7 +3025,6 @@ dependencies = [
|
||||
"toml 0.7.8",
|
||||
"url",
|
||||
"uuid",
|
||||
"webpki-roots 0.26.1",
|
||||
"winapi 0.3.9",
|
||||
"zstd 0.13.0",
|
||||
]
|
||||
@@ -3100,9 +3100,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "0.2.9"
|
||||
version = "0.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482"
|
||||
checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
@@ -3111,9 +3111,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "http-body"
|
||||
version = "0.4.5"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1"
|
||||
checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http",
|
||||
@@ -3153,9 +3153,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "0.14.27"
|
||||
version = "0.14.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468"
|
||||
checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
@@ -3168,7 +3168,7 @@ dependencies = [
|
||||
"httpdate",
|
||||
"itoa 1.0.9",
|
||||
"pin-project-lite",
|
||||
"socket2 0.4.10",
|
||||
"socket2 0.5.5",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
@@ -4979,7 +4979,7 @@ dependencies = [
|
||||
"ring 0.16.20",
|
||||
"rustc-hash",
|
||||
"rustls 0.20.9",
|
||||
"rustls-native-certs",
|
||||
"rustls-native-certs 0.6.3",
|
||||
"slab",
|
||||
"thiserror",
|
||||
"tinyvec",
|
||||
@@ -5314,7 +5314,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.11.23"
|
||||
source = "git+https://github.com/rustdesk-org/reqwest"
|
||||
source = "git+https://github.com/rustdesk-org/reqwest#9cb758c9fb2f4edc62eb790acfd45a6a3da21ed3"
|
||||
dependencies = [
|
||||
"async-compression",
|
||||
"base64 0.21.5",
|
||||
@@ -5337,8 +5337,8 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"rustls 0.21.10",
|
||||
"rustls-native-certs",
|
||||
"rustls-pemfile",
|
||||
"rustls-native-certs 0.6.3",
|
||||
"rustls-pemfile 1.0.3",
|
||||
"serde 1.0.190",
|
||||
"serde_json 1.0.107",
|
||||
"serde_urlencoded",
|
||||
@@ -5354,7 +5354,7 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"webpki-roots 0.25.3",
|
||||
"webpki-roots 0.25.4",
|
||||
"winreg 0.50.0",
|
||||
]
|
||||
|
||||
@@ -5500,7 +5500,6 @@ dependencies = [
|
||||
"arboard",
|
||||
"async-process",
|
||||
"async-trait",
|
||||
"base64 0.21.5",
|
||||
"bytes",
|
||||
"cc",
|
||||
"cfg-if 1.0.0",
|
||||
@@ -5687,7 +5686,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00"
|
||||
dependencies = [
|
||||
"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",
|
||||
"security-framework",
|
||||
]
|
||||
@@ -5701,12 +5713,49 @@ dependencies = [
|
||||
"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]]
|
||||
name = "rustls-pki-types"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "rustls-webpki"
|
||||
version = "0.101.7"
|
||||
@@ -5842,22 +5891,23 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "security-framework"
|
||||
version = "2.9.2"
|
||||
version = "2.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de"
|
||||
checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"core-foundation 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"core-foundation-sys 0.8.4",
|
||||
"libc",
|
||||
"num-bigint",
|
||||
"security-framework-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "security-framework-sys"
|
||||
version = "2.9.1"
|
||||
version = "2.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a"
|
||||
checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef"
|
||||
dependencies = [
|
||||
"core-foundation-sys 0.8.4",
|
||||
"libc",
|
||||
@@ -6836,9 +6886,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "try-lock"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
|
||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
@@ -7291,9 +7341,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "0.25.3"
|
||||
version = "0.25.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10"
|
||||
checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1"
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
|
||||
@@ -65,7 +65,6 @@ samplerate = { version = "0.2", optional = true }
|
||||
uuid = { version = "1.3", features = ["v4"] }
|
||||
clap = "4.2"
|
||||
rpassword = "7.2"
|
||||
base64 = "0.21"
|
||||
num_cpus = "1.15"
|
||||
bytes = { version = "1.4", features = ["serde"] }
|
||||
default-net = "0.14"
|
||||
|
||||
@@ -1104,7 +1104,7 @@ class _NetworkState extends State<_Network> with AutomaticKeepAliveClientMixin {
|
||||
child: Column(children: [
|
||||
server(enabled),
|
||||
_Card(title: 'Proxy', children: [
|
||||
_Button("Socks5/Http(s) Proxy", changeSocks5Proxy,
|
||||
_Button('Socks5/Http(s) Proxy', changeSocks5Proxy,
|
||||
enabled: enabled),
|
||||
]),
|
||||
]),
|
||||
@@ -2034,7 +2034,7 @@ void changeSocks5Proxy() async {
|
||||
}
|
||||
|
||||
return CustomAlertDialog(
|
||||
title: Text(translate("Socks5/Http(s) Proxy")),
|
||||
title: Text(translate('Socks5/Http(s) Proxy')),
|
||||
content: ConstrainedBox(
|
||||
constraints: const BoxConstraints(minWidth: 500),
|
||||
child: Column(
|
||||
@@ -2052,7 +2052,7 @@ void changeSocks5Proxy() async {
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
errorText: proxyMsg.isNotEmpty ? proxyMsg : null,
|
||||
hintText: translate("Default proxy protocol is socks5"),
|
||||
hintText: translate('Default protocol and port are Socks5 and 1080'),
|
||||
),
|
||||
controller: proxyController,
|
||||
autofocus: true,
|
||||
|
||||
@@ -17,7 +17,6 @@ bool refreshingUser = false;
|
||||
class UserModel {
|
||||
final RxString userName = ''.obs;
|
||||
final RxBool isAdmin = false.obs;
|
||||
|
||||
bool get isLogin => userName.isNotEmpty;
|
||||
WeakReference<FFI> parent;
|
||||
|
||||
|
||||
@@ -13,9 +13,6 @@ class HttpService {
|
||||
dynamic body,
|
||||
}) async {
|
||||
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.
|
||||
final isProxy = await bind.mainGetProxyStatus();
|
||||
|
||||
@@ -23,13 +20,15 @@ class HttpService {
|
||||
return await _pollFultterHttp(url, method, headers: headers, body: body);
|
||||
}
|
||||
|
||||
String headersJson = jsonEncode(headers);
|
||||
String methodName = method.toString().split('.').last;
|
||||
await bind.mainHttpRequest(
|
||||
url: url.toString(),
|
||||
method: methodName.toLowerCase(),
|
||||
body: body,
|
||||
header: headersJson);
|
||||
|
||||
var resJson = await _pollForResponse();
|
||||
var resJson = await _pollForResponse(url.toString());
|
||||
return _parseHttpResponse(resJson);
|
||||
}
|
||||
|
||||
@@ -39,7 +38,7 @@ class HttpService {
|
||||
Map<String, String>? headers,
|
||||
dynamic body,
|
||||
}) async {
|
||||
var response = http.Response('', 400); // 默认响应
|
||||
var response = http.Response('', 400);
|
||||
|
||||
switch (method) {
|
||||
case HttpMethod.get:
|
||||
@@ -61,13 +60,18 @@ class HttpService {
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<String> _pollForResponse() async {
|
||||
String responseJson = await bind.mainGetAsyncStatus();
|
||||
Future<String> _pollForResponse(String url) async {
|
||||
String? responseJson = " ";
|
||||
while (responseJson == " ") {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
responseJson = await bind.mainGetAsyncStatus();
|
||||
responseJson = await bind.mainGetHttpStatus(url: url);
|
||||
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) {
|
||||
|
||||
@@ -49,7 +49,7 @@ mac_address = "1.1"
|
||||
machine-uid = { git = "https://github.com/21pages/machine-uid" }
|
||||
[target.'cfg(not(any(target_os = "macos", target_os = "windows")))'.dependencies]
|
||||
tokio-rustls = "0.26"
|
||||
webpki-roots = "0.26"
|
||||
rustls-platform-verifier = "0.3"
|
||||
rustls-pki-types = "1.4"
|
||||
[target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies]
|
||||
tokio-native-tls ="0.3"
|
||||
|
||||
@@ -50,6 +50,7 @@ pub use machine_uid;
|
||||
pub use sysinfo;
|
||||
pub use toml;
|
||||
pub use uuid;
|
||||
pub use base64;
|
||||
|
||||
#[cfg(feature = "quic")]
|
||||
pub type Stream = quic::Connection;
|
||||
|
||||
@@ -1,27 +1,31 @@
|
||||
use crate::bytes_codec::BytesCodec;
|
||||
use crate::config::Socks5Server;
|
||||
use crate::tcp::{DynTcpStream, FramedStream};
|
||||
use crate::ResultType;
|
||||
use base64::engine::general_purpose;
|
||||
use base64::Engine;
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
io::Error as IoError,
|
||||
net::{SocketAddr, ToSocketAddrs},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use base64::{engine::general_purpose, Engine};
|
||||
use httparse::{Error as HttpParseError, Response, EMPTY_HEADER};
|
||||
use log::info;
|
||||
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 tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, BufStream};
|
||||
#[cfg(any(target_os = "windows", target_os = "macos"))]
|
||||
use tokio_native_tls::{native_tls, TlsConnector, TlsStream};
|
||||
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
||||
use tokio_rustls::{client::TlsStream, rustls, TlsConnector};
|
||||
use tokio_socks::tcp::Socks5Stream;
|
||||
use tokio_socks::IntoTargetAddr;
|
||||
use tokio_socks::{tcp::Socks5Stream, IntoTargetAddr};
|
||||
use tokio_util::codec::Framed;
|
||||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
bytes_codec::BytesCodec,
|
||||
config::Socks5Server,
|
||||
tcp::{DynTcpStream, FramedStream},
|
||||
ResultType,
|
||||
};
|
||||
|
||||
#[derive(Debug, ThisError)]
|
||||
pub enum ProxyError {
|
||||
#[error("IO Error: {0}")]
|
||||
@@ -450,20 +454,14 @@ impl Proxy {
|
||||
Input: AsyncRead + AsyncWrite + Unpin,
|
||||
T: IntoTargetAddr<'a>,
|
||||
{
|
||||
let root_store = rustls::RootCertStore {
|
||||
roots: webpki_roots::TLS_SERVER_ROOTS.into(),
|
||||
};
|
||||
|
||||
let config = rustls::ClientConfig::builder()
|
||||
.with_root_certificates(root_store)
|
||||
.with_no_client_auth();
|
||||
let verifier = rustls_platform_verifier::tls_config();
|
||||
let url_domain = self.intercept.get_domain()?;
|
||||
|
||||
let domain = rustls_pki_types::ServerName::try_from(url_domain.as_str())
|
||||
.map_err(|e| ProxyError::AddressResolutionFailed(e.to_string()))?
|
||||
.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?;
|
||||
self.http_connect(stream, target).await
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::proxy::IntoProxyScheme;
|
||||
use crate::{
|
||||
config::{Config, NetworkType},
|
||||
proxy::IntoProxyScheme,
|
||||
tcp::FramedStream,
|
||||
udp::FramedSocket,
|
||||
ResultType,
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
use crate::config::Socks5Server;
|
||||
use crate::proxy::Proxy;
|
||||
use crate::{bail, bytes_codec::BytesCodec, ResultType};
|
||||
use crate::{bail, bytes_codec::BytesCodec, ResultType, config::Socks5Server, proxy::Proxy};
|
||||
use anyhow::Context as AnyhowCtx;
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
use futures::{SinkExt, StreamExt};
|
||||
|
||||
@@ -31,7 +31,7 @@ use hbb_common::tokio::sync::mpsc::UnboundedSender;
|
||||
use hbb_common::tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
anyhow::{anyhow, Context},
|
||||
anyhow::Context,
|
||||
bail,
|
||||
config::{
|
||||
self, Config, LocalConfig, PeerConfig, PeerInfoSerde, Resolution, CONNECT_TIMEOUT,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use serde_json::Value;
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
future::Future,
|
||||
@@ -6,6 +5,8 @@ use std::{
|
||||
task::Poll,
|
||||
};
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum GrabState {
|
||||
Ready,
|
||||
@@ -124,7 +125,7 @@ use hbb_common::compress::decompress;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
anyhow::{anyhow, Context},
|
||||
bail,
|
||||
bail, base64,
|
||||
bytes::Bytes,
|
||||
compress::compress as compress_func,
|
||||
config::{self, Config, CONNECT_TIMEOUT, READ_TIMEOUT},
|
||||
@@ -145,10 +146,11 @@ use hbb_common::{
|
||||
};
|
||||
// #[cfg(any(target_os = "android", target_os = "ios", feature = "cli"))]
|
||||
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::ui_interface::{get_option, set_option};
|
||||
use crate::{
|
||||
hbbs_http::create_http_client_async,
|
||||
ui_interface::{get_option, set_option},
|
||||
};
|
||||
|
||||
pub type NotifyMessageBox = fn(String, String, String, String) -> dyn Future<Output = ()>;
|
||||
|
||||
@@ -1095,7 +1097,6 @@ pub async fn http_request_sync(
|
||||
header: String,
|
||||
) -> ResultType<String> {
|
||||
let http_client = create_http_client_async();
|
||||
debug!("url: {}, method: {}, body: {:?}, header: {}", url, method, body,header);
|
||||
let mut http_client = match method.as_str() {
|
||||
"get" => http_client.get(url),
|
||||
"post" => http_client.post(url),
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _};
|
||||
use hbb_common::{bail, sodiumoxide::crypto::sign, ResultType};
|
||||
use hbb_common::{
|
||||
bail,
|
||||
base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _},
|
||||
sodiumoxide::crypto::sign,
|
||||
ResultType,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, PartialEq, Default, Serialize, Deserialize, Clone)]
|
||||
|
||||
@@ -745,6 +745,10 @@ pub fn main_get_async_status() -> String {
|
||||
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 {
|
||||
get_option(key)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ macro_rules! configure_http_client {
|
||||
($builder:expr, $Client: ty) => {{
|
||||
let mut builder = $builder;
|
||||
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);
|
||||
|
||||
match proxy_result {
|
||||
|
||||
@@ -240,7 +240,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Invalid folder name", "无效文件夹名称"),
|
||||
("Socks5 Proxy", "Socks5 代理"),
|
||||
("Socks5/Http(s) Proxy", "Socks5/Http(s) 代理"),
|
||||
("Default proxy protocol is socks5", "默认代理协议为socks5"),
|
||||
("Default protocol and port are Socks5 and 1080", "默认代理协议及端口为Socks5和1080"),
|
||||
("Discovered", "已发现"),
|
||||
("install_daemon_tip", "为了开机启动,请安装系统服务。"),
|
||||
("Remote ID", "远程 ID"),
|
||||
|
||||
@@ -61,7 +61,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Remove from Favorites", "Remove from favorites"),
|
||||
("Socks5 Proxy", "Socks5 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."),
|
||||
("Are you sure to close the connection?", "Are you sure you want to close the connection?"),
|
||||
("One-Finger Tap", "One-finger tap"),
|
||||
|
||||
@@ -239,7 +239,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Empty", "空空如也"),
|
||||
("Invalid folder name", "資料夾名稱無效"),
|
||||
("Socks5 Proxy", "Socks5 代理伺服器"),
|
||||
("Socks5/Http(s) Proxy", "Socks5/Http(s) 代理伺服器"),
|
||||
("Socks5/Http(s) Proxy", "Socks5/Http(s) 代理伺服器"),
|
||||
("Discovered", "已探索"),
|
||||
("install_daemon_tip", "若要在開機時啟動,您需要安裝系統服務。"),
|
||||
("Remote ID", "遠端 ID"),
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
mod custom_server;
|
||||
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _};
|
||||
use hbb_common::ResultType;
|
||||
use hbb_common::{ResultType, base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine as _}};
|
||||
use custom_server::*;
|
||||
|
||||
fn gen_name(lic: &CustomServer) -> ResultType<String> {
|
||||
|
||||
@@ -5,7 +5,6 @@ use crate::{
|
||||
ui_interface::get_api_server,
|
||||
};
|
||||
use hbb_common::{lazy_static, log, message_proto::PluginRequest};
|
||||
use reqwest::blocking::Client;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use serde_json;
|
||||
use std::{
|
||||
|
||||
@@ -9,14 +9,13 @@ use std::{
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use hbb_common::log::info;
|
||||
use hbb_common::proxy::Proxy;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
anyhow::{self, bail},
|
||||
config::{self, Config, CONNECT_TIMEOUT, READ_TIMEOUT, REG_INTERVAL, RENDEZVOUS_PORT},
|
||||
futures::future::join_all,
|
||||
log,
|
||||
proxy::Proxy,
|
||||
protobuf::Message as _,
|
||||
rendezvous_proto::*,
|
||||
sleep,
|
||||
@@ -389,7 +388,7 @@ impl RendezvousMediator {
|
||||
}
|
||||
|
||||
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.
|
||||
let is_http_proxy = if let Some(conf) = Config::get_socks() {
|
||||
let proxy = Proxy::from_conf(&conf, None)?;
|
||||
|
||||
@@ -564,6 +564,10 @@ impl UI {
|
||||
get_async_job_status()
|
||||
}
|
||||
|
||||
fn get_http_status(&self, url: String) -> Option<String> {
|
||||
get_async_http_status(url)
|
||||
}
|
||||
|
||||
fn t(&self, name: String) -> String {
|
||||
crate::client::translate(name)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use hbb_common::{
|
||||
allow_err,
|
||||
bytes::Bytes,
|
||||
config::{
|
||||
self, Config, LocalConfig, PeerConfig, CONNECT_TIMEOUT, HARD_SETTINGS, RENDEZVOUS_PORT,
|
||||
self, Config, LocalConfig, PeerConfig, CONNECT_TIMEOUT, RENDEZVOUS_PORT,
|
||||
},
|
||||
directories_next,
|
||||
futures::future::join_all,
|
||||
@@ -24,7 +24,6 @@ use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use hbb_common::log::error;
|
||||
|
||||
use crate::common::SOFTWARE_UPDATE_URL;
|
||||
#[cfg(feature = "flutter")]
|
||||
@@ -66,6 +65,7 @@ lazy_static::lazy_static! {
|
||||
id: "".to_owned(),
|
||||
}));
|
||||
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()));
|
||||
}
|
||||
|
||||
@@ -426,6 +426,8 @@ pub fn set_socks(proxy: String, username: String, password: String) {
|
||||
pub fn get_proxy_status() -> bool {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
return ipc::get_proxy_status();
|
||||
|
||||
// Currently, only the desktop version has proxy settings.
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
return false;
|
||||
}
|
||||
@@ -719,15 +721,25 @@ pub fn change_id(id: String) {
|
||||
|
||||
#[inline]
|
||||
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 || {
|
||||
*ASYNC_JOB_STATUS.lock().unwrap() =
|
||||
match crate::http_request_sync(url, method, body, header) {
|
||||
Err(err) => { error!("{}", err); err.to_string() },
|
||||
let res = match crate::http_request_sync(url.clone(), method, body, header) {
|
||||
Err(err) => { log::error!("{}", err); err.to_string() },
|
||||
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]
|
||||
pub fn post_request(url: String, body: String, header: String) {
|
||||
|
||||
Reference in New Issue
Block a user