Struct QuicConnection

Source
pub struct QuicConnection<RES> { /* private fields */ }

Implementations§

Source§

impl<RES: DeserializeOwned> QuicConnection<RES>

Source

pub async fn new<AS: AgentSigner<RES>>( url: Url, agent_signer: &AS, server_certs: &[CertificateDer<'static>], allow_quic_insecure: bool, ) -> Result<Self>

Examples found in repository?
examples/benchmark_clients.rs (line 154)
109async fn connect(client: usize, args: Args, registry: Arc<dyn ServiceRegistry>) {
110    #[cfg(feature = "quic")]
111    let default_tunnel_cert = CertificateDer::from(DEFAULT_TUNNEL_CERT.to_vec());
112
113    #[cfg(feature = "quic")]
114    let quic_certs = if let Some(cert) = args.custom_quic_cert_base64 {
115        vec![CertificateDer::from(URL_SAFE.decode(&cert).expect("Custom cert should in base64 format").to_vec())]
116    } else {
117        vec![default_tunnel_cert]
118    };
119    #[cfg(feature = "tls")]
120    let tls_cert = if let Some(cert) = args.custom_tls_cert_base64 {
121        Certificate::from_der(&URL_SAFE.decode(cert).expect("Custom cert should in base64 format")).expect("should load custom cert")
122    } else {
123        Certificate::from_der(DEFAULT_TUNNEL_CERT).expect("should load default cert")
124    };
125    let agent_signer = AgentLocalKey::random();
126
127    loop {
128        log::info!("Connecting to connector... {:?} addr: {}", args.connector_protocol, args.connector_addr);
129        let started = Instant::now();
130        match args.connector_protocol {
131            #[cfg(feature = "tcp")]
132            Protocol::Tcp => match TcpConnection::new(args.connector_addr.clone(), &agent_signer).await {
133                Ok(conn) => {
134                    log::info!("Connected to connector via tcp with res {:?}", conn.response());
135                    println!("{client} connected after {:?}", started.elapsed());
136                    run_connection_loop(conn, registry.clone()).await;
137                }
138                Err(e) => {
139                    log::error!("Connect to connector via tcp error: {e}");
140                }
141            },
142            #[cfg(feature = "tls")]
143            Protocol::Tls => match TlsConnection::new(args.connector_addr.clone(), &agent_signer, tls_cert.clone(), args.allow_tls_insecure).await {
144                Ok(conn) => {
145                    log::info!("Connected to connector via tcp with res {:?}", conn.response());
146                    println!("{client} connected after {:?}", started.elapsed());
147                    run_connection_loop(conn, registry.clone()).await;
148                }
149                Err(e) => {
150                    log::error!("Connect to connector via tcp error: {e}");
151                }
152            },
153            #[cfg(feature = "quic")]
154            Protocol::Quic => match QuicConnection::new(args.connector_addr.clone(), &agent_signer, &quic_certs, args.allow_quic_insecure).await {
155                Ok(conn) => {
156                    log::info!("Connected to connector via quic with res {:?}", conn.response());
157                    println!("{client} connected after {:?}", started.elapsed());
158                    run_connection_loop(conn, registry.clone()).await;
159                }
160                Err(e) => {
161                    log::error!("Connect to connector via quic error: {e}");
162                }
163            },
164        }
165        //TODO exponential backoff
166        sleep(std::time::Duration::from_secs(1)).await;
167    }
168}
Source

pub fn response(&self) -> &RES

Examples found in repository?
examples/benchmark_clients.rs (line 156)
109async fn connect(client: usize, args: Args, registry: Arc<dyn ServiceRegistry>) {
110    #[cfg(feature = "quic")]
111    let default_tunnel_cert = CertificateDer::from(DEFAULT_TUNNEL_CERT.to_vec());
112
113    #[cfg(feature = "quic")]
114    let quic_certs = if let Some(cert) = args.custom_quic_cert_base64 {
115        vec![CertificateDer::from(URL_SAFE.decode(&cert).expect("Custom cert should in base64 format").to_vec())]
116    } else {
117        vec![default_tunnel_cert]
118    };
119    #[cfg(feature = "tls")]
120    let tls_cert = if let Some(cert) = args.custom_tls_cert_base64 {
121        Certificate::from_der(&URL_SAFE.decode(cert).expect("Custom cert should in base64 format")).expect("should load custom cert")
122    } else {
123        Certificate::from_der(DEFAULT_TUNNEL_CERT).expect("should load default cert")
124    };
125    let agent_signer = AgentLocalKey::random();
126
127    loop {
128        log::info!("Connecting to connector... {:?} addr: {}", args.connector_protocol, args.connector_addr);
129        let started = Instant::now();
130        match args.connector_protocol {
131            #[cfg(feature = "tcp")]
132            Protocol::Tcp => match TcpConnection::new(args.connector_addr.clone(), &agent_signer).await {
133                Ok(conn) => {
134                    log::info!("Connected to connector via tcp with res {:?}", conn.response());
135                    println!("{client} connected after {:?}", started.elapsed());
136                    run_connection_loop(conn, registry.clone()).await;
137                }
138                Err(e) => {
139                    log::error!("Connect to connector via tcp error: {e}");
140                }
141            },
142            #[cfg(feature = "tls")]
143            Protocol::Tls => match TlsConnection::new(args.connector_addr.clone(), &agent_signer, tls_cert.clone(), args.allow_tls_insecure).await {
144                Ok(conn) => {
145                    log::info!("Connected to connector via tcp with res {:?}", conn.response());
146                    println!("{client} connected after {:?}", started.elapsed());
147                    run_connection_loop(conn, registry.clone()).await;
148                }
149                Err(e) => {
150                    log::error!("Connect to connector via tcp error: {e}");
151                }
152            },
153            #[cfg(feature = "quic")]
154            Protocol::Quic => match QuicConnection::new(args.connector_addr.clone(), &agent_signer, &quic_certs, args.allow_quic_insecure).await {
155                Ok(conn) => {
156                    log::info!("Connected to connector via quic with res {:?}", conn.response());
157                    println!("{client} connected after {:?}", started.elapsed());
158                    run_connection_loop(conn, registry.clone()).await;
159                }
160                Err(e) => {
161                    log::error!("Connect to connector via quic error: {e}");
162                }
163            },
164        }
165        //TODO exponential backoff
166        sleep(std::time::Duration::from_secs(1)).await;
167    }
168}

Trait Implementations§

Source§

impl<RES: Send + Sync> Connection<TunnelStream<RecvStream, SendStream>> for QuicConnection<RES>

Source§

fn create_outgoing<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<QuicSubConnection>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn recv<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<QuicSubConnection>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Auto Trait Implementations§

§

impl<RES> Freeze for QuicConnection<RES>
where RES: Freeze,

§

impl<RES> RefUnwindSafe for QuicConnection<RES>
where RES: RefUnwindSafe,

§

impl<RES> Send for QuicConnection<RES>
where RES: Send,

§

impl<RES> Sync for QuicConnection<RES>
where RES: Sync,

§

impl<RES> Unpin for QuicConnection<RES>
where RES: Unpin,

§

impl<RES> UnwindSafe for QuicConnection<RES>
where RES: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,