mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/app.git
synced 2025-06-28 04:24:45 +08:00
feat: RsProcess
This commit is contained in:
@ -11,7 +11,7 @@ strip = "debuginfo"
|
||||
crate-type = ["cdylib", "staticlib"]
|
||||
|
||||
[dependencies]
|
||||
flutter_rust_bridge = "=2.0.0-dev.32"
|
||||
flutter_rust_bridge = { version = "=2.0.0-dev.32" }
|
||||
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros", "process"] }
|
||||
url = "2.5"
|
||||
async-std = "1.12"
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
use reqwest::Method;
|
||||
use crate::http_package;
|
||||
use crate::http_package::RustHttpResponse;
|
||||
use reqwest::Method;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub enum MyMethod {
|
||||
Options,
|
||||
@ -17,15 +17,15 @@ pub enum MyMethod {
|
||||
|
||||
fn _my_method_to_hyper_method(m: MyMethod) -> Method {
|
||||
return match m {
|
||||
MyMethod::Options => { Method::OPTIONS }
|
||||
MyMethod::Gets => { Method::GET }
|
||||
MyMethod::Post => { Method::POST }
|
||||
MyMethod::Put => { Method::PUT }
|
||||
MyMethod::Delete => { Method::DELETE }
|
||||
MyMethod::Head => { Method::HEAD }
|
||||
MyMethod::Trace => { Method::TRACE }
|
||||
MyMethod::Connect => { Method::CONNECT }
|
||||
MyMethod::Patch => { Method::PATCH }
|
||||
MyMethod::Options => Method::OPTIONS,
|
||||
MyMethod::Gets => Method::GET,
|
||||
MyMethod::Post => Method::POST,
|
||||
MyMethod::Put => Method::PUT,
|
||||
MyMethod::Delete => Method::DELETE,
|
||||
MyMethod::Head => Method::HEAD,
|
||||
MyMethod::Trace => Method::TRACE,
|
||||
MyMethod::Connect => Method::CONNECT,
|
||||
MyMethod::Patch => Method::PATCH,
|
||||
};
|
||||
}
|
||||
|
||||
@ -33,11 +33,21 @@ pub fn set_default_header(headers: HashMap<String, String>) {
|
||||
http_package::set_default_header(headers)
|
||||
}
|
||||
|
||||
pub async fn fetch(method: MyMethod,
|
||||
url: String,
|
||||
headers: Option<HashMap<String, String>>,
|
||||
input_data: Option<Vec<u8>>, with_ip_address: Option<String>) -> anyhow::Result<RustHttpResponse> {
|
||||
http_package::fetch(_my_method_to_hyper_method(method), url, headers, input_data, with_ip_address).await
|
||||
pub async fn fetch(
|
||||
method: MyMethod,
|
||||
url: String,
|
||||
headers: Option<HashMap<String, String>>,
|
||||
input_data: Option<Vec<u8>>,
|
||||
with_ip_address: Option<String>,
|
||||
) -> anyhow::Result<RustHttpResponse> {
|
||||
http_package::fetch(
|
||||
_my_method_to_hyper_method(method),
|
||||
url,
|
||||
headers,
|
||||
input_data,
|
||||
with_ip_address,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn dns_lookup_txt(host: String) -> anyhow::Result<Vec<String>> {
|
||||
@ -46,4 +56,4 @@ pub async fn dns_lookup_txt(host: String) -> anyhow::Result<Vec<String>> {
|
||||
|
||||
pub async fn dns_lookup_ips(host: String) -> anyhow::Result<Vec<String>> {
|
||||
http_package::dns_lookup_ips(host).await
|
||||
}
|
||||
}
|
||||
|
@ -3,4 +3,4 @@
|
||||
//
|
||||
pub mod http_api;
|
||||
|
||||
pub mod process_api;
|
||||
pub mod rs_process;
|
||||
|
@ -1,90 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use tokio::io::{AsyncBufReadExt, BufReader};
|
||||
|
||||
use crate::frb_generated::StreamSink;
|
||||
|
||||
pub async fn start_process(
|
||||
executable: String,
|
||||
arguments: Vec<String>,
|
||||
working_directory: String,
|
||||
stream_sink: StreamSink<String>,
|
||||
) {
|
||||
let stream_sink_arc = Arc::from(stream_sink);
|
||||
|
||||
let mut command = tokio::process::Command::new(&executable);
|
||||
command
|
||||
.args(arguments)
|
||||
.current_dir(working_directory)
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.kill_on_drop(true);
|
||||
|
||||
command.creation_flags(0x08000000);
|
||||
|
||||
let job = win32job::Job::create().unwrap();
|
||||
let mut info = job.query_extended_limit_info().unwrap();
|
||||
info.limit_kill_on_job_close();
|
||||
job.set_extended_limit_info(&mut info).unwrap();
|
||||
|
||||
let job_arc = Arc::from(job);
|
||||
|
||||
if let Ok(mut child) = command.spawn() {
|
||||
{
|
||||
let raw_handle = child.raw_handle();
|
||||
if raw_handle.is_some() {
|
||||
job_arc.assign_process(raw_handle.unwrap() as isize).unwrap();
|
||||
}
|
||||
}
|
||||
let stdout = child.stdout.take().expect("Failed to open stdout");
|
||||
let stderr = child.stderr.take().expect("Failed to open stderr");
|
||||
// let stdin = child.stdin.take().expect("Failed to open stderr");
|
||||
|
||||
let output_task = tokio::spawn(process_output(stdout, stream_sink_arc.clone()));
|
||||
let error_task = tokio::spawn(process_error(stderr, stream_sink_arc.clone()));
|
||||
// let input_task = tokio::spawn(process_input(stdin));
|
||||
|
||||
tokio::select! {
|
||||
_ = output_task => (),
|
||||
_ = error_task => (),
|
||||
// _ = input_task => (),
|
||||
}
|
||||
|
||||
let exit_status = child.wait().await.expect("Failed to wait for child process");
|
||||
if !exit_status.success() {
|
||||
eprintln!("Child process exited with an error: {:?}", exit_status);
|
||||
stream_sink_arc.add("exit:".to_string()).unwrap();
|
||||
}
|
||||
} else {
|
||||
eprintln!("Failed to start {}", executable);
|
||||
stream_sink_arc.add("error:Failed to start".to_string()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
async fn process_output<R>(stdout: R, stream_sink: Arc<StreamSink<String>>)
|
||||
where
|
||||
R: tokio::io::AsyncRead + Unpin,
|
||||
{
|
||||
let reader = BufReader::new(stdout);
|
||||
let mut lines = reader.lines();
|
||||
|
||||
while let Some(line) = lines.next_line().await.unwrap() {
|
||||
if line.trim().is_empty() {
|
||||
continue;
|
||||
}
|
||||
println!("{}", line.trim());
|
||||
stream_sink.add("output:".to_string() + &*line.trim().to_string()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
async fn process_error<R>(stderr: R, stream_sink: Arc<StreamSink<String>>)
|
||||
where
|
||||
R: tokio::io::AsyncRead + Unpin,
|
||||
{
|
||||
let reader = BufReader::new(stderr);
|
||||
let mut lines = reader.lines();
|
||||
while let Some(line) = lines.next_line().await.unwrap() {
|
||||
println!("{}", line.trim());
|
||||
stream_sink.add("error:".to_string() + &*line.trim().to_string()).unwrap();
|
||||
}
|
||||
}
|
152
rust/src/api/rs_process.rs
Normal file
152
rust/src/api/rs_process.rs
Normal file
@ -0,0 +1,152 @@
|
||||
use flutter_rust_bridge::for_generated::futures::lock::Mutex;
|
||||
use std::sync::Arc;
|
||||
|
||||
use flutter_rust_bridge::frb;
|
||||
use tokio::io::BufReader;
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt};
|
||||
use tokio::process::ChildStdin;
|
||||
|
||||
use crate::frb_generated::StreamSink;
|
||||
|
||||
#[frb(opaque)]
|
||||
pub struct RsProcess {
|
||||
child_stdin: Option<Arc<Mutex<ChildStdin>>>,
|
||||
pid: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum RsProcessStreamDataType {
|
||||
Output,
|
||||
Error,
|
||||
Exit,
|
||||
}
|
||||
|
||||
pub struct RsProcessStreamData {
|
||||
pub data_type: RsProcessStreamDataType,
|
||||
pub data: String,
|
||||
}
|
||||
|
||||
impl RsProcess {
|
||||
#[frb(sync)]
|
||||
pub fn new() -> Self {
|
||||
RsProcess {
|
||||
child_stdin: None,
|
||||
pid: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn start(
|
||||
&mut self,
|
||||
executable: String,
|
||||
arguments: Vec<String>,
|
||||
working_directory: String,
|
||||
stream_sink: StreamSink<RsProcessStreamData>,
|
||||
) {
|
||||
let stream_sink_arc = Arc::from(stream_sink);
|
||||
|
||||
let mut command = tokio::process::Command::new(executable);
|
||||
command
|
||||
.args(arguments)
|
||||
.current_dir(working_directory)
|
||||
.stdin(std::process::Stdio::piped())
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.kill_on_drop(true);
|
||||
|
||||
command.creation_flags(0x08000000);
|
||||
|
||||
let job = win32job::Job::create().unwrap();
|
||||
let mut info = job.query_extended_limit_info().unwrap();
|
||||
info.limit_kill_on_job_close();
|
||||
job.set_extended_limit_info(&mut info).unwrap();
|
||||
|
||||
let job_arc = Arc::from(job);
|
||||
|
||||
if let Ok(mut child) = command.spawn() {
|
||||
{
|
||||
let raw_handle = child.raw_handle();
|
||||
if raw_handle.is_some() {
|
||||
job_arc
|
||||
.assign_process(raw_handle.unwrap() as isize)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
let stdout = child.stdout.take().expect("Failed to open stdout");
|
||||
let stderr = child.stderr.take().expect("Failed to open stderr");
|
||||
|
||||
let stdin = child.stdin.take().expect("Failed to open stdin");
|
||||
self.child_stdin = Some(Arc::from(Mutex::new(stdin)));
|
||||
|
||||
let output_task = tokio::spawn(_process_output(
|
||||
stdout,
|
||||
stream_sink_arc.clone(),
|
||||
RsProcessStreamDataType::Output,
|
||||
));
|
||||
let error_task = tokio::spawn(_process_output(
|
||||
stderr,
|
||||
stream_sink_arc.clone(),
|
||||
RsProcessStreamDataType::Error,
|
||||
));
|
||||
|
||||
self.pid = child.id();
|
||||
|
||||
tokio::select! {
|
||||
_ = output_task => (),
|
||||
_ = error_task => (),
|
||||
}
|
||||
|
||||
let exit_status = child
|
||||
.wait()
|
||||
.await
|
||||
.expect("Failed to wait for child process");
|
||||
|
||||
if !exit_status.success() {
|
||||
eprintln!("Child process exited with an error: {:?}", exit_status);
|
||||
let message = RsProcessStreamData {
|
||||
data_type: RsProcessStreamDataType::Exit,
|
||||
data: "exit".to_string(),
|
||||
};
|
||||
stream_sink_arc.add(message).unwrap();
|
||||
}
|
||||
} else {
|
||||
eprintln!("Failed to start");
|
||||
let message = RsProcessStreamData {
|
||||
data_type: RsProcessStreamDataType::Error,
|
||||
data: "Failed to start".to_string(),
|
||||
};
|
||||
stream_sink_arc.add(message).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn write(&mut self, data: String) {
|
||||
if let Some(stdin) = &self.child_stdin {
|
||||
let mut stdin_lock = stdin.lock().await;
|
||||
stdin_lock.write_all(data.as_bytes()).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[frb(sync)]
|
||||
pub fn get_pid(&self) -> Option<u32> {
|
||||
self.pid
|
||||
}
|
||||
}
|
||||
|
||||
async fn _process_output<R>(
|
||||
stdout: R,
|
||||
stream_sink: Arc<StreamSink<RsProcessStreamData>>,
|
||||
data_type: RsProcessStreamDataType,
|
||||
) where
|
||||
R: tokio::io::AsyncRead + Unpin,
|
||||
{
|
||||
let reader = BufReader::new(stdout);
|
||||
let mut lines = reader.lines();
|
||||
|
||||
while let Some(line) = lines.next_line().await.unwrap() {
|
||||
let message = RsProcessStreamData {
|
||||
data_type,
|
||||
data: line.trim().parse().unwrap(),
|
||||
};
|
||||
stream_sink.add(message).unwrap();
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
// Section: imports
|
||||
|
||||
use super::*;
|
||||
use crate::api::rs_process::*;
|
||||
use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
|
||||
use flutter_rust_bridge::for_generated::transform_result_dco;
|
||||
use flutter_rust_bridge::{Handler, IntoIntoDart};
|
||||
@ -22,6 +23,12 @@ impl CstDecode<flutter_rust_bridge::for_generated::anyhow::Error>
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
impl CstDecode<RsProcess> for usize {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> RsProcess {
|
||||
CstDecode::<RustOpaqueNom<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>>>::cst_decode(self).rust_auto_opaque_decode_owned()
|
||||
}
|
||||
}
|
||||
impl CstDecode<std::collections::HashMap<String, String>>
|
||||
for *mut wire_cst_list_record_string_string
|
||||
{
|
||||
@ -31,11 +38,31 @@ impl CstDecode<std::collections::HashMap<String, String>>
|
||||
vec.into_iter().collect()
|
||||
}
|
||||
}
|
||||
impl CstDecode<StreamSink<String, flutter_rust_bridge::for_generated::DcoCodec>>
|
||||
for *mut wire_cst_list_prim_u_8_strict
|
||||
impl CstDecode<RustOpaqueNom<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>>>
|
||||
for usize
|
||||
{
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> StreamSink<String, flutter_rust_bridge::for_generated::DcoCodec> {
|
||||
fn cst_decode(
|
||||
self,
|
||||
) -> RustOpaqueNom<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>> {
|
||||
unsafe { decode_rust_opaque_nom(self as _) }
|
||||
}
|
||||
}
|
||||
impl
|
||||
CstDecode<
|
||||
StreamSink<
|
||||
crate::api::rs_process::RsProcessStreamData,
|
||||
flutter_rust_bridge::for_generated::DcoCodec,
|
||||
>,
|
||||
> for *mut wire_cst_list_prim_u_8_strict
|
||||
{
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(
|
||||
self,
|
||||
) -> StreamSink<
|
||||
crate::api::rs_process::RsProcessStreamData,
|
||||
flutter_rust_bridge::for_generated::DcoCodec,
|
||||
> {
|
||||
let raw: String = self.cst_decode();
|
||||
StreamSink::deserialize(raw)
|
||||
}
|
||||
@ -47,6 +74,12 @@ impl CstDecode<String> for *mut wire_cst_list_prim_u_8_strict {
|
||||
String::from_utf8(vec).unwrap()
|
||||
}
|
||||
}
|
||||
impl CstDecode<u32> for *mut u32 {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> u32 {
|
||||
unsafe { *flutter_rust_bridge::for_generated::box_from_leak_ptr(self) }
|
||||
}
|
||||
}
|
||||
impl CstDecode<u64> for *mut u64 {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> u64 {
|
||||
@ -88,6 +121,15 @@ impl CstDecode<(String, String)> for wire_cst_record_string_string {
|
||||
(self.field0.cst_decode(), self.field1.cst_decode())
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::api::rs_process::RsProcessStreamData> for wire_cst_rs_process_stream_data {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::api::rs_process::RsProcessStreamData {
|
||||
crate::api::rs_process::RsProcessStreamData {
|
||||
data_type: self.data_type.cst_decode(),
|
||||
data: self.data.cst_decode(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::http_package::RustHttpResponse> for wire_cst_rust_http_response {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::http_package::RustHttpResponse {
|
||||
@ -115,6 +157,19 @@ impl Default for wire_cst_record_string_string {
|
||||
Self::new_with_null_ptr()
|
||||
}
|
||||
}
|
||||
impl NewWithNullPtr for wire_cst_rs_process_stream_data {
|
||||
fn new_with_null_ptr() -> Self {
|
||||
Self {
|
||||
data_type: Default::default(),
|
||||
data: core::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Default for wire_cst_rs_process_stream_data {
|
||||
fn default() -> Self {
|
||||
Self::new_with_null_ptr()
|
||||
}
|
||||
}
|
||||
impl NewWithNullPtr for wire_cst_rust_http_response {
|
||||
fn new_with_null_ptr() -> Self {
|
||||
Self {
|
||||
@ -171,14 +226,67 @@ pub extern "C" fn frbgen_starcitizen_doctor_wire_set_default_header(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_starcitizen_doctor_wire_start_process(
|
||||
pub extern "C" fn frbgen_starcitizen_doctor_wire_RsProcess_get_pid(
|
||||
that: usize,
|
||||
) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco {
|
||||
wire_RsProcess_get_pid_impl(that)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_starcitizen_doctor_wire_RsProcess_new(
|
||||
) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco {
|
||||
wire_RsProcess_new_impl()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_starcitizen_doctor_wire_RsProcess_start(
|
||||
port_: i64,
|
||||
that: usize,
|
||||
executable: *mut wire_cst_list_prim_u_8_strict,
|
||||
arguments: *mut wire_cst_list_String,
|
||||
working_directory: *mut wire_cst_list_prim_u_8_strict,
|
||||
stream_sink: *mut wire_cst_list_prim_u_8_strict,
|
||||
) {
|
||||
wire_start_process_impl(port_, executable, arguments, working_directory, stream_sink)
|
||||
wire_RsProcess_start_impl(
|
||||
port_,
|
||||
that,
|
||||
executable,
|
||||
arguments,
|
||||
working_directory,
|
||||
stream_sink,
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_starcitizen_doctor_wire_RsProcess_write(
|
||||
port_: i64,
|
||||
that: usize,
|
||||
data: *mut wire_cst_list_prim_u_8_strict,
|
||||
) {
|
||||
wire_RsProcess_write_impl(port_, that, data)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_starcitizen_doctor_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockRsProcess(
|
||||
ptr: *const std::ffi::c_void,
|
||||
) {
|
||||
unsafe {
|
||||
StdArc::<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>>::increment_strong_count(ptr as _);
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_starcitizen_doctor_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedrust_asyncRwLockRsProcess(
|
||||
ptr: *const std::ffi::c_void,
|
||||
) {
|
||||
unsafe {
|
||||
StdArc::<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>>::decrement_strong_count(ptr as _);
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn frbgen_starcitizen_doctor_cst_new_box_autoadd_u_32(value: u32) -> *mut u32 {
|
||||
flutter_rust_bridge::for_generated::new_leak_box_ptr(value)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@ -251,6 +359,12 @@ pub struct wire_cst_record_string_string {
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct wire_cst_rs_process_stream_data {
|
||||
data_type: i32,
|
||||
data: *mut wire_cst_list_prim_u_8_strict,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct wire_cst_rust_http_response {
|
||||
status_code: u16,
|
||||
headers: *mut wire_cst_list_record_string_string,
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
// Section: imports
|
||||
|
||||
use crate::api::rs_process::*;
|
||||
use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt};
|
||||
use flutter_rust_bridge::for_generated::transform_result_dco;
|
||||
use flutter_rust_bridge::{Handler, IntoIntoDart};
|
||||
@ -31,7 +32,7 @@ flutter_rust_bridge::frb_generated_boilerplate!(
|
||||
default_rust_auto_opaque = RustAutoOpaqueNom,
|
||||
);
|
||||
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.0.0-dev.32";
|
||||
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 593879172;
|
||||
pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 333909092;
|
||||
|
||||
// Section: executor
|
||||
|
||||
@ -139,20 +140,63 @@ fn wire_set_default_header_impl(
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire_start_process_impl(
|
||||
fn wire_RsProcess_get_pid_impl(
|
||||
that: impl CstDecode<
|
||||
RustOpaqueNom<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>>,
|
||||
>,
|
||||
) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_sync::<flutter_rust_bridge::for_generated::DcoCodec, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "RsProcess_get_pid",
|
||||
port: None,
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Sync,
|
||||
},
|
||||
move || {
|
||||
let api_that = that.cst_decode();
|
||||
transform_result_dco((move || {
|
||||
let api_that = api_that.rust_auto_opaque_decode_ref();
|
||||
Result::<_, ()>::Ok(crate::api::rs_process::RsProcess::get_pid(&api_that))
|
||||
})())
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire_RsProcess_new_impl() -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_sync::<flutter_rust_bridge::for_generated::DcoCodec, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "RsProcess_new",
|
||||
port: None,
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Sync,
|
||||
},
|
||||
move || {
|
||||
transform_result_dco((move || {
|
||||
Result::<_, ()>::Ok(crate::api::rs_process::RsProcess::new())
|
||||
})())
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire_RsProcess_start_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
that: impl CstDecode<
|
||||
RustOpaqueNom<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>>,
|
||||
>,
|
||||
executable: impl CstDecode<String>,
|
||||
arguments: impl CstDecode<Vec<String>>,
|
||||
working_directory: impl CstDecode<String>,
|
||||
stream_sink: impl CstDecode<StreamSink<String, flutter_rust_bridge::for_generated::DcoCodec>>,
|
||||
stream_sink: impl CstDecode<
|
||||
StreamSink<
|
||||
crate::api::rs_process::RsProcessStreamData,
|
||||
flutter_rust_bridge::for_generated::DcoCodec,
|
||||
>,
|
||||
>,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::DcoCodec, _, _, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "start_process",
|
||||
debug_name: "RsProcess_start",
|
||||
port: Some(port_),
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
|
||||
},
|
||||
move || {
|
||||
let api_that = that.cst_decode();
|
||||
let api_executable = executable.cst_decode();
|
||||
let api_arguments = arguments.cst_decode();
|
||||
let api_working_directory = working_directory.cst_decode();
|
||||
@ -160,8 +204,10 @@ fn wire_start_process_impl(
|
||||
move |context| async move {
|
||||
transform_result_dco(
|
||||
(move || async move {
|
||||
let mut api_that = api_that.rust_auto_opaque_decode_ref_mut();
|
||||
Result::<_, ()>::Ok(
|
||||
crate::api::process_api::start_process(
|
||||
crate::api::rs_process::RsProcess::start(
|
||||
&mut api_that,
|
||||
api_executable,
|
||||
api_arguments,
|
||||
api_working_directory,
|
||||
@ -176,6 +222,36 @@ fn wire_start_process_impl(
|
||||
},
|
||||
)
|
||||
}
|
||||
fn wire_RsProcess_write_impl(
|
||||
port_: flutter_rust_bridge::for_generated::MessagePort,
|
||||
that: impl CstDecode<
|
||||
RustOpaqueNom<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>>,
|
||||
>,
|
||||
data: impl CstDecode<String>,
|
||||
) {
|
||||
FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::<flutter_rust_bridge::for_generated::DcoCodec, _, _, _>(
|
||||
flutter_rust_bridge::for_generated::TaskInfo {
|
||||
debug_name: "RsProcess_write",
|
||||
port: Some(port_),
|
||||
mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal,
|
||||
},
|
||||
move || {
|
||||
let api_that = that.cst_decode();
|
||||
let api_data = data.cst_decode();
|
||||
move |context| async move {
|
||||
transform_result_dco(
|
||||
(move || async move {
|
||||
let mut api_that = api_that.rust_auto_opaque_decode_ref_mut();
|
||||
Result::<_, ()>::Ok(
|
||||
crate::api::rs_process::RsProcess::write(&mut api_that, api_data).await,
|
||||
)
|
||||
})()
|
||||
.await,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
// Section: dart2rust
|
||||
|
||||
@ -216,12 +292,29 @@ impl CstDecode<crate::api::http_api::MyMethod> for i32 {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl CstDecode<crate::api::rs_process::RsProcessStreamDataType> for i32 {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> crate::api::rs_process::RsProcessStreamDataType {
|
||||
match self {
|
||||
0 => crate::api::rs_process::RsProcessStreamDataType::Output,
|
||||
1 => crate::api::rs_process::RsProcessStreamDataType::Error,
|
||||
2 => crate::api::rs_process::RsProcessStreamDataType::Exit,
|
||||
_ => unreachable!("Invalid variant for RsProcessStreamDataType: {}", self),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl CstDecode<u16> for u16 {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> u16 {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl CstDecode<u32> for u32 {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> u32 {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl CstDecode<u64> for u64 {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> u64 {
|
||||
@ -234,6 +327,12 @@ impl CstDecode<u8> for u8 {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl CstDecode<usize> for usize {
|
||||
// Codec=Cst (C-struct based), see doc to use other codecs
|
||||
fn cst_decode(self) -> usize {
|
||||
self
|
||||
}
|
||||
}
|
||||
impl SseDecode for flutter_rust_bridge::for_generated::anyhow::Error {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@ -241,6 +340,16 @@ impl SseDecode for flutter_rust_bridge::for_generated::anyhow::Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for RsProcess {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut inner = <RustOpaqueNom<
|
||||
flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>,
|
||||
>>::sse_decode(deserializer);
|
||||
return inner.rust_auto_opaque_decode_owned();
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for std::collections::HashMap<String, String> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@ -249,7 +358,22 @@ impl SseDecode for std::collections::HashMap<String, String> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for StreamSink<String, flutter_rust_bridge::for_generated::DcoCodec> {
|
||||
impl SseDecode
|
||||
for RustOpaqueNom<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>>
|
||||
{
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut inner = <usize>::sse_decode(deserializer);
|
||||
return unsafe { decode_rust_opaque_nom(inner) };
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode
|
||||
for StreamSink<
|
||||
crate::api::rs_process::RsProcessStreamData,
|
||||
flutter_rust_bridge::for_generated::DcoCodec,
|
||||
>
|
||||
{
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut inner = <String>::sse_decode(deserializer);
|
||||
@ -367,6 +491,17 @@ impl SseDecode for Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for Option<u32> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
if (<bool>::sse_decode(deserializer)) {
|
||||
return Some(<u32>::sse_decode(deserializer));
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for Option<u64> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@ -398,6 +533,32 @@ impl SseDecode for (String, String) {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::api::rs_process::RsProcessStreamData {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut var_dataType =
|
||||
<crate::api::rs_process::RsProcessStreamDataType>::sse_decode(deserializer);
|
||||
let mut var_data = <String>::sse_decode(deserializer);
|
||||
return crate::api::rs_process::RsProcessStreamData {
|
||||
data_type: var_dataType,
|
||||
data: var_data,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::api::rs_process::RsProcessStreamDataType {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
let mut inner = <i32>::sse_decode(deserializer);
|
||||
return match inner {
|
||||
0 => crate::api::rs_process::RsProcessStreamDataType::Output,
|
||||
1 => crate::api::rs_process::RsProcessStreamDataType::Error,
|
||||
2 => crate::api::rs_process::RsProcessStreamDataType::Exit,
|
||||
_ => unreachable!("Invalid variant for RsProcessStreamDataType: {}", inner),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for crate::http_package::RustHttpResponse {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@ -427,6 +588,13 @@ impl SseDecode for u16 {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for u32 {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
deserializer.cursor.read_u32::<NativeEndian>().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for u64 {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@ -446,6 +614,13 @@ impl SseDecode for () {
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {}
|
||||
}
|
||||
|
||||
impl SseDecode for usize {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
deserializer.cursor.read_u64::<NativeEndian>().unwrap() as _
|
||||
}
|
||||
}
|
||||
|
||||
impl SseDecode for bool {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
|
||||
@ -480,6 +655,21 @@ fn pde_ffi_dispatcher_sync_impl(
|
||||
|
||||
// Section: rust2dart
|
||||
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for FrbWrapper<RsProcess> {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
flutter_rust_bridge::for_generated::rust_auto_opaque_encode::<_, StdArc<_>>(self.0)
|
||||
.into_dart()
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive for FrbWrapper<RsProcess> {}
|
||||
|
||||
impl flutter_rust_bridge::IntoIntoDart<FrbWrapper<RsProcess>> for RsProcess {
|
||||
fn into_into_dart(self) -> FrbWrapper<RsProcess> {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::http_package::MyHttpVersion {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
@ -532,6 +722,48 @@ impl flutter_rust_bridge::IntoIntoDart<crate::api::http_api::MyMethod>
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::api::rs_process::RsProcessStreamData {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
self.data_type.into_into_dart().into_dart(),
|
||||
self.data.into_into_dart().into_dart(),
|
||||
]
|
||||
.into_dart()
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
|
||||
for crate::api::rs_process::RsProcessStreamData
|
||||
{
|
||||
}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::api::rs_process::RsProcessStreamData>
|
||||
for crate::api::rs_process::RsProcessStreamData
|
||||
{
|
||||
fn into_into_dart(self) -> crate::api::rs_process::RsProcessStreamData {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::api::rs_process::RsProcessStreamDataType {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
match self {
|
||||
Self::Output => 0.into_dart(),
|
||||
Self::Error => 1.into_dart(),
|
||||
Self::Exit => 2.into_dart(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive
|
||||
for crate::api::rs_process::RsProcessStreamDataType
|
||||
{
|
||||
}
|
||||
impl flutter_rust_bridge::IntoIntoDart<crate::api::rs_process::RsProcessStreamDataType>
|
||||
for crate::api::rs_process::RsProcessStreamDataType
|
||||
{
|
||||
fn into_into_dart(self) -> crate::api::rs_process::RsProcessStreamDataType {
|
||||
self
|
||||
}
|
||||
}
|
||||
// Codec=Dco (DartCObject based), see doc to use other codecs
|
||||
impl flutter_rust_bridge::IntoDart for crate::http_package::RustHttpResponse {
|
||||
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
|
||||
[
|
||||
@ -565,6 +797,13 @@ impl SseEncode for flutter_rust_bridge::for_generated::anyhow::Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for RsProcess {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<RustOpaqueNom<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>>>::sse_encode(flutter_rust_bridge::for_generated::rust_auto_opaque_encode::<_, StdArc<_>>(self), serializer);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for std::collections::HashMap<String, String> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@ -572,7 +811,23 @@ impl SseEncode for std::collections::HashMap<String, String> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for StreamSink<String, flutter_rust_bridge::for_generated::DcoCodec> {
|
||||
impl SseEncode
|
||||
for RustOpaqueNom<flutter_rust_bridge::for_generated::rust_async::RwLock<RsProcess>>
|
||||
{
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
let (ptr, size) = self.sse_encode_raw();
|
||||
<usize>::sse_encode(ptr, serializer);
|
||||
<i32>::sse_encode(size, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode
|
||||
for StreamSink<
|
||||
crate::api::rs_process::RsProcessStreamData,
|
||||
flutter_rust_bridge::for_generated::DcoCodec,
|
||||
>
|
||||
{
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
unimplemented!("")
|
||||
@ -686,6 +941,16 @@ impl SseEncode for Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for Option<u32> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<bool>::sse_encode(self.is_some(), serializer);
|
||||
if let Some(value) = self {
|
||||
<u32>::sse_encode(value, serializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for Option<u64> {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@ -714,6 +979,31 @@ impl SseEncode for (String, String) {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::api::rs_process::RsProcessStreamData {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<crate::api::rs_process::RsProcessStreamDataType>::sse_encode(self.data_type, serializer);
|
||||
<String>::sse_encode(self.data, serializer);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::api::rs_process::RsProcessStreamDataType {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
<i32>::sse_encode(
|
||||
match self {
|
||||
crate::api::rs_process::RsProcessStreamDataType::Output => 0,
|
||||
crate::api::rs_process::RsProcessStreamDataType::Error => 1,
|
||||
crate::api::rs_process::RsProcessStreamDataType::Exit => 2,
|
||||
_ => {
|
||||
unimplemented!("");
|
||||
}
|
||||
},
|
||||
serializer,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for crate::http_package::RustHttpResponse {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@ -734,6 +1024,13 @@ impl SseEncode for u16 {
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for u32 {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
serializer.cursor.write_u32::<NativeEndian>(self).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for u64 {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
@ -753,6 +1050,16 @@ impl SseEncode for () {
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {}
|
||||
}
|
||||
|
||||
impl SseEncode for usize {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
serializer
|
||||
.cursor
|
||||
.write_u64::<NativeEndian>(self as _)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl SseEncode for bool {
|
||||
// Codec=Sse (Serialization based), see doc to use other codecs
|
||||
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
|
||||
|
@ -1,15 +1,15 @@
|
||||
use hickory_resolver::config::{NameServerConfigGroup, ResolverConfig, ResolverOpts};
|
||||
use hickory_resolver::{lookup_ip::LookupIpIntoIter, TokioAsyncResolver};
|
||||
use lazy_static::lazy_static;
|
||||
use once_cell::sync::OnceCell;
|
||||
use reqwest::dns::{Addrs, Name, Resolve, Resolving};
|
||||
use std::collections::HashMap;
|
||||
use std::io;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref MY_HOSTS_MAP: RwLock<HashMap<String, IpAddr>> = RwLock::from(HashMap::new());
|
||||
pub static ref MY_HOSTS_MAP: RwLock<HashMap<String, IpAddr>> = RwLock::from(HashMap::new());
|
||||
}
|
||||
|
||||
/// Wrapper around an `AsyncResolver`, which implements the `Resolve` trait.
|
||||
@ -60,10 +60,7 @@ impl MyHickoryDnsResolver {
|
||||
pub(crate) async fn lookup_ips(&self, name: String) -> anyhow::Result<Vec<String>> {
|
||||
let resolver = self.state.get_or_try_init(new_resolver)?;
|
||||
let ips = resolver.ipv4_lookup(name).await?;
|
||||
let t = ips
|
||||
.iter()
|
||||
.map(|ip| ip.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
let t = ips.iter().map(|ip| ip.to_string()).collect::<Vec<_>>();
|
||||
Ok(t)
|
||||
}
|
||||
}
|
||||
@ -88,7 +85,9 @@ fn new_resolver() -> io::Result<TokioAsyncResolver> {
|
||||
IpAddr::V4(Ipv4Addr::new(166, 111, 8, 28)),
|
||||
IpAddr::V4(Ipv4Addr::new(101, 226, 4, 6)),
|
||||
IpAddr::V4(Ipv4Addr::new(114, 114, 114, 114)),
|
||||
], 53, false,
|
||||
],
|
||||
53,
|
||||
false,
|
||||
);
|
||||
let cfg = ResolverConfig::from_parts(None, vec![], group);
|
||||
let mut opts = ResolverOpts::default();
|
||||
|
@ -1,9 +1,9 @@
|
||||
pub mod dns;
|
||||
|
||||
use scopeguard::defer;
|
||||
use lazy_static::lazy_static;
|
||||
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
|
||||
use reqwest::{Method, RequestBuilder};
|
||||
use scopeguard::defer;
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Arc, RwLock};
|
||||
@ -45,7 +45,8 @@ fn _hyper_version_to_my_version(v: reqwest::Version) -> MyHttpVersion {
|
||||
|
||||
lazy_static! {
|
||||
static ref DEFAULT_HEADER: RwLock<HeaderMap> = RwLock::from(HeaderMap::new());
|
||||
static ref DNS_CLIENT: Arc<dns::MyHickoryDnsResolver> = Arc::from(dns::MyHickoryDnsResolver::default());
|
||||
static ref DNS_CLIENT: Arc<dns::MyHickoryDnsResolver> =
|
||||
Arc::from(dns::MyHickoryDnsResolver::default());
|
||||
static ref HTTP_CLIENT: reqwest::Client = new_http_client(true);
|
||||
}
|
||||
|
||||
@ -88,7 +89,11 @@ pub async fn fetch(
|
||||
if address_clone.is_some() {
|
||||
let addr = std::net::IpAddr::from_str(with_ip_address.unwrap().as_str()).unwrap();
|
||||
let mut hosts = dns::MY_HOSTS_MAP.write().unwrap();
|
||||
let url_host = Url::from_str(url.as_str()).unwrap().host().unwrap().to_string();
|
||||
let url_host = Url::from_str(url.as_str())
|
||||
.unwrap()
|
||||
.host()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
hosts.insert(url_host, addr);
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
mod frb_generated;
|
||||
pub mod api;
|
||||
mod frb_generated;
|
||||
pub mod http_package;
|
||||
|
Reference in New Issue
Block a user