Simple connect function

This commit is contained in:
Benjamin Saunders
2021-11-27 15:00:01 -08:00
parent bf2e4016ae
commit ba74597bc3
2 changed files with 23 additions and 0 deletions
+21
View File
@@ -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)
}
+2
View File
@@ -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,