pub struct QuicConnection<RES> { /* private fields */ }
Implementations§
Source§impl<RES: DeserializeOwned> QuicConnection<RES>
impl<RES: DeserializeOwned> QuicConnection<RES>
Sourcepub async fn new<AS: AgentSigner<RES>>(
url: Url,
agent_signer: &AS,
server_certs: &[CertificateDer<'static>],
allow_quic_insecure: bool,
) -> Result<Self>
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}
Sourcepub fn response(&self) -> &RES
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>
impl<RES: Send + Sync> Connection<TunnelStream<RecvStream, SendStream>> for QuicConnection<RES>
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,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more