Skip to content

Commit

Permalink
first draft, no custom root cert
Browse files Browse the repository at this point in the history
  • Loading branch information
rucciva committed Oct 15, 2024
1 parent be14d12 commit d5d41b8
Show file tree
Hide file tree
Showing 10 changed files with 1,121 additions and 379 deletions.
997 changes: 620 additions & 377 deletions Cargo.lock
100644 → 100755

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions Cargo.toml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ default = [
"native-tls",
"noise",
"websocket-native-tls",
"http2-native-tls",
"hot-reload",
]

Expand Down Expand Up @@ -53,6 +54,26 @@ websocket-rustls = [
"rustls",
]

# HTTP2 support
http2-native-tls = [
"hyper",
"hyper-util",
"http",
"http-body-util",
"tokio-util",
"hyper-tls",
"native-tls",
]
http2-rustls = [
"hyper",
"hyper-util",
"http",
"http-body-util",
"tokio-util",
"hyper-tls",
"rustls",
]

# Configuration hot-reload support
hot-reload = ["notify"]

Expand Down Expand Up @@ -117,6 +138,11 @@ async-http-proxy = { version = "1.2", features = [
async-socks5 = "0.5"
url = { version = "2.2", features = ["serde"] }
tokio-tungstenite = { version = "0.20.1", optional = true }
http = { version = "1.1.0", optional = true }
hyper = { version = "1.4.1", optional = true , features = ["client","server","http2"] }
hyper-util = { version = "0.1.9", optional = true , features = ["full"]}
http-body-util = { version = "0.1.2", optional = true }
hyper-tls = { version = "0.6.0", optional = true }
tokio-util = { version = "0.7.9", optional = true, features = ["io"] }
futures-core = { version = "0.3.28", optional = true }
futures-sink = { version = "0.3.28", optional = true }
Expand Down
11 changes: 10 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::protocol::{
self, read_ack, read_control_cmd, read_data_cmd, read_hello, Ack, Auth, ControlChannelCmd,
DataChannelCmd, UdpTraffic, CURRENT_PROTO_VERSION, HASH_WIDTH_IN_BYTES,
};
use crate::transport::{AddrMaybeCached, SocketOpts, TcpTransport, Transport};
use crate::transport::{AddrMaybeCached, HTTP2Transport, SocketOpts, TcpTransport, Transport};
use anyhow::{anyhow, bail, Context, Result};
use backoff::backoff::Backoff;
use backoff::future::retry_notify;
Expand Down Expand Up @@ -74,6 +74,15 @@ pub async fn run_client(
#[cfg(not(any(feature = "websocket-native-tls", feature = "websocket-rustls")))]
crate::helper::feature_neither_compile("websocket-native-tls", "websocket-rustls")
}
TransportType::HTTP2 => {
#[cfg(any(feature = "http2-native-tls", feature = "http2-rustls"))]
{
let mut client = Client::<HTTP2Transport>::from(config).await?;
client.run(shutdown_rx, update_rx).await
}
#[cfg(not(any(feature = "http2-native-tls", feature = "http2-rustls")))]
crate::helper::feature_neither_compile("http2-native-tls", "http2-rustls")
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/config.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub enum TransportType {
Noise,
#[serde(rename = "websocket")]
Websocket,
#[serde(rename = "http2")]
HTTP2,
}

/// Per service config
Expand Down Expand Up @@ -141,6 +143,12 @@ pub struct WebsocketConfig {
pub tls: bool,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct HTTP2Config {
pub tls: bool,
}

fn default_nodelay() -> bool {
DEFAULT_NODELAY
}
Expand Down Expand Up @@ -186,6 +194,7 @@ pub struct TransportConfig {
pub tls: Option<TlsConfig>,
pub noise: Option<NoiseConfig>,
pub websocket: Option<WebsocketConfig>,
pub http2: Option<HTTP2Config>,
}

fn default_heartbeat_timeout() -> u64 {
Expand Down Expand Up @@ -320,6 +329,7 @@ impl Config {
Ok(())
}
TransportType::Websocket => Ok(()),
TransportType::HTTP2 => Ok(()),
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::protocol::{
self, read_auth, read_hello, Ack, ControlChannelCmd, DataChannelCmd, Hello, UdpTraffic,
HASH_WIDTH_IN_BYTES,
};
use crate::transport::{SocketOpts, TcpTransport, Transport};
use crate::transport::{HTTP2Transport, SocketOpts, TcpTransport, Transport};
use anyhow::{anyhow, bail, Context, Result};
use backoff::backoff::Backoff;
use backoff::ExponentialBackoff;
Expand Down Expand Up @@ -83,6 +83,15 @@ pub async fn run_server(
#[cfg(not(any(feature = "websocket-native-tls", feature = "websocket-rustls")))]
crate::helper::feature_neither_compile("websocket-native-tls", "websocket-rustls")
}
TransportType::HTTP2 => {
#[cfg(any(feature = "http2-native-tls", feature = "http2-rustls"))]
{
let mut server = Server::<HTTP2Transport>::from(config).await?;
server.run(shutdown_rx, update_rx).await?;
}
#[cfg(not(any(feature = "http2-native-tls", feature = "http2-rustls")))]
crate::helper::feature_neither_compile("http2-native-tls", "http2-rustls")
}
}

Ok(())
Expand Down
Loading

0 comments on commit d5d41b8

Please sign in to comment.