1
0
Fork 0
mirror of https://gitee.com/fantix/kloop.git synced 2024-12-22 00:46:28 +00:00

Clean up Rust project

This commit is contained in:
Fantix King 2022-06-11 17:53:30 -04:00
parent eca322da58
commit a935db4858
No known key found for this signature in database
GPG key ID: 95304B04071CCDB4
5 changed files with 58 additions and 70 deletions

50
resolver/Cargo.lock generated
View file

@ -39,9 +39,9 @@ checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57"
[[package]]
name = "enum-as-inner"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21cdad81446a7f7dc43f6a77409efeb9733d2fa65553efef6018ef257c959b73"
checksum = "432f044e9077ad6666f3446df0489a71ac3ed0336ea54edf6b85e00cd7562283"
dependencies = [
"heck",
"proc-macro2",
@ -237,6 +237,12 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "once_cell"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
[[package]]
name = "parking_lot"
version = "0.12.0"
@ -446,10 +452,42 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tracing"
version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160"
dependencies = [
"cfg-if",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7709595b8878a4965ce5e87ebf880a7d39c9afc6837721b21a5a816a8117d921"
dependencies = [
"once_cell",
]
[[package]]
name = "trust-dns-proto"
version = "0.21.2"
source = "git+https://github.com/fantix/trust-dns?branch=0_21_2_patch#843c22f1d267660d816480d7168c17ee5467cda8"
source = "git+https://github.com/bluejekyll/trust-dns#170e3f7d7dfbc2b6c48318cb5c996a8cc6db77a1"
dependencies = [
"async-trait",
"cfg-if",
@ -461,29 +499,29 @@ dependencies = [
"idna",
"ipnet",
"lazy_static",
"log",
"rand",
"smallvec",
"thiserror",
"tinyvec",
"tracing",
"url",
]
[[package]]
name = "trust-dns-resolver"
version = "0.21.2"
source = "git+https://github.com/fantix/trust-dns?branch=0_21_2_patch#843c22f1d267660d816480d7168c17ee5467cda8"
source = "git+https://github.com/bluejekyll/trust-dns#170e3f7d7dfbc2b6c48318cb5c996a8cc6db77a1"
dependencies = [
"cfg-if",
"futures-util",
"ipconfig",
"lazy_static",
"log",
"lru-cache",
"parking_lot",
"resolv-conf",
"smallvec",
"thiserror",
"tracing",
"trust-dns-proto",
]

View file

@ -11,8 +11,8 @@ crate-type = ["staticlib"]
libc = "0.2.124"
log = "0.4.16"
resolv-conf = { version = "0.7.0", features = ["system"] }
trust-dns-proto = { git = "https://github.com/fantix/trust-dns", branch = "0_21_2_patch", default-features = false }
trust-dns-resolver = { git = "https://github.com/fantix/trust-dns", branch = "0_21_2_patch", default-features = false, features = ["system-config"]}
trust-dns-proto = { git = "https://github.com/bluejekyll/trust-dns", default-features = false }
trust-dns-resolver = { git = "https://github.com/bluejekyll/trust-dns", default-features = false, features = ["system-config"]}
futures-util = "0.3.21"
futures-io = "0.3.5"
futures-executor = "0.3.5"

View file

@ -1,57 +0,0 @@
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use futures_util::task::noop_waker_ref;
use libc;
pub type BoxFuture<'a, T> = Box<dyn Future<Output = T> + 'a>;
pub struct Poller<'a> {
ctx: Context<'a>,
fut: BoxFuture<'a, libc::c_int>,
}
impl<'a> Poller<'a> {
pub fn new(fut: impl Future<Output = libc::c_int> + 'a) -> Self {
let waker = noop_waker_ref();
Poller {
ctx: Context::from_waker(waker),
fut: Box::new(fut),
}
}
pub fn step(&mut self) -> Option<libc::c_int> {
let fut = unsafe { Pin::new_unchecked(self.fut.as_mut()) };
match fut.poll(&mut self.ctx) {
Poll::Ready(rv) => Some(rv),
Poll::Pending => None,
}
}
}
pub struct OnceFuture {
seen: bool,
}
impl OnceFuture {
pub fn new() -> Self {
Self { seen: false }
}
}
impl Future for OnceFuture {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.seen {
println!("poll ready");
Poll::Ready(())
} else {
println!("poll pending");
self.get_mut().seen = true;
Poll::Pending
}
}
}

View file

@ -28,8 +28,6 @@ use trust_dns_resolver::{AsyncResolver, Hosts};
use crate::kloop::{resolve_done_cb, resolve_prep_addr, resolver_set, CResolve, CResolver};
use crate::runtime::{KLoopHandle, KLoopRuntime};
const DEFAULT_PORT: u16 = 53;
type KLoopConnection = GenericConnection;
type KLoopConnectionProvider = GenericConnectionProvider<KLoopRuntime>;
@ -56,7 +54,7 @@ impl KLoopResolver {
options.use_hosts_file = false;
let conn_provider = GenericConnectionProvider::new(KLoopHandle);
let mut resolver = AsyncResolver::new_with_conn(config, options, conn_provider).unwrap();
resolver.set_hosts(Some(Hosts::default().read_hosts_conf(hosts_conf)));
resolver.set_hosts(Some(Hosts::default().read_hosts_conf(hosts_conf)?));
let pool = LocalPool::new();
let spawner = pool.spawner();
Ok(Self {
@ -137,7 +135,7 @@ pub extern "C" fn resolver_init(
let resolv_conf =
unsafe { std::slice::from_raw_parts(resolv_conf_data, resolv_conf_data_size) };
let hosts_conf = unsafe { std::slice::from_raw_parts(hosts_conf_data, hosts_conf_data_size) };
let mut resolver = match KLoopResolver::new(resolv_conf, hosts_conf, c_resolver) {
let resolver = match KLoopResolver::new(resolv_conf, hosts_conf, c_resolver) {
Ok(resolver) => resolver,
Err(e) => return 0,
};

View file

@ -23,7 +23,6 @@ use std::pin::Pin;
use std::task::{Context, Poll, Waker};
use std::time::Duration;
use std::{io, mem};
use futures_util::future::Ready;
use trust_dns_proto::error::ProtoError;
use trust_dns_proto::tcp::{Connect, DnsTcpStream};
use trust_dns_proto::udp::UdpSocket;
@ -107,6 +106,16 @@ pub struct KLoopUdp {
impl UdpSocket for KLoopUdp {
type Time = KLoopTimer;
async fn connect(addr: SocketAddr) -> io::Result<Self> {
println!("TODO: KLoopUdp: connect({})", addr);
todo!()
}
async fn connect_with_bind(addr: SocketAddr, bind_addr: SocketAddr) -> io::Result<Self> {
println!("TODO: KLoopUdp: connect_with_bind({}, {})", addr, bind_addr);
todo!()
}
async fn bind(addr: SocketAddr) -> io::Result<Self> {
let (addr_ptr, addr_len) = socket_addr_as_ptr(addr);
let fd = unsafe { kloop::udp_bind(addr_ptr, addr_len) };