mirror of
https://github.com/n0-computer/noq.git
synced 2026-10-03 12:40:46 +00:00
Simple connect function
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
use std::{
|
||||
io,
|
||||
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
|
||||
};
|
||||
|
||||
use crate::{ClientConfig, Connecting, Endpoint};
|
||||
|
||||
/// Connect to `server_address`, authenticating it as `server_name`, using a new endpoint
|
||||
pub fn connect(
|
||||
config: ClientConfig,
|
||||
server_address: SocketAddr,
|
||||
server_name: &str,
|
||||
) -> io::Result<Connecting> {
|
||||
let bind_addr = match server_address {
|
||||
SocketAddr::V6(_) => IpAddr::from(Ipv6Addr::UNSPECIFIED),
|
||||
SocketAddr::V4(_) => IpAddr::from(Ipv4Addr::UNSPECIFIED),
|
||||
};
|
||||
let endpoint = Endpoint::client(SocketAddr::new(bind_addr, 0))?;
|
||||
let fut = endpoint.connect_with(config, server_address, server_name)?;
|
||||
Ok(fut)
|
||||
}
|
||||
@@ -42,6 +42,7 @@
|
||||
use std::time::Duration;
|
||||
|
||||
mod broadcast;
|
||||
mod connect;
|
||||
mod connection;
|
||||
mod endpoint;
|
||||
mod mutex;
|
||||
@@ -55,6 +56,7 @@ pub use proto::{
|
||||
Transmit, TransportConfig, VarInt,
|
||||
};
|
||||
|
||||
pub use crate::connect::connect;
|
||||
pub use crate::connection::{
|
||||
Connecting, Connection, Datagrams, IncomingBiStreams, IncomingUniStreams, NewConnection,
|
||||
OpenBi, OpenUni, SendDatagramError, ZeroRttAccepted,
|
||||
|
||||
Reference in New Issue
Block a user