Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use dyn upcasting for server traits #131

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
strategy:
matrix:
rust:
- stable
- beta
- nightly
#- stable
#- beta
- nightly
steps:
- name: Checkout sources
uses: actions/checkout@v4
Expand All @@ -38,7 +38,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@nightly
with:
components: clippy
- name: Install dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
strategy:
matrix:
rust:
- stable
- beta
#- stable
#- beta
- nightly
steps:
- name: Checkout sources
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@nightly
with:
components: clippy
- name: Install dependencies
Expand Down
8 changes: 3 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ g3-ctl = { version = "0.1", path = "lib/g3-ctl" }
g3-datetime = { version = "0.1", path = "lib/g3-datetime" }
g3-dpi = { version = "0.1", path = "lib/g3-dpi" }
g3-fluentd = { version = "0.1", path = "lib/g3-fluentd" }
g3-ftp-client = { version = "0.2", path = "lib/g3-ftp-client" }
g3-ftp-client = { version = "0.3", path = "lib/g3-ftp-client" }
g3-h2 = { version = "0.1", path = "lib/g3-h2" }
g3-http = { version = "0.2", path = "lib/g3-http" }
g3-icap-client = { version = "0.1", path = "lib/g3-icap-client" }
g3-icap-client = { version = "0.2", path = "lib/g3-icap-client" }
g3-io-ext = { version = "0.6", path = "lib/g3-io-ext" }
g3-journal = { version = "0.2", path = "lib/g3-journal" }
g3-json = { version = "0.3", path = "lib/g3-json" }
Expand Down
1 change: 0 additions & 1 deletion g3bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ thiserror.workspace = true
anyhow.workspace = true
clap.workspace = true
clap_complete.workspace = true
async-trait.workspace = true
indicatif = "0.17"
tokio = { workspace = true, features = ["rt", "net", "macros"] }
http.workspace = true
Expand Down
2 changes: 0 additions & 2 deletions g3bench/src/target/dns/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::cell::UnsafeCell;
use std::sync::Arc;

use anyhow::{anyhow, Context};
use async_trait::async_trait;
use hickory_client::client::{AsyncClient, ClientHandle};
use hickory_proto::op::ResponseCode;
use tokio::time::Instant;
Expand Down Expand Up @@ -133,7 +132,6 @@ impl DnsTaskContext {
}
}

#[async_trait]
impl BenchTaskContext for DnsTaskContext {
fn mark_task_start(&self) {
self.runtime_stats.add_task_total();
Expand Down
2 changes: 0 additions & 2 deletions g3bench/src/target/h1/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::sync::Arc;
use std::time::Duration;

use anyhow::{anyhow, Context};
use async_trait::async_trait;
use futures_util::FutureExt;
use tokio::io::{AsyncReadExt, AsyncWriteExt, BufReader};
use tokio::time::Instant;
Expand Down Expand Up @@ -183,7 +182,6 @@ impl HttpTaskContext {
}
}

#[async_trait]
impl BenchTaskContext for HttpTaskContext {
fn mark_task_start(&self) {
self.runtime_stats.add_task_total();
Expand Down
2 changes: 0 additions & 2 deletions g3bench/src/target/h2/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::sync::Arc;

use anyhow::{anyhow, Context};
use async_trait::async_trait;
use bytes::Bytes;
use h2::client::SendRequest;
use tokio::time::Instant;
Expand Down Expand Up @@ -180,7 +179,6 @@ impl H2TaskContext {
}
}

#[async_trait]
impl BenchTaskContext for H2TaskContext {
fn mark_task_start(&self) {
self.runtime_stats.add_task_total();
Expand Down
2 changes: 0 additions & 2 deletions g3bench/src/target/h3/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::sync::Arc;

use anyhow::{anyhow, Context};
use async_trait::async_trait;
use bytes::Bytes;
use h3::client::SendRequest;
use h3_quinn::OpenStreams;
Expand Down Expand Up @@ -167,7 +166,6 @@ impl H3TaskContext {
}
}

#[async_trait]
impl BenchTaskContext for H3TaskContext {
fn mark_task_start(&self) {
self.runtime_stats.add_task_total();
Expand Down
2 changes: 0 additions & 2 deletions g3bench/src/target/keyless/cloudflare/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::sync::Arc;

use anyhow::anyhow;
use async_trait::async_trait;
use tokio::time::Instant;

use super::{
Expand Down Expand Up @@ -179,7 +178,6 @@ impl KeylessCloudflareTaskContext {
}
}

#[async_trait]
impl BenchTaskContext for KeylessCloudflareTaskContext {
fn mark_task_start(&self) {
self.runtime_stats.add_task_total();
Expand Down
2 changes: 0 additions & 2 deletions g3bench/src/target/keyless/openssl/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use std::sync::Arc;

use async_trait::async_trait;
use tokio::time::Instant;

use super::{
Expand Down Expand Up @@ -57,7 +56,6 @@ impl KeylessOpensslTaskContext {
}
}

#[async_trait]
impl BenchTaskContext for KeylessOpensslTaskContext {
fn mark_task_start(&self) {
self.runtime_stats.add_task_total();
Expand Down
11 changes: 8 additions & 3 deletions g3bench/src/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

use std::future::Future;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;

use anyhow::{anyhow, Context};
use async_trait::async_trait;
use cadence::{Gauged, StatsdClient};
use hdrhistogram::Histogram;
use tokio::signal::unix::SignalKind;
Expand Down Expand Up @@ -173,12 +173,17 @@ enum BenchError {
Task(anyhow::Error),
}

#[async_trait]
trait BenchTaskContext {
fn mark_task_start(&self);
fn mark_task_passed(&self);
fn mark_task_failed(&self);
async fn run(&mut self, task_id: usize, time_started: Instant) -> Result<(), BenchError>;

// TODO use native async fn declaration
fn run(
&mut self,
task_id: usize,
time_started: Instant,
) -> impl Future<Output = Result<(), BenchError>> + Send;
}

trait BenchTarget<RS, H, C>
Expand Down
2 changes: 0 additions & 2 deletions g3bench/src/target/ssl/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::sync::Arc;
use std::time::Duration;

use anyhow::anyhow;
use async_trait::async_trait;
use tokio::io::AsyncWriteExt;
use tokio::net::TcpStream;
use tokio::time::Instant;
Expand Down Expand Up @@ -76,7 +75,6 @@ impl SslTaskContext {
}
}

#[async_trait]
impl BenchTaskContext for SslTaskContext {
fn mark_task_start(&self) {
self.runtime_stats.add_task_total();
Expand Down
1 change: 0 additions & 1 deletion g3keymess/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ chrono = { workspace = true, features = ["clock"] }
uuid.workspace = true
url.workspace = true
ahash.workspace = true
async-trait.workspace = true
futures-util.workspace = true
cadence.workspace = true
itoa.workspace = true
Expand Down
2 changes: 0 additions & 2 deletions g3keymess/src/config/store/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::path::{Path, PathBuf};

use anyhow::anyhow;
use async_trait::async_trait;
use openssl::pkey::{PKey, Private};
use tokio::sync::oneshot;
use yaml_rust::{yaml, Yaml};
Expand Down Expand Up @@ -88,7 +87,6 @@ impl LocalKeyStoreConfig {
}
}

#[async_trait]
impl KeyStoreConfig for LocalKeyStoreConfig {
#[inline]
fn name(&self) -> &MetricsName {
Expand Down
2 changes: 0 additions & 2 deletions g3keymess/src/config/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use std::path::Path;

use anyhow::anyhow;
use async_trait::async_trait;
use openssl::pkey::{PKey, Private};
use tokio::sync::oneshot;
use yaml_rust::{yaml, Yaml};
Expand All @@ -33,7 +32,6 @@ pub(crate) use registry::{clear, get_all};

const CONFIG_KEY_STORE_TYPE: &str = "type";

#[async_trait]
pub trait KeyStoreConfig {
fn name(&self) -> &MetricsName;
async fn load_certs(&self) -> anyhow::Result<Vec<PKey<Private>>>;
Expand Down
2 changes: 0 additions & 2 deletions g3keymess/src/config/store/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

use anyhow::anyhow;
use async_trait::async_trait;
use openssl::pkey::{PKey, Private};
use url::Url;
use yaml_rust::{yaml, Yaml};
Expand Down Expand Up @@ -80,7 +79,6 @@ impl RedisKeyStoreConfig {
}
}

#[async_trait]
impl KeyStoreConfig for RedisKeyStoreConfig {
#[inline]
fn name(&self) -> &MetricsName {
Expand Down
2 changes: 0 additions & 2 deletions g3proxy/src/inspect/http/v1/forward/adaptation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::io::{self, IoSlice};
use std::pin::Pin;
use std::task::{Context, Poll};

use async_trait::async_trait;
use tokio::io::{AsyncWrite, AsyncWriteExt};

use g3_http::server::HttpTransparentRequest;
Expand Down Expand Up @@ -61,7 +60,6 @@ where
}
}

#[async_trait]
impl<'a, W> HttpRequestUpstreamWriter<HttpTransparentRequest>
for HttpRequestWriterForAdaptation<'a, W>
where
Expand Down
2 changes: 2 additions & 0 deletions g3proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

#![feature(trait_upcasting)]

pub mod audit;
pub mod auth;
pub mod config;
Expand Down
1 change: 0 additions & 1 deletion g3proxy/src/module/http_forward/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ impl<'a> AsyncWrite for HttpForwardWriterForAdaptation<'a> {
}
}

#[async_trait]
impl<'a> HttpRequestUpstreamWriter<HttpProxyClientRequest> for HttpForwardWriterForAdaptation<'a> {
async fn send_request_header(&mut self, req: &HttpProxyClientRequest) -> io::Result<()> {
self.inner.send_request_header(req).await
Expand Down
Loading