style(client): cargo fmt
This commit is contained in:
1 parent
759c627ca4
commit
2a75724dde
7 files changed
+39
-56
No files matched your search
@@ -4,12 +4,12 @@
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(feature = "iroh")]
|
||||
use iroh;
|
||||
#[cfg(feature = "quinn")]
|
||||
use quinn;
|
||||
#[cfg(feature = "tcp")]
|
||||
use tokio_rustls;
|
||||
#[cfg(feature = "iroh")]
|
||||
use iroh;
|
||||
|
||||
#[cfg(feature = "socks5")]
|
||||
use crate::socks5::Socks5ProxyConfig;
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
use alknet_core::credentials::ConnectionCredentials;
|
||||
use alknet_core::types::Connection;
|
||||
|
||||
use crate::error::ClientDialError;
|
||||
use crate::client::AlknetClient;
|
||||
use crate::error::ClientDialError;
|
||||
|
||||
impl AlknetClient {
|
||||
/// Iroh dial. Dials on `alpn` via the iroh endpoint. The iroh path
|
||||
@@ -28,14 +28,14 @@ impl AlknetClient {
|
||||
alpn: &[u8],
|
||||
creds: &ConnectionCredentials,
|
||||
) -> Result<Connection, ClientDialError> {
|
||||
let endpoint = self.iroh.as_ref().ok_or(ClientDialError::NoTransport {
|
||||
transport: "iroh",
|
||||
})?;
|
||||
let endpoint = self
|
||||
.iroh
|
||||
.as_ref()
|
||||
.ok_or(ClientDialError::NoTransport { transport: "iroh" })?;
|
||||
|
||||
let node_id = match &creds.remote_identity {
|
||||
Some(ri) => extract_iroh_endpoint_id(&ri.fingerprint).map_err(|e| {
|
||||
ClientDialError::TlsConfig(alknet_tls::TlsError::Config(e))
|
||||
})?,
|
||||
Some(ri) => extract_iroh_endpoint_id(&ri.fingerprint)
|
||||
.map_err(|e| ClientDialError::TlsConfig(alknet_tls::TlsError::Config(e)))?,
|
||||
None => {
|
||||
return Err(ClientDialError::TlsConfig(alknet_tls::TlsError::Config(
|
||||
"iroh requires a known remote (remote_identity must be Some); \
|
||||
@@ -74,8 +74,7 @@ fn extract_iroh_endpoint_id(fingerprint: &str) -> Result<iroh::EndpointId, Strin
|
||||
let arr: [u8; 32] = bytes
|
||||
.try_into()
|
||||
.map_err(|_| "invalid ed25519 fingerprint length".to_string())?;
|
||||
iroh::EndpointId::from_bytes(&arr)
|
||||
.map_err(|e| format!("invalid iroh EndpointId: {e}"))
|
||||
iroh::EndpointId::from_bytes(&arr).map_err(|e| format!("invalid iroh EndpointId: {e}"))
|
||||
} else {
|
||||
Err(format!(
|
||||
"iroh requires an ed25519: fingerprint, got: {}",
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
//! All three are unified on `&ConnectionCredentials` (ADR-091) and return a
|
||||
//! `Connection` for protocol take-overs to consume.
|
||||
|
||||
#[cfg(feature = "iroh")]
|
||||
pub mod iroh;
|
||||
#[cfg(feature = "quinn")]
|
||||
pub mod quinn;
|
||||
#[cfg(feature = "tcp")]
|
||||
pub mod tcp_tls;
|
||||
#[cfg(feature = "iroh")]
|
||||
pub mod iroh;
|
||||
@@ -13,8 +13,8 @@ use alknet_core::credentials::ConnectionCredentials;
|
||||
use alknet_core::types::Connection;
|
||||
use alknet_tls::client::TlsClientConfig;
|
||||
|
||||
use crate::error::ClientDialError;
|
||||
use crate::client::AlknetClient;
|
||||
use crate::error::ClientDialError;
|
||||
|
||||
impl AlknetClient {
|
||||
/// QUIC dial. Builds a `TlsClientConfig` from `creds`
|
||||
@@ -53,9 +53,7 @@ impl AlknetClient {
|
||||
let endpoint = self
|
||||
.quinn
|
||||
.as_ref()
|
||||
.ok_or(ClientDialError::NoTransport {
|
||||
transport: "quinn",
|
||||
})?;
|
||||
.ok_or(ClientDialError::NoTransport { transport: "quinn" })?;
|
||||
endpoint
|
||||
.connect_with(client_config, addr, server_name)
|
||||
.map_err(|e| ClientDialError::Connect(e.to_string()))?
|
||||
@@ -68,9 +66,7 @@ impl AlknetClient {
|
||||
let endpoint = self
|
||||
.quinn
|
||||
.as_ref()
|
||||
.ok_or(ClientDialError::NoTransport {
|
||||
transport: "quinn",
|
||||
})?;
|
||||
.ok_or(ClientDialError::NoTransport { transport: "quinn" })?;
|
||||
endpoint
|
||||
.connect_with(client_config, addr, server_name)
|
||||
.map_err(|e| ClientDialError::Connect(e.to_string()))?
|
||||
|
||||
@@ -13,8 +13,8 @@ use alknet_core::types::Connection;
|
||||
use alknet_tls::client::TlsClientConfig;
|
||||
use tokio::net::TcpStream;
|
||||
|
||||
use crate::error::ClientDialError;
|
||||
use crate::client::AlknetClient;
|
||||
use crate::error::ClientDialError;
|
||||
|
||||
impl AlknetClient {
|
||||
/// TCP+TLS dial. Builds a `TlsClientConfig` from `creds`,
|
||||
@@ -47,12 +47,9 @@ impl AlknetClient {
|
||||
crate::socks5::socks5_connect(&mut tcp, proxy, addr)
|
||||
.await
|
||||
.map_err(ClientDialError::Proxy)?;
|
||||
let server_name: rustls::pki_types::ServerName = host
|
||||
.to_owned()
|
||||
.try_into()
|
||||
.map_err(|e: rustls::pki_types::InvalidDnsNameError| {
|
||||
ClientDialError::Connect(e.to_string())
|
||||
})?;
|
||||
let server_name: rustls::pki_types::ServerName = host.to_owned().try_into().map_err(
|
||||
|e: rustls::pki_types::InvalidDnsNameError| ClientDialError::Connect(e.to_string()),
|
||||
)?;
|
||||
connector
|
||||
.connect(server_name, tcp)
|
||||
.await
|
||||
@@ -61,12 +58,9 @@ impl AlknetClient {
|
||||
let tcp_stream = TcpStream::connect(addr)
|
||||
.await
|
||||
.map_err(|e| ClientDialError::Connect(e.to_string()))?;
|
||||
let server_name: rustls::pki_types::ServerName = host
|
||||
.to_owned()
|
||||
.try_into()
|
||||
.map_err(|e: rustls::pki_types::InvalidDnsNameError| {
|
||||
ClientDialError::Connect(e.to_string())
|
||||
})?;
|
||||
let server_name: rustls::pki_types::ServerName = host.to_owned().try_into().map_err(
|
||||
|e: rustls::pki_types::InvalidDnsNameError| ClientDialError::Connect(e.to_string()),
|
||||
)?;
|
||||
connector
|
||||
.connect(server_name, tcp_stream)
|
||||
.await
|
||||
@@ -78,23 +72,16 @@ impl AlknetClient {
|
||||
let tcp_stream = TcpStream::connect(addr)
|
||||
.await
|
||||
.map_err(|e| ClientDialError::Connect(e.to_string()))?;
|
||||
let server_name: rustls::pki_types::ServerName = host
|
||||
.to_owned()
|
||||
.try_into()
|
||||
.map_err(|e: rustls::pki_types::InvalidDnsNameError| {
|
||||
ClientDialError::Connect(e.to_string())
|
||||
})?;
|
||||
let server_name: rustls::pki_types::ServerName = host.to_owned().try_into().map_err(
|
||||
|e: rustls::pki_types::InvalidDnsNameError| ClientDialError::Connect(e.to_string()),
|
||||
)?;
|
||||
connector
|
||||
.connect(server_name, tcp_stream)
|
||||
.await
|
||||
.map_err(|e| ClientDialError::Handshake(e.to_string()))?
|
||||
};
|
||||
|
||||
Ok(Connection::from_bidi(
|
||||
tls_stream,
|
||||
alpn.to_vec(),
|
||||
Some(addr),
|
||||
))
|
||||
Ok(Connection::from_bidi(tls_stream, alpn.to_vec(), Some(addr)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +52,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn no_transport_displays_transport_name() {
|
||||
let err = ClientDialError::NoTransport {
|
||||
transport: "quinn",
|
||||
};
|
||||
let err = ClientDialError::NoTransport { transport: "quinn" };
|
||||
assert!(err.to_string().contains("quinn"));
|
||||
}
|
||||
|
||||
|
||||
@@ -121,10 +121,7 @@ impl quinn::AsyncUdpSocket for Socks5UdpSocket {
|
||||
|
||||
let sent = self.socket.send_to(&buf, self.relay_addr)?;
|
||||
if sent < buf.len() {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::WouldBlock,
|
||||
"partial send",
|
||||
));
|
||||
return Err(io::Error::new(io::ErrorKind::WouldBlock, "partial send"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -174,9 +171,7 @@ impl quinn::AsyncUdpSocket for Socks5UdpSocket {
|
||||
};
|
||||
Poll::Ready(Ok(1))
|
||||
}
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
Poll::Pending
|
||||
}
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => Poll::Pending,
|
||||
Err(e) => Poll::Ready(Err(e)),
|
||||
}
|
||||
}
|
||||
@@ -207,7 +202,13 @@ impl std::fmt::Debug for UdpPollerImpl {
|
||||
impl quinn::UdpPoller for UdpPollerImpl {
|
||||
fn poll_writable(self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
|
||||
if let Some(ref socket) = self.socket {
|
||||
match socket.send_to(&[], socket.local_addr().ok().unwrap_or_else(|| "0.0.0.0:0".parse().unwrap())) {
|
||||
match socket.send_to(
|
||||
&[],
|
||||
socket
|
||||
.local_addr()
|
||||
.ok()
|
||||
.unwrap_or_else(|| "0.0.0.0:0".parse().unwrap()),
|
||||
) {
|
||||
Ok(_) => Poll::Ready(Ok(())),
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
*self.waker.lock().unwrap() = Some(cx.waker().clone());
|
||||
@@ -307,7 +308,9 @@ async fn socks5_udp_associate(stream: &mut TcpStream) -> Result<SocketAddr, Clie
|
||||
.map_err(|e| ClientDialError::Proxy(e.to_string()))?;
|
||||
|
||||
if resp[0] != 0x05 {
|
||||
return Err(ClientDialError::Proxy("invalid SOCKS5 version in reply".into()));
|
||||
return Err(ClientDialError::Proxy(
|
||||
"invalid SOCKS5 version in reply".into(),
|
||||
));
|
||||
}
|
||||
if resp[1] != 0x00 {
|
||||
return Err(ClientDialError::Proxy(format!(
|
||||
|
||||
Reference in new issue
Block a user