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