Skip to content

Commit

Permalink
move old rama design to new crate
Browse files Browse the repository at this point in the history
so we can start the new design appraoch from scratch... once again *sigh*
  • Loading branch information
glendc committed Nov 2, 2023
1 parent 7907b53 commit c545ebc
Show file tree
Hide file tree
Showing 17 changed files with 119 additions and 97 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"rama",
"rama-old",
]
resolver = "2"
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ like `tokio` and `hyper` that we also not rely on it.
Just not somethingt worry about ourselves immediately.

```rust
use rama::{
use rama_old::{
// better name then Stream?!
server::Stream,
server::http::Request,
Expand All @@ -79,7 +79,7 @@ use rama::{
#[tokio::main]
async fn main() {
// client profiles...
let client_profile_db = rama::client::ProfileDB::new(..);
let client_profile_db = rama_old::client::ProfileDB::new(..);

let shutdown = tokio_graceful::Shutdown::default();

Expand Down Expand Up @@ -111,7 +111,7 @@ async fn main() {
}

async fn http_server(guard: Guard, client_profile_database: ProfileDatabase) {
rama::server::HttpServer::build()
rama_old::server::HttpServer::build()
.get("/k8s/health", |_| async {
"Ok"
})
Expand All @@ -126,32 +126,32 @@ async fn http_server(guard: Guard, client_profile_database: ProfileDatabase) {

async fn https_proxy(guard: Guard, client_profile_database: ProfileDatabase) {
// requires `rustls` or `boringssl` feature to be enabled
let tls_server_config = rama::server::TlsServerConfig::builder()
let tls_server_config = rama_old::server::TlsServerConfig::builder()
.with_safe_defaults()
.with_no_client_auth()
.with_single_cert(certs, key)
.unwrap();
let tls_acceptor = rama::server::TlsAcceptor::from(
let tls_acceptor = rama_old::server::TlsAcceptor::from(
std::sync::Arc::new(tls_server_config),
);

// proxy acceptor, always available
let http_proxy_config = rama::server::HttpProxyConfig::builder()
let http_proxy_config = rama_old::server::HttpProxyConfig::builder()
.with_basic_auth("username", "password")
.unwrap();
let proxy_acceptor = rama::server::HttpProxy::from(
let proxy_acceptor = rama_old::server::HttpProxy::from(
std::sync::Arc::new(http_proxy_config),
);

// profile db layer
let client_profile_database_layer = client_profile_database.layer();

// proxy db
let upstream_proxy_db = rama::proxy::ProxyDB::new(..);
let upstream_proxy_db = rama_old::proxy::ProxyDB::new(..);
let upstream_proxy_db_layer = upstream_proxy_db.layer();

// available only when enabled `smol` or `tokio`
rama::server::TcpServer::bind(&"0.0.0.0:8080".parse().unwrap())
rama_old::server::TcpServer::bind(&"0.0.0.0:8080".parse().unwrap())
.serve(|stream: Stream| async move {
let client_profile_database_layer = client_profile_database_layer.clone();

Expand All @@ -165,28 +165,28 @@ async fn https_proxy(guard: Guard, client_profile_database: ProfileDatabase) {

// serve http,
// available when `hyper` feature is enabled (== default)
rama::server::HttpConnection::builder()
rama_old::server::HttpConnection::builder()
.http1_only(true)
.http1_keep_alive(true)
.serve(
stream,
rama::client::HttpClient::new()
rama_old::client::HttpClient::new()
.handle_upgrade(
"websocket",
|request: Request| {
// ... do stuff with request if desired...
// ... todo
// for default response you can use the shipped one
rama::client::ws::accept_response(request)
rama_old::client::ws::accept_response(request)
},
|client: HttpClient, stream: Stream| {
// TODO... how to get desired client conn...
},
)
.layer(rama::middleware::http::RemoveHeaders::default())
.layer(rama_old::middleware::http::RemoveHeaders::default())
.layer(client_profile_db_layer.clone())
.layer(upstream_proxy_db_layer.clone())
.layer(rama::middleware::http::Firewall::new(
.layer(rama_old::middleware::http::Firewall::new(
Some(vec!["127.0.0.1"]),
None,
))
Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions rama-old/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[package]
categories = ["asynchronous", "network-programming"]
edition = "2021"
name = "rama-old"
version = "0.2.0"
description = "proxy framework using Tokio written purely in Rust"
homepage = "https://github.com/plabayo/rama"
readme = "../README.md"
keywords = ["io", "async", "non-blocking", "futures"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/plabayo/rama"

[[bin]]
name = "rama"
path = "./bin/main.rs"

[features]
default = [
"tokio",
]
tokio = [
"dep:tokio",
]

[dependencies]
pin-project-lite = "0.2"
tokio = { version = "1", features = ["full"], optional = true }
tower-async = { version = "0.1", features = ["full"] }
tracing = "0.1"

[dev-dependencies]
anyhow = "1.0"
clap = { version = "4.3", features = ["derive"] }
futures = "0.3"
tokio-test = "0.4"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rama::tokio::{bytes::service::EchoService, tcp::server::TcpListener};
use rama_old::tokio::{bytes::service::EchoService, tcp::server::TcpListener};

use anyhow::{Context, Result};
use clap::Parser;
Expand Down
50 changes: 50 additions & 0 deletions rama-old/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! # Rama
//!
//! rama is early work in progress, use at your own risk.
//!
//! Not everything that exists is documented and not everything that is documented is implemented.
#![warn(
clippy::all,
clippy::dbg_macro,
clippy::todo,
clippy::empty_enum,
clippy::enum_glob_use,
clippy::mem_forget,
clippy::unused_self,
clippy::filter_map_next,
clippy::needless_continue,
clippy::needless_borrow,
clippy::match_wildcard_for_single_variants,
clippy::if_let_mutex,
clippy::mismatched_target_os,
clippy::await_holding_lock,
clippy::match_on_vec_items,
clippy::imprecise_flops,
clippy::suboptimal_flops,
clippy::lossy_float_literal,
clippy::rest_pat_in_fully_bound_structs,
clippy::fn_params_excessive_bools,
clippy::exit,
clippy::inefficient_to_string,
clippy::linkedlist,
clippy::macro_use_imports,
clippy::option_option,
clippy::verbose_file_reads,
clippy::unnested_or_patterns,
rust_2018_idioms,
future_incompatible,
nonstandard_style,
missing_docs
)]
#![forbid(unsafe_code)]
#![allow(incomplete_features)]
#![feature(async_fn_in_trait)]
#![feature(return_type_notation)]
#![feature(impl_trait_projections)]
#![allow(elided_lifetimes_in_paths, clippy::type_complexity)]
#![cfg_attr(test, allow(clippy::float_cmp))]
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]

#[cfg(feature = "tokio")]
pub mod tokio;
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::tokio::bytes::ByteStream;
///
/// ```rust
/// use tower_async::Service;
/// use rama::tokio::bytes::service::EchoService;
/// use rama_old::tokio::bytes::service::EchoService;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::tokio::bytes::ByteStream;
///
/// ```rust
/// use tower_async::Service;
/// use rama::tokio::bytes::service::ForwardService;
/// use rama_old::tokio::bytes::service::ForwardService;
///
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 3 additions & 32 deletions rama/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
[package]
categories = ["asynchronous", "network-programming"]
edition = "2021"
name = "rama"
version = "0.2.0"
description = "proxy framework using Tokio written purely in Rust"
homepage = "https://github.com/plabayo/rama"
readme = "../README.md"
keywords = ["io", "async", "non-blocking", "futures"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/plabayo/rama"

[[bin]]
name = "rama"
path = "./bin/main.rs"

[features]
default = [
"tokio",
]
tokio = [
"dep:tokio",
]
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
pin-project-lite = "0.2"
tokio = { version = "1", features = ["full"], optional = true }
tower-async = { version = "0.1", features = ["full"] }
tracing = "0.1"

[dev-dependencies]
anyhow = "1.0"
clap = { version = "4.3", features = ["derive"] }
futures = "0.3"
tokio-test = "0.4"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
60 changes: 12 additions & 48 deletions rama/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,14 @@
//! # Rama
//!
//! rama is early work in progress, use at your own risk.
//!
//! Not everything that exists is documented and not everything that is documented is implemented.
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#![warn(
clippy::all,
clippy::dbg_macro,
clippy::todo,
clippy::empty_enum,
clippy::enum_glob_use,
clippy::mem_forget,
clippy::unused_self,
clippy::filter_map_next,
clippy::needless_continue,
clippy::needless_borrow,
clippy::match_wildcard_for_single_variants,
clippy::if_let_mutex,
clippy::mismatched_target_os,
clippy::await_holding_lock,
clippy::match_on_vec_items,
clippy::imprecise_flops,
clippy::suboptimal_flops,
clippy::lossy_float_literal,
clippy::rest_pat_in_fully_bound_structs,
clippy::fn_params_excessive_bools,
clippy::exit,
clippy::inefficient_to_string,
clippy::linkedlist,
clippy::macro_use_imports,
clippy::option_option,
clippy::verbose_file_reads,
clippy::unnested_or_patterns,
rust_2018_idioms,
future_incompatible,
nonstandard_style,
missing_docs
)]
#![forbid(unsafe_code)]
#![allow(incomplete_features)]
#![feature(async_fn_in_trait)]
#![feature(return_type_notation)]
#![feature(impl_trait_projections)]
#![allow(elided_lifetimes_in_paths, clippy::type_complexity)]
#![cfg_attr(test, allow(clippy::float_cmp))]
#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
#[cfg(test)]
mod tests {
use super::*;

#[cfg(feature = "tokio")]
pub mod tokio;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

0 comments on commit c545ebc

Please sign in to comment.