├── .gitignore ├── rust-toolchain ├── monoio-gateway ├── src │ ├── proxy │ │ ├── h2.rs │ │ ├── mod.rs │ │ ├── tcp.rs │ │ └── h1.rs │ ├── lib.rs │ ├── main.rs │ └── gateway.rs └── Cargo.toml ├── monoio-gateway-core ├── src │ ├── balance │ │ ├── mod.rs │ │ └── balance.rs │ ├── error │ │ └── mod.rs │ ├── util │ │ ├── mod.rs │ │ ├── identity.rs │ │ └── stack.rs │ ├── discover │ │ ├── change.rs │ │ ├── mod.rs │ │ └── discover.rs │ ├── http │ │ ├── version.rs │ │ ├── mod.rs │ │ ├── detect.rs │ │ ├── rewrite.rs │ │ ├── ssl.rs │ │ └── router.rs │ ├── dns │ │ ├── mod.rs │ │ ├── tcp.rs │ │ └── http.rs │ ├── config.rs │ ├── acme │ │ ├── mod.rs │ │ └── acme.rs │ ├── service.rs │ ├── lib.rs │ └── transfer │ │ └── mod.rs └── Cargo.toml ├── examples ├── cert │ ├── rootCA.srl │ ├── v3.ext │ ├── README.md │ ├── server.csr │ ├── rootCA.crt │ ├── server.crt │ ├── rootCA.key │ └── server.key ├── config.json ├── tcp-proxy.rs ├── Cargo.toml ├── http-proxy.rs ├── router-with-delay.rs ├── https-proxy.rs └── acme.rs ├── monoio-gateway-services ├── src │ ├── lib.rs │ └── layer │ │ ├── mod.rs │ │ ├── auth.rs │ │ ├── acme.rs │ │ ├── discover.rs │ │ ├── accept.rs │ │ ├── delay.rs │ │ ├── timeout.rs │ │ ├── listen.rs │ │ ├── detect.rs │ │ ├── endpoint.rs │ │ ├── tls.rs │ │ └── router.rs └── Cargo.toml ├── Cargo.toml ├── monoio-gateway.code-workspace ├── README.md ├── LICENSE └── Cargo.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | nightly -------------------------------------------------------------------------------- /monoio-gateway/src/proxy/h2.rs: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/balance/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod balance; 2 | -------------------------------------------------------------------------------- /examples/cert/rootCA.srl: -------------------------------------------------------------------------------- 1 | 6890BF801227B6406D46B41DB48334CC8EE5E7BB 2 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/error/mod.rs: -------------------------------------------------------------------------------- 1 | pub type GError = anyhow::Error; 2 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/util/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod identity; 2 | pub mod stack; 3 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(type_alias_impl_trait)] 2 | 3 | pub mod layer; 4 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/discover/change.rs: -------------------------------------------------------------------------------- 1 | pub enum DiscoverChange { 2 | Add(Key, S), 3 | Remove(Key, S), 4 | None, 5 | } 6 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "monoio-gateway", 4 | "monoio-gateway-core", 5 | "monoio-gateway-services", 6 | # examples 7 | "examples" 8 | ] -------------------------------------------------------------------------------- /monoio-gateway-core/src/http/version.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug)] 2 | pub enum Version { 3 | HTTP11, 4 | HTTP2, 5 | } 6 | 7 | #[derive(Debug)] 8 | pub enum Type { 9 | HTTP, 10 | HTTPS, 11 | } 12 | -------------------------------------------------------------------------------- /examples/cert/v3.ext: -------------------------------------------------------------------------------- 1 | authorityKeyIdentifier=keyid,issuer 2 | basicConstraints=CA:FALSE 3 | keyUsage=digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment 4 | extendedKeyUsage=serverAuth 5 | subjectAltName=@alt_names 6 | 7 | [alt_names] 8 | DNS.1=monoio.rs 9 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/balance/balance.rs: -------------------------------------------------------------------------------- 1 | use crate::{discover::Discover, service::SvcList}; 2 | 3 | // /// Load Balancer 4 | pub struct Balance 5 | where 6 | D: Discover, 7 | S: IntoIterator, 8 | { 9 | pub discover: D, 10 | pub services: SvcList, 11 | } 12 | -------------------------------------------------------------------------------- /monoio-gateway/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(type_alias_impl_trait)] 2 | 3 | pub mod gateway; 4 | pub mod proxy; 5 | 6 | pub trait ParamRef { 7 | fn param_ref(&self) -> &T; 8 | } 9 | 10 | pub trait ParamMut { 11 | fn param_mut(&mut self) -> &mut T; 12 | } 13 | 14 | pub fn init_env() { 15 | env_logger::init(); 16 | } 17 | -------------------------------------------------------------------------------- /monoio-gateway/src/proxy/mod.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | 3 | pub mod h1; 4 | pub mod h2; 5 | pub mod tcp; 6 | 7 | pub trait Proxy { 8 | type Error; 9 | type OutputFuture<'a>: Future> 10 | where 11 | Self: 'a; 12 | 13 | fn io_loop(&self) -> Self::OutputFuture<'_>; 14 | } 15 | -------------------------------------------------------------------------------- /monoio-gateway.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | }, 6 | { 7 | "path": "../monoio-http" 8 | }, 9 | { 10 | "path": "../monoio-codec" 11 | }, 12 | { 13 | "path": "../monoio" 14 | }, 15 | { 16 | "path": "../../../../var/monoio-gateway/acme/monoio-gateway.kingtous.cn" 17 | } 18 | ], 19 | "settings": {} 20 | } -------------------------------------------------------------------------------- /monoio-gateway-core/src/util/identity.rs: -------------------------------------------------------------------------------- 1 | use crate::service::Layer; 2 | 3 | #[derive(Default)] 4 | pub struct Identity { 5 | _p: (), 6 | } 7 | 8 | impl Identity { 9 | pub fn new() -> Self { 10 | Self { _p: () } 11 | } 12 | } 13 | 14 | impl Layer for Identity { 15 | type Service = S; 16 | 17 | fn layer(&self, inner: S) -> Self::Service { 18 | inner 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod accept; 2 | pub mod acme; 3 | pub mod auth; 4 | pub mod delay; 5 | pub mod detect; 6 | pub mod discover; 7 | pub mod endpoint; 8 | pub mod listen; 9 | pub mod router; 10 | pub mod timeout; 11 | pub mod tls; 12 | /// monoio service layer 13 | 14 | pub trait NewService { 15 | type Service; 16 | 17 | fn new_svc(&self, inner: I) -> Self::Service; 18 | } 19 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/http/mod.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | 3 | pub mod detect; 4 | pub mod router; 5 | pub mod ssl; 6 | pub mod version; 7 | 8 | mod rewrite; 9 | pub use rewrite::Rewrite; 10 | 11 | pub trait Detect { 12 | type Protocol; 13 | type DetectFuture<'a>: Future, anyhow::Error>> 14 | where 15 | Self: 'a; 16 | 17 | fn detect_proto(&self, io: &mut I) -> Self::DetectFuture<'_>; 18 | } 19 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/dns/mod.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fmt::{Debug, Display}, 3 | future::Future, 4 | hash::Hash, 5 | net::ToSocketAddrs, 6 | }; 7 | 8 | pub mod http; 9 | pub mod tcp; 10 | 11 | pub trait Resolvable: Clone + Display + PartialEq + Eq + Hash { 12 | type Error: Debug; 13 | type Address: ToSocketAddrs; 14 | type ResolveFuture<'a>: Future, Self::Error>> 15 | where 16 | Self: 'a; 17 | 18 | fn resolve(&self) -> Self::ResolveFuture<'_>; 19 | } 20 | -------------------------------------------------------------------------------- /examples/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "configs": [ 3 | { 4 | "server_name": "test.kingtous.cn", 5 | "listen_port": [80, 443], 6 | "rules": [ 7 | { 8 | "path": "/", 9 | "proxy_pass": { 10 | "uri": "https://file.kingtous.cn" 11 | } 12 | }, 13 | { 14 | "path": "/docs", 15 | "proxy_pass": { 16 | "uri": "http://captive.apple.com" 17 | } 18 | } 19 | ], 20 | "tls": { 21 | "mail": "me@kingtous.cn" 22 | } 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /monoio-gateway-core/src/discover/mod.rs: -------------------------------------------------------------------------------- 1 | use std::{fmt::Display, future::Future}; 2 | 3 | use self::change::DiscoverChange; 4 | 5 | pub mod change; 6 | pub mod discover; 7 | 8 | /// Service Discover Trait 9 | pub trait Discover { 10 | type Key: Eq; 11 | 12 | type Service; 13 | 14 | type Error: Display; 15 | 16 | type DiscoverFuture<'a>: Future< 17 | Output = Result>, Self::Error>, 18 | > 19 | where 20 | Self: 'a; 21 | 22 | fn discover(&self) -> Self::DiscoverFuture<'_>; 23 | } 24 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/http/detect.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | 3 | use monoio::io::AsyncReadRent; 4 | 5 | use super::Detect; 6 | 7 | #[derive(Default)] 8 | pub struct DetectHttpVersion {} 9 | 10 | impl Detect for DetectHttpVersion 11 | where 12 | I: AsyncReadRent, 13 | { 14 | type Protocol = DetectHttpVersion; 15 | 16 | type DetectFuture<'a> = impl Future, anyhow::Error>>; 17 | 18 | fn detect_proto(&self, _io: &mut I) -> Self::DetectFuture<'_> { 19 | // TODO 20 | async { Ok(None) } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/util/stack.rs: -------------------------------------------------------------------------------- 1 | use crate::service::Layer; 2 | 3 | pub struct Stack { 4 | pub(crate) inner: I, 5 | pub(crate) outer: O, 6 | } 7 | 8 | impl Stack { 9 | pub fn new(inner: I, outer: O) -> Stack { 10 | Self { inner, outer } 11 | } 12 | } 13 | 14 | impl Layer for Stack 15 | where 16 | I: Layer, 17 | O: Layer, 18 | { 19 | type Service = O::Service; 20 | 21 | fn layer(&self, service: S) -> Self::Service { 22 | let inner = self.inner.layer(service); 23 | 24 | self.outer.layer(inner) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/discover/discover.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | 3 | use crate::error::GError; 4 | 5 | use super::{change::DiscoverChange, Discover}; 6 | 7 | pub struct DummyDiscover { 8 | data: S, 9 | } 10 | 11 | impl Discover for DummyDiscover 12 | where 13 | S: Clone, 14 | { 15 | type Key = (); 16 | 17 | type Service = S; 18 | 19 | type Error = GError; 20 | 21 | type DiscoverFuture<'a> = impl Future< 22 | Output = Result>, Self::Error>, 23 | > + 'a 24 | where 25 | Self: 'a; 26 | 27 | fn discover(&self) -> Self::DiscoverFuture<'_> { 28 | async { Ok(Some(DiscoverChange::Add((), self.data.clone()))) } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /monoio-gateway-services/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "monoio-gateway-services" 3 | version = "0.1.1" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | monoio = {version = "0.0.9", features = ['splice'], path = "../../monoio/monoio"} 10 | monoio-gateway-core = {path = "../monoio-gateway-core"} 11 | monoio-http = {version = "0.0.2", path = "../../monoio-http/monoio-http"} 12 | monoio-rustls = {version = "0.0.7", path = "../../monoio-tls/monoio-rustls", features = ["tls12"], default-features=false} 13 | # tls 14 | rustls = {version = "0.20", features = ["tls12"]} 15 | rustls-pemfile = "1" 16 | webpki-roots = "0.22" 17 | 18 | anyhow = "1" 19 | log = "0.4" 20 | http = "0.2" 21 | acme-lib = "0.8" 22 | bytes = "1" 23 | 24 | async-channel = "1" 25 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/auth.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | 3 | use http::HeaderValue; 4 | use monoio_gateway_core::{error::GError, service::Service}; 5 | use monoio_http::common::request::Request; 6 | 7 | #[derive(Clone)] 8 | pub struct BearerAuthService { 9 | token: String, 10 | } 11 | 12 | impl Service for BearerAuthService { 13 | type Response = Request; 14 | 15 | type Error = GError; 16 | 17 | type Future<'cx> = impl Future> + 'cx 18 | where 19 | Self: 'cx; 20 | 21 | fn call(&mut self, mut req: Request) -> Self::Future<'_> { 22 | async { 23 | let headers = req.headers_mut(); 24 | headers.insert("Authorization", HeaderValue::from_str(&self.token).unwrap()); 25 | Ok(req) 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /monoio-gateway/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "monoio-gateway" 3 | version = "0.1.1" 4 | edition = "2021" 5 | keywords = ["monoio", "http", "async"] 6 | description = "The gateway plugin for monoio" 7 | 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 9 | 10 | [dependencies] 11 | monoio-gateway-core = { path = "../monoio-gateway-core", features = ['full'] } 12 | monoio-gateway-services = { path = "../monoio-gateway-services" } 13 | 14 | monoio = { version = "0.0.9", path = "../../monoio/monoio" } 15 | monoio-http = { version = "0.0.2", path = "../../monoio-http/monoio-http" } 16 | 17 | bytes = "1" 18 | http = "0.2" 19 | httparse = "1" 20 | thiserror = "1" 21 | anyhow = "1" 22 | # logger 23 | env_logger = "0.10" 24 | log = "0.4" 25 | clap = { version = "4", features = ['derive'] } 26 | 27 | tower = { version = "0.4", features = ["full"] } 28 | 29 | serde = "1" 30 | serde_json = "1" 31 | serde_derive = "1" 32 | -------------------------------------------------------------------------------- /monoio-gateway-core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "monoio-gateway-core" 3 | version = "0.1.1" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | monoio = {version = "0.0.9", features = ['splice'], path = "../../monoio/monoio"} 10 | monoio-http = {version = "0.0.2", path = "../../monoio-http/monoio-http"} 11 | monoio-rustls = {version = "0.0.7", path = "../../monoio-tls/monoio-rustls", features = ["tls12"], default-features=false} 12 | 13 | thiserror = "1" 14 | anyhow = "1" 15 | http = "0.2" 16 | http-serde = "1" 17 | 18 | serde = "1" 19 | serde_derive = "1" 20 | serde_json = "1" 21 | 22 | log = "0.4" 23 | 24 | figlet-rs = "0.1" 25 | 26 | acme-lib = "0.8" 27 | lazy_static = "1" 28 | 29 | rustls = {version = "0.20", features = ["tls12"]} 30 | rustls-pemfile = "1" 31 | webpki-roots = "0.22" 32 | 33 | [features] 34 | default = [] 35 | acme = [] 36 | full = ['acme'] -------------------------------------------------------------------------------- /examples/tcp-proxy.rs: -------------------------------------------------------------------------------- 1 | use monoio_gateway::{ 2 | init_env, 3 | proxy::{tcp::TcpProxy, Proxy}, 4 | }; 5 | use monoio_gateway_core::{ 6 | dns::tcp::TcpAddress, 7 | http::router::{RouterConfig, RouterRule}, 8 | }; 9 | 10 | /// a simple tcp proxy 11 | #[monoio::main(timer_enabled = true)] 12 | async fn main() -> Result<(), anyhow::Error> { 13 | init_env(); 14 | let target = TcpAddress::new("127.0.0.1:8000".parse().expect("tcp address is not valid")); 15 | let _listen_port = 5000; 16 | let server_name = "".to_string(); 17 | let router_config = vec![RouterConfig { 18 | server_name: server_name.to_owned(), 19 | listen_port: vec![80], 20 | rules: vec![RouterRule { 21 | path: "".to_string(), 22 | proxy_pass: target.clone(), 23 | }], 24 | tls: None, 25 | }]; 26 | let tcp_proxy = TcpProxy::build_with_config(&router_config); 27 | tcp_proxy.io_loop().await?; 28 | Ok(()) 29 | } 30 | -------------------------------------------------------------------------------- /examples/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "monoio-gateway-examples" 3 | version = "0.1.1" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | monoio-gateway = {path = '../monoio-gateway'} 10 | monoio-gateway-core = {path = '../monoio-gateway-core', features = ['full']} 11 | monoio-gateway-services = {path = '../monoio-gateway-services'} 12 | monoio = {version = "0.0.9", features = ['splice'], path = "../../monoio/monoio"} 13 | monoio-http = {version = "0.0.2", path = '../../monoio-http/monoio-http'} 14 | anyhow = "1" 15 | 16 | 17 | [[example]] 18 | name = "tcp-proxy" 19 | path = "tcp-proxy.rs" 20 | 21 | [[example]] 22 | name = "http-proxy" 23 | path = "http-proxy.rs" 24 | 25 | [[example]] 26 | name = "https-proxy" 27 | path = "https-proxy.rs" 28 | 29 | [[example]] 30 | name = "router-with-delay" 31 | path = "router-with-delay.rs" 32 | 33 | [[example]] 34 | name = "acme" 35 | path = "acme.rs" 36 | -------------------------------------------------------------------------------- /examples/http-proxy.rs: -------------------------------------------------------------------------------- 1 | use monoio_gateway::{ 2 | gateway::{Gateway, Gatewayable, Servable}, 3 | init_env, 4 | }; 5 | use monoio_gateway_core::{ 6 | dns::http::Domain, 7 | http::router::{Router, RouterConfig, RouterRule, RoutersConfig}, 8 | Builder, 9 | }; 10 | 11 | #[monoio::main(timer_enabled = true)] 12 | async fn main() -> Result<(), anyhow::Error> { 13 | init_env(); 14 | let domain = Domain::with_uri("http://127.0.0.1:8000".parse()?); 15 | let server_name = "python.server:5000".to_string(); 16 | let listen_port = 5000; 17 | let router_config = RouterConfig { 18 | server_name: server_name.clone(), 19 | listen_port: vec![listen_port], 20 | rules: vec![RouterRule { 21 | path: "/".to_string(), 22 | proxy_pass: domain.clone(), 23 | }], 24 | tls: None, 25 | }; 26 | let conf = RoutersConfig { 27 | configs: vec![router_config], 28 | }; 29 | let router = Router::build_with_config(conf); 30 | let gws = Gateway::from_router(router); 31 | let _ = gws.serve().await; 32 | Ok(()) 33 | } 34 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/acme.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | 3 | use acme_lib::Certificate; 4 | use anyhow::bail; 5 | use monoio_gateway_core::{ 6 | acme::{Acme, GenericAcme}, 7 | error::GError, 8 | service::Service, 9 | }; 10 | 11 | pub type ServerName = String; 12 | pub type Email = String; 13 | pub type AcmeParams = (ServerName, Email); 14 | 15 | #[derive(Clone)] 16 | pub struct LetsEncryptService; 17 | 18 | impl Service for LetsEncryptService { 19 | type Response = Option; 20 | 21 | type Error = GError; 22 | 23 | type Future<'cx> = impl Future> 24 | where 25 | Self: 'cx; 26 | 27 | fn call(&mut self, req: AcmeParams) -> Self::Future<'_> { 28 | async move { 29 | let acme = GenericAcme::new_lets_encrypt(req.0, req.1); 30 | match acme.acme(()).await { 31 | Ok(Some(cert)) => { 32 | let cert: Certificate = cert; 33 | Ok(Some(cert)) 34 | } 35 | Ok(None) => Ok(None), 36 | Err(err) => bail!("{}", err), 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/router-with-delay.rs: -------------------------------------------------------------------------------- 1 | use monoio_gateway::{ 2 | gateway::{Gateway, Gatewayable, Servable}, 3 | init_env, 4 | }; 5 | use monoio_gateway_core::{ 6 | dns::http::Domain, 7 | error::GError, 8 | http::router::{Router, RouterConfig, RouterRule, RoutersConfig}, 9 | Builder, 10 | }; 11 | 12 | /// This is an example to builder to proxy with 1s delay per request 13 | #[monoio::main(timer_enabled = true)] 14 | pub async fn main() -> Result<(), GError> { 15 | init_env(); 16 | let domain = Domain::with_uri("http://127.0.0.1:8000".parse()?); 17 | let server_name = "python.server:5000".to_string(); 18 | let listen_port = 5000; 19 | let router_config = RouterConfig { 20 | server_name: server_name.clone(), 21 | listen_port: vec![listen_port], 22 | rules: vec![RouterRule { 23 | path: "/".to_string(), 24 | proxy_pass: domain.clone(), 25 | }], 26 | tls: None, 27 | }; 28 | let conf = RoutersConfig { 29 | configs: vec![router_config], 30 | }; 31 | let router = Router::build_with_config(conf); 32 | let gws = Gateway::from_router(router); 33 | let _ = gws.serve().await; 34 | Ok(()) 35 | } 36 | -------------------------------------------------------------------------------- /examples/https-proxy.rs: -------------------------------------------------------------------------------- 1 | use monoio_gateway::{ 2 | gateway::{Gateway, Gatewayable, Servable}, 3 | init_env, 4 | }; 5 | use monoio_gateway_core::{ 6 | dns::http::Domain, 7 | http::router::{Router, RouterConfig, RouterRule, RoutersConfig, TlsConfig}, 8 | Builder, 9 | }; 10 | 11 | #[monoio::main(timer_enabled = true)] 12 | async fn main() -> Result<(), anyhow::Error> { 13 | init_env(); 14 | let domain = Domain::with_uri("http://127.0.0.1:8000".parse()?); 15 | let server_name = "monoio-gateway.kingtous.cn".to_string(); 16 | let router_config = RouterConfig { 17 | server_name: server_name.clone(), 18 | listen_port: vec![80, 443], 19 | rules: vec![RouterRule { 20 | path: "/".to_string(), 21 | proxy_pass: domain.clone(), 22 | }], 23 | tls: Some(TlsConfig { 24 | mail: "me@kingtous.cn".into(), 25 | chain: None, 26 | private_key: None, 27 | }), 28 | }; 29 | let conf = RoutersConfig { 30 | configs: vec![router_config], 31 | }; 32 | let router = Router::build_with_config(conf); 33 | let gws = Gateway::from_router(router); 34 | let _ = gws.serve().await; 35 | Ok(()) 36 | } 37 | -------------------------------------------------------------------------------- /examples/cert/README.md: -------------------------------------------------------------------------------- 1 | # Certs 2 | Note: The certificates here are only for demo. 3 | 4 | ## Self Signed Cert Generation 5 | If you want to generate CA and server certificates by yourself, please make sure the certificates are in x509 v3 format(since webpki only support v3, and there's no way to convert v1 to v3). By default openssl generate server certificate in x509 v1. 6 | 7 | ```bash 8 | openssl genrsa -out rootCA.key 4096 9 | openssl req -x509 -new -nodes -sha512 -days 3650 \ 10 | -subj "/C=CN/ST=Shanghai/L=Shanghai/O=Monoio/OU=TLSDemo/CN=monoio-ca" \ 11 | -key rootCA.key \ 12 | -out rootCA.crt 13 | 14 | openssl genrsa -out server.key 4096 15 | openssl req -sha512 -new \ 16 | -subj "/C=CN/ST=Shanghai/L=Shanghai/O=Monoio/OU=TLSDemoServer/CN=monoio.rs" \ 17 | -key server.key \ 18 | -out server.csr 19 | 20 | cat > v3.ext <<-EOF 21 | authorityKeyIdentifier=keyid,issuer 22 | basicConstraints=CA:FALSE 23 | keyUsage=digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment 24 | extendedKeyUsage=serverAuth 25 | subjectAltName=@alt_names 26 | 27 | [alt_names] 28 | DNS.1=monoio.rs 29 | EOF 30 | 31 | openssl x509 -req -sha512 -days 3650 \ 32 | -extfile v3.ext \ 33 | -CA rootCA.crt -CAkey rootCA.key -CAcreateserial \ 34 | -in server.csr \ 35 | -out server.crt 36 | ``` -------------------------------------------------------------------------------- /monoio-gateway-core/src/dns/tcp.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fmt::Display, 3 | future::Future, 4 | net::{SocketAddr, ToSocketAddrs}, 5 | option, 6 | }; 7 | 8 | use serde::{Deserialize, Serialize}; 9 | 10 | use super::Resolvable; 11 | 12 | #[derive(Copy, Clone, Deserialize, Serialize, PartialEq, Eq, Hash)] 13 | pub struct TcpAddress { 14 | inner: SocketAddr, 15 | } 16 | 17 | impl TcpAddress { 18 | pub fn new(s: SocketAddr) -> Self { 19 | Self { inner: s } 20 | } 21 | } 22 | 23 | impl Resolvable for TcpAddress { 24 | type Error = anyhow::Error; 25 | 26 | type ResolveFuture<'a> = impl Future, Self::Error>> + 'a; 27 | 28 | type Address = SocketAddr; 29 | 30 | fn resolve(&self) -> Self::ResolveFuture<'_> { 31 | async { Ok(Some(self.inner.clone())) } 32 | } 33 | } 34 | 35 | // impl Resolvable for SocketAddr {} 36 | impl Display for TcpAddress { 37 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 38 | writeln!(f, "{}", self.inner) 39 | } 40 | } 41 | 42 | impl ToSocketAddrs for TcpAddress { 43 | type Iter = option::IntoIter; 44 | 45 | fn to_socket_addrs(&self) -> std::io::Result { 46 | self.inner.to_socket_addrs() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/discover.rs: -------------------------------------------------------------------------------- 1 | use std::{future::Future, time::Duration}; 2 | 3 | use monoio_gateway_core::{ 4 | discover::{change::DiscoverChange, Discover}, 5 | service::Service, 6 | }; 7 | 8 | #[derive(Clone)] 9 | pub struct DiscoverService { 10 | discover: D, 11 | delay: Duration, 12 | } 13 | 14 | impl Service<()> for DiscoverService 15 | where 16 | D: Discover + Clone, 17 | { 18 | type Response = DiscoverChange; 19 | 20 | type Error = D::Error; 21 | 22 | type Future<'cx> = impl Future> + 'cx 23 | where 24 | Self: 'cx; 25 | 26 | fn call(&mut self, _req: ()) -> Self::Future<'_> { 27 | async { 28 | let _ = monoio::time::sleep(self.delay).await; 29 | let res = self.discover.discover().await; 30 | match res { 31 | Ok(Some(change)) => { 32 | return Ok(change); 33 | } 34 | Ok(None) => { 35 | log::info!("no endpoint discovered"); 36 | return Ok(DiscoverChange::None); 37 | } 38 | Err(err) => { 39 | return Err(err); 40 | } 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/acme.rs: -------------------------------------------------------------------------------- 1 | use monoio_gateway::{ 2 | gateway::{Gateway, Gatewayable, Servable}, 3 | init_env, 4 | }; 5 | use monoio_gateway_core::{ 6 | dns::http::Domain, 7 | error::GError, 8 | http::router::{Router, RouterConfig, RouterRule, RoutersConfig, TlsConfig}, 9 | Builder, 10 | }; 11 | 12 | #[monoio::main(timer_enabled = true)] 13 | async fn main() -> Result<(), GError> { 14 | init_env(); 15 | let server_name = "monoio-gateway.kingtous.cn"; 16 | let mail = "me@kingtous.cn"; 17 | // http handler for compatiblity 18 | let server_config = RouterConfig { 19 | server_name: server_name.to_string(), 20 | listen_port: vec![80, 443], 21 | rules: vec![RouterRule { 22 | path: "/".to_string(), 23 | proxy_pass: Domain::with_uri("https://cv.kingtous.cn".parse().unwrap()), 24 | }], 25 | tls: Some(TlsConfig { 26 | mail: mail.to_string(), 27 | // None to use prebuilt acme support 28 | chain: None, 29 | private_key: None, 30 | }), 31 | }; 32 | let conf = RoutersConfig { 33 | configs: vec![server_config], 34 | }; 35 | let router = Router::build_with_config(conf); 36 | let gws = Gateway::from_router(router); 37 | let _ = gws.serve().await; 38 | Ok(()) 39 | } 40 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/accept.rs: -------------------------------------------------------------------------------- 1 | use std::{future::Future, net::SocketAddr, rc::Rc}; 2 | 3 | use anyhow::bail; 4 | use log::info; 5 | use monoio::net::{TcpListener, TcpStream}; 6 | use monoio_gateway_core::{ 7 | error::GError, 8 | service::{Layer, Service}, 9 | }; 10 | 11 | #[derive(Default, Clone)] 12 | pub struct TcpAcceptService; 13 | 14 | pub type Accept = (S, SocketAddr); 15 | 16 | impl Service> for TcpAcceptService { 17 | type Response = Accept; 18 | 19 | type Error = GError; 20 | 21 | type Future<'cx> = impl Future> 22 | where 23 | Self: 'cx; 24 | 25 | fn call(&mut self, listener: Rc) -> Self::Future<'_> { 26 | async move { 27 | match listener.accept().await { 28 | Ok(accept) => { 29 | info!("accept a connection"); 30 | return Ok(accept); 31 | } 32 | Err(err) => bail!("{}", err), 33 | } 34 | } 35 | } 36 | } 37 | 38 | #[derive(Default)] 39 | pub struct TcpAcceptLayer {} 40 | 41 | impl Layer for TcpAcceptLayer { 42 | type Service = TcpAcceptService; 43 | 44 | fn layer(&self, _service: S) -> Self::Service { 45 | TcpAcceptService {} 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/delay.rs: -------------------------------------------------------------------------------- 1 | use std::{future::Future, time::Duration}; 2 | 3 | use log::info; 4 | use monoio_gateway_core::service::{Layer, Service}; 5 | 6 | #[derive(Clone)] 7 | pub struct DelayService { 8 | inner: T, 9 | delay: Duration, 10 | } 11 | 12 | impl Service for DelayService 13 | where 14 | T: Service, 15 | R: 'static, 16 | { 17 | type Response = T::Response; 18 | 19 | type Error = T::Error; 20 | 21 | type Future<'cx> = impl Future> + 'cx 22 | where 23 | Self: 'cx; 24 | 25 | fn call(&mut self, req: R) -> Self::Future<'_> { 26 | async move { 27 | info!("lets delay for {}", self.delay.as_secs()); 28 | monoio::time::sleep(self.delay.to_owned()).await; 29 | let resp = self.inner.call(req).await; 30 | resp 31 | } 32 | } 33 | } 34 | 35 | pub struct DelayLayer { 36 | delay: Duration, 37 | } 38 | 39 | impl Layer for DelayLayer { 40 | type Service = DelayService; 41 | 42 | fn layer(&self, service: S) -> Self::Service { 43 | DelayService { 44 | inner: service, 45 | delay: self.delay, 46 | } 47 | } 48 | } 49 | 50 | impl DelayLayer { 51 | pub fn new(delay: Duration) -> Self { 52 | Self { delay } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/config.rs: -------------------------------------------------------------------------------- 1 | use std::vec; 2 | 3 | use monoio::net::ListenerConfig; 4 | 5 | #[derive(Clone)] 6 | pub struct Config { 7 | pub proxies: Vec>, 8 | } 9 | 10 | impl Config { 11 | pub fn new() -> Self { 12 | Self { proxies: vec![] } 13 | } 14 | 15 | pub fn push(mut self, proxy_config: ProxyConfig) -> Self { 16 | self.proxies.push(proxy_config); 17 | self 18 | } 19 | } 20 | 21 | #[derive(Clone)] 22 | pub struct ProxyConfig { 23 | pub inbound: InBoundConfig, 24 | pub outbound: OutBoundConfig, 25 | pub listener: ListenerConfig, 26 | } 27 | 28 | #[derive(Clone)] 29 | pub struct InBoundConfig { 30 | pub server: ServerConfig, 31 | } 32 | 33 | impl InBoundConfig { 34 | pub fn new(config: ServerConfig) -> Self { 35 | Self { server: config } 36 | } 37 | } 38 | 39 | #[derive(Clone)] 40 | pub struct OutBoundConfig { 41 | pub server: ServerConfig, 42 | } 43 | 44 | impl OutBoundConfig { 45 | pub fn new(config: ServerConfig) -> Self { 46 | Self { server: config } 47 | } 48 | } 49 | 50 | #[derive(Clone)] 51 | pub struct ServerConfig { 52 | pub addr: Addr, 53 | // TODO: max retries 54 | } 55 | 56 | impl ServerConfig { 57 | pub fn new(addr: Addr) -> Self { 58 | Self { addr } 59 | } 60 | } 61 | 62 | // traits start 63 | 64 | // traits ended 65 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/acme/mod.rs: -------------------------------------------------------------------------------- 1 | use std::{ffi::OsString, fmt::Display, fs::create_dir_all, future::Future, path::Path}; 2 | 3 | use log::info; 4 | 5 | use crate::{dns::http::Domain, error::GError, ACME_DIR}; 6 | 7 | mod acme; 8 | 9 | pub type GenericAcme = acme::GenericAcme; 10 | 11 | pub use acme::{start_acme, update_certificate}; 12 | 13 | /// ACME agent trait 14 | pub trait Acme { 15 | type Response; 16 | 17 | type Error: Display; 18 | 19 | type Future<'cx>: Future, Self::Error>> 20 | where 21 | Self: 'cx; 22 | 23 | fn acme(&self, acme_request: ()) -> Self::Future<'_>; 24 | } 25 | 26 | /// for those domain, to get acme path 27 | pub trait Acmed { 28 | fn get_acme_path(&self) -> Result; 29 | } 30 | 31 | pub(crate) fn get_acme_path(domain: &str) -> Result { 32 | let path = Path::new(&ACME_DIR.to_string()).join(Path::new(domain)); 33 | info!("acme path for {}: {:?}", domain, path); 34 | // ensure path exists 35 | create_dir_all(path.to_owned())?; 36 | Ok(path.into()) 37 | } 38 | 39 | impl Acmed for Domain { 40 | fn get_acme_path(&self) -> Result { 41 | get_acme_path(&self.host()) 42 | } 43 | } 44 | 45 | /// for convinient convert a server name to acme path 46 | impl Acmed for &str { 47 | fn get_acme_path(&self) -> Result { 48 | get_acme_path(self) 49 | } 50 | } 51 | 52 | impl Acmed for String { 53 | fn get_acme_path(&self) -> Result { 54 | get_acme_path(&self) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/http/rewrite.rs: -------------------------------------------------------------------------------- 1 | use http::HeaderValue; 2 | use monoio_http::{ 3 | common::{request::Request, response::Response}, 4 | h1::payload::Payload, 5 | }; 6 | 7 | use crate::dns::http::Domain; 8 | 9 | pub struct Rewrite; 10 | 11 | impl Rewrite { 12 | #[inline] 13 | pub fn rewrite_request(request: &mut Request, remote: &Domain) { 14 | let authority = remote.authority(); 15 | if authority.is_none() { 16 | // ignore rewrite 17 | return; 18 | } 19 | let new_header = HeaderValue::from_str(authority.unwrap().as_str()) 20 | .unwrap_or(HeaderValue::from_static("")); 21 | log::debug!( 22 | "Request: {:?} -> {:?}", 23 | request.headers().get(http::header::HOST), 24 | new_header 25 | ); 26 | request.headers_mut().insert(http::header::HOST, new_header); 27 | } 28 | 29 | #[inline] 30 | pub fn rewrite_response(response: &mut Response, local: &Domain) { 31 | let authority = local.authority(); 32 | if authority.is_none() || response.headers().get(http::header::HOST).is_none() { 33 | // ignore rewrite 34 | return; 35 | } 36 | let new_header = HeaderValue::from_str(authority.unwrap().as_str()) 37 | .unwrap_or(HeaderValue::from_static("")); 38 | log::debug!( 39 | "Response: {:?} <- {:?}", 40 | new_header, 41 | response.headers().get(http::header::HOST) 42 | ); 43 | response 44 | .headers_mut() 45 | .insert(http::header::HOST, new_header); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/service.rs: -------------------------------------------------------------------------------- 1 | use std::{fmt::Display, future::Future, iter::Enumerate}; 2 | 3 | use crate::util::{identity::Identity, stack::Stack}; 4 | 5 | pub trait Service: Clone { 6 | /// Responses given by the service. 7 | type Response; 8 | /// Errors produced by the service. 9 | type Error: Display; 10 | 11 | /// The future response value. 12 | type Future<'cx>: Future> 13 | where 14 | Self: 'cx; 15 | 16 | /// Process the request and return the response asynchronously. 17 | fn call(&mut self, req: Request) -> Self::Future<'_>; 18 | } 19 | 20 | pub trait Layer { 21 | type Service; 22 | 23 | fn layer(&self, service: S) -> Self::Service; 24 | } 25 | 26 | #[allow(dead_code)] 27 | pub struct SvcList 28 | where 29 | S: IntoIterator, 30 | { 31 | inner: Enumerate, 32 | } 33 | 34 | #[allow(dead_code)] 35 | type ListSvcList = SvcList>; 36 | 37 | pub struct ServiceBuilder { 38 | layer: L, 39 | } 40 | 41 | impl ServiceBuilder { 42 | pub fn new() -> Self { 43 | Self { 44 | layer: Identity::new(), 45 | } 46 | } 47 | } 48 | 49 | impl Default for ServiceBuilder { 50 | fn default() -> Self { 51 | Self::new() 52 | } 53 | } 54 | 55 | impl ServiceBuilder { 56 | pub fn layer(self, s: T) -> ServiceBuilder> { 57 | ServiceBuilder { 58 | layer: Stack::new(s, self.layer), 59 | } 60 | } 61 | 62 | pub fn service(&self, s: S) -> L::Service 63 | where 64 | L: Layer, 65 | { 66 | self.layer.layer(s) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/timeout.rs: -------------------------------------------------------------------------------- 1 | use std::{fmt::Display, future::Future, time::Duration}; 2 | 3 | use monoio_gateway_core::{ 4 | error::GError, 5 | service::{Layer, Service}, 6 | }; 7 | #[derive(Clone)] 8 | pub struct TimeoutService { 9 | inner: T, 10 | timeout: Duration, 11 | } 12 | 13 | impl Service for TimeoutService 14 | where 15 | T: Service, 16 | T::Error: Display, 17 | R: 'static, 18 | { 19 | type Response = Option; 20 | 21 | type Error = GError; 22 | 23 | type Future<'cx> = impl Future> + 'cx 24 | where 25 | Self: 'cx; 26 | 27 | fn call(&mut self, req: R) -> Self::Future<'_> { 28 | async { 29 | monoio::select! { 30 | _ = monoio::time::timeout(self.timeout, async {}) => { 31 | return Err(anyhow::anyhow!("timeout")) 32 | } 33 | 34 | ret = self.inner.call(req) => { 35 | return match ret { 36 | Ok(resp) => Ok(Some(resp)), 37 | Err(err) => Err(anyhow::anyhow!("{}", err)), 38 | } 39 | } 40 | } 41 | } 42 | } 43 | } 44 | 45 | pub struct TimeoutLayer { 46 | timeout: Duration, 47 | } 48 | 49 | impl Layer for TimeoutLayer { 50 | type Service = TimeoutService; 51 | 52 | fn layer(&self, service: S) -> Self::Service { 53 | TimeoutService { 54 | inner: service, 55 | timeout: self.timeout, 56 | } 57 | } 58 | } 59 | 60 | impl TimeoutLayer { 61 | pub fn new(timeout: Duration) -> Self { 62 | Self { timeout } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /examples/cert/server.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIEtTCCAp0CAQAwcDELMAkGA1UEBhMCQ04xETAPBgNVBAgMCFNoYW5naGFpMREw 3 | DwYDVQQHDAhTaGFuZ2hhaTEPMA0GA1UECgwGTW9ub2lvMRYwFAYDVQQLDA1UTFNE 4 | ZW1vU2VydmVyMRIwEAYDVQQDDAltb25vaW8ucnMwggIiMA0GCSqGSIb3DQEBAQUA 5 | A4ICDwAwggIKAoICAQDQg5NLGuO0TSW10C+FkykxmO99ixCNpbi89w5R37n2moe9 6 | gLGvCtF3lZNbBPix8qkdnEaxXhkDAi4Ry2xdA11gTDI7moWrNHcaxPk9nKtc/0dr 7 | BXnTtEFRrCbGtMCNbSHrie/WofOx77sVbe3NnKMKH9KqnhaxfutdOFaDNPgXuF3u 8 | cg3Biy7bNyQDd/7nq/gPEigUomE6Yi/MFh3onhTlV6Y89aQl3yLTTx4QxGSK69NU 9 | jPy9XDS4q0Kl8tYbFG7XeBt1lxLPVZzaCHwZt+wqnoTRnTt+heSCRH56sItuZ/yW 10 | yeeieceba9+dvKLrk5/ofIsHo5soltX+YQEL3dJJk2N1mOaLfy2Z0pIxtvmaByyy 11 | QsUcd0jfHnf8MUfsHhFoOba3iN/Vu3PV3ONeitlclV3oApegDybaNSm4UukYSqSI 12 | auz31V47SdTdU5LzBQmf8Zn++irfop4XfjBiQyZF/+m7sIVYkaN1V+yAEac2YSc7 13 | uDyRZ2A05mRcxCpMjV0ZStBQoDBTfSkc5s5RmTaOIvDE64zYBYoLZuGHbiHWGriv 14 | zpcebckGsChDOEKg7DfZhIx+bc40CMMP/eN7WJ3wApDZ1xHdMYv55ctWCTqfUd9P 15 | SBnk02kRjEDQHPgVMFV4TQG8lJ/6P++paJfQy87//yt+HBMdP88VAH0rI7oVpwID 16 | AQABoAAwDQYJKoZIhvcNAQENBQADggIBABygUqZSZ6zTHN2TxGJHq6spQfZtBh1y 17 | mfg1nhvpYdC3NqSm8Vw7IpTKr9iNCH+k9eR7/ThUC+1p7/l0blV/QzZNFNVf3ma5 18 | h0G3S/f94plmuFczKs09WCWPHrUNVjGncallnHkHihHgW7shu2G31dQ6df0UV4Ti 19 | CDcfb4P1CWAEdXH5c6z2EzuSI1S1az4NK2lVGwrFdPk6TmwIOjXS746PSWwLH4aF 20 | 1PKt3n8h4Q25vSu6f+ubnob8g5OVfkoUE2IuKaATqTqN1J0xCAS4IvVgTAivCTG2 21 | Lq5AFczJnxnZVI3tu7i/g5RExK/Adf3FeHWZCRKD3aHeDQBVgO5PqpRC28zlObN6 22 | Itf7xPJosu+H8VSDvfsBI/8oJBMkTCpjxdWkiTM8gF+OijA/gdk/1aJFpWFGWrWQ 23 | u6AZFoBbg4PBIOL11CXYzctql4RPfl1XS3A+XdmWM0kmOfkA+MzflCmStTxylE5F 24 | P96RTfoHeT7HZ+TSTSetA3BI0hkynhD8hnpv3gstsvmtV4ALg1UXytwwqmKmAZ1j 25 | nTkVHm7tdq+wbJjCur845Jvzh8Dcdz7oXy1ezKGk1n8VLoDqULYVbXXX8EEXl9nx 26 | 1VSUQM9H8oqazgy5QsSO5cGOSQt7HYKEF5C1sm4DwK1vVKpduBKRom8YIemwZoXR 27 | LKZ7Qdn1RxHH 28 | -----END CERTIFICATE REQUEST----- 29 | -------------------------------------------------------------------------------- /examples/cert/rootCA.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | 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 32 | 5FEh+FRqhfQ2V6UZ8Z/ny5c37yFi+Xe20A== 33 | -----END CERTIFICATE----- 34 | -------------------------------------------------------------------------------- /examples/cert/server.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | 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 33 | Yws= 34 | -----END CERTIFICATE----- 35 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/dns/http.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fmt::Display, 3 | future::Future, 4 | }; 5 | 6 | use http::{uri::Authority, Uri}; 7 | use serde::{Deserialize, Serialize}; 8 | 9 | use super::Resolvable; 10 | 11 | #[derive(Clone, Deserialize, Serialize, PartialEq, Eq, Hash)] 12 | pub struct Domain { 13 | #[serde(with = "http_serde::uri")] 14 | uri: Uri, 15 | } 16 | 17 | impl Domain { 18 | pub fn new(scheme: &str, authority: &str, path: &str) -> Self { 19 | Self { 20 | uri: Uri::builder() 21 | .scheme(scheme) 22 | .authority(authority) 23 | .path_and_query(path) 24 | .build() 25 | .unwrap(), 26 | } 27 | } 28 | 29 | pub fn with_uri(uri: Uri) -> Self { 30 | Self { uri } 31 | } 32 | 33 | pub fn version(&self) -> crate::http::version::Type { 34 | let v = self.uri.scheme_str().or_else(|| Some("http")).unwrap(); 35 | return if v == "https" { 36 | crate::http::version::Type::HTTPS 37 | } else { 38 | crate::http::version::Type::HTTP 39 | }; 40 | } 41 | 42 | pub fn port(&self) -> u16 { 43 | match self.version() { 44 | crate::http::version::Type::HTTP => self.uri.port_u16().or_else(|| Some(80)).unwrap(), 45 | crate::http::version::Type::HTTPS => self.uri.port_u16().or_else(|| Some(443)).unwrap(), 46 | } 47 | } 48 | 49 | pub fn authority(&self) -> Option<&Authority> { 50 | self.uri.authority() 51 | } 52 | 53 | #[inline] 54 | pub fn host(&self) -> &str { 55 | self.uri.authority().unwrap().host() 56 | } 57 | 58 | pub fn listen_addr(&self, wide: bool) -> String { 59 | if wide { 60 | format!("0.0.0.0:{}", self.port()) 61 | } else { 62 | format!("127.0.0.1:{}", self.port()) 63 | } 64 | } 65 | } 66 | 67 | impl Resolvable for Domain { 68 | type Error = anyhow::Error; 69 | 70 | type Address = String; 71 | 72 | type ResolveFuture<'a> = impl Future, Self::Error>> + 'a 73 | where 74 | Self: 'a; 75 | 76 | fn resolve(&self) -> Self::ResolveFuture<'_> { 77 | async { Ok(Some(format!("{}:{}", self.host(), self.port()))) } 78 | } 79 | } 80 | 81 | impl Display for Domain { 82 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 83 | write!(f, "{}", self.uri) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/listen.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | 3 | use anyhow::bail; 4 | use log::info; 5 | use monoio::net::{ListenerConfig, TcpListener}; 6 | use monoio_gateway_core::{ 7 | error::GError, 8 | service::{Layer, Service}, 9 | }; 10 | #[derive(Clone)] 11 | pub struct TcpListenService { 12 | inner: T, 13 | listen_port: u16, 14 | allow_lan: bool, 15 | listener_config: ListenerConfig, 16 | } 17 | 18 | impl Service<()> for TcpListenService 19 | where 20 | T: Service, 21 | { 22 | type Response = T::Response; 23 | 24 | type Error = GError; 25 | 26 | type Future<'cx> = impl Future> + 'cx 27 | where 28 | Self: 'cx; 29 | 30 | fn call(&mut self, _: ()) -> Self::Future<'_> { 31 | async { 32 | info!("binding port: {}", self.listen_port); 33 | let listen_addr = if self.allow_lan { 34 | format!("0.0.0.0:{}", self.listen_port) 35 | } else { 36 | format!("127.0.0.1:{}", self.listen_port) 37 | }; 38 | let listener = TcpListener::bind_with_config(listen_addr, &self.listener_config) 39 | .expect("err bind address"); 40 | // call listener 41 | match self.inner.call(listener).await { 42 | Ok(resp) => Ok(resp), 43 | Err(e) => bail!("{}", e), 44 | } 45 | } 46 | } 47 | } 48 | 49 | #[derive(Default)] 50 | pub struct TcpListenLayer { 51 | listen_port: u16, 52 | allow_lan: bool, 53 | listener_config: ListenerConfig, 54 | } 55 | 56 | impl TcpListenLayer { 57 | pub fn new(listen_port: u16, allow_lan: bool) -> Self { 58 | TcpListenLayer { 59 | listen_port, 60 | allow_lan, 61 | ..Default::default() 62 | } 63 | } 64 | 65 | pub fn new_allow_lan(listen_port: u16) -> Self { 66 | TcpListenLayer { 67 | listen_port, 68 | allow_lan: true, 69 | ..Default::default() 70 | } 71 | } 72 | } 73 | 74 | impl Layer for TcpListenLayer { 75 | type Service = TcpListenService; 76 | 77 | fn layer(&self, service: S) -> Self::Service { 78 | TcpListenService { 79 | inner: service, 80 | allow_lan: self.allow_lan, 81 | listener_config: self.listener_config.clone(), 82 | listen_port: self.listen_port, 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/detect.rs: -------------------------------------------------------------------------------- 1 | use std::{future::Future, io::Cursor, net::SocketAddr}; 2 | 3 | use log::info; 4 | use monoio::io::{AsyncReadRent, AsyncWriteRent, PrefixedReadIo, Split}; 5 | use monoio_gateway_core::{error::GError, http::version::Type, service::Service}; 6 | 7 | use super::accept::Accept; 8 | 9 | const SSL_RECORD_TYPE: u8 = 22; 10 | const SSL: u8 = 0x03; 11 | 12 | #[derive(Clone)] 13 | pub struct DetectService; 14 | 15 | pub type DetectResult = (Type, Stream, SocketAddr); 16 | 17 | pub struct DetectResponse { 18 | pub pio: PrefixedReadIo, 19 | } 20 | 21 | impl Service> for DetectService 22 | where 23 | S: Split + AsyncReadRent + AsyncWriteRent, 24 | { 25 | type Response = Option>>>>; 26 | 27 | type Error = GError; 28 | 29 | type Future<'cx> = impl Future> where Self: 'cx; 30 | 31 | fn call(&mut self, acc: Accept) -> Self::Future<'_> { 32 | // let detect = self.detect.clone(); 33 | // Byte 0 = SSL record type 34 | // Bytes 1-2 = SSL version (major/minor) 35 | // Bytes 3-4 = Length of data in the record (excluding the header itself). 36 | // The maximum SSL supports is 16384 (16K). 37 | // we use first 3 bytes to read 38 | let buf = vec![0 as u8; 3]; 39 | async move { 40 | info!("detecting client protocol"); 41 | let (mut tcp, socketaddr) = acc; 42 | let (sz, buf) = tcp.read(buf).await; 43 | // for lint 44 | let buf: Vec = buf; 45 | let sz = sz?; 46 | if sz < 3 { 47 | return Ok(None); 48 | } 49 | let ssl_record_type: u8 = buf[0]; 50 | let ssl_version_b1: u8 = buf[1]; 51 | let _ssl_version_b2: u8 = buf[2]; 52 | let reader = Cursor::new(buf); 53 | let pio = PrefixedReadIo::new(tcp, reader); 54 | // 22 -> SSL 55 | if ssl_record_type != SSL_RECORD_TYPE { 56 | return Ok(Some((Type::HTTP, pio, socketaddr))); 57 | } 58 | if ssl_version_b1 != SSL { 59 | return Ok(Some((Type::HTTP, pio, socketaddr))); 60 | } 61 | Ok(Some((Type::HTTPS, pio, socketaddr))) 62 | } 63 | } 64 | } 65 | 66 | impl DetectService { 67 | pub fn new_http_detect() -> Self { 68 | Self 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![feature(type_alias_impl_trait)] 2 | 3 | #[cfg(feature = "acme")] 4 | pub mod acme; 5 | pub mod balance; 6 | pub mod config; 7 | pub mod discover; 8 | pub mod dns; 9 | pub mod error; 10 | pub mod http; 11 | pub mod service; 12 | pub mod transfer; 13 | pub mod util; 14 | 15 | use std::{ 16 | collections::HashMap, 17 | num::NonZeroUsize, 18 | sync::{Arc, RwLock}, 19 | }; 20 | 21 | use figlet_rs::FIGfont; 22 | 23 | #[cfg(feature = "acme")] 24 | use lazy_static::lazy_static; 25 | use rustls::{OwnedTrustAnchor, RootCertStore}; 26 | 27 | use crate::{dns::http::Domain, http::ssl::CertificateResolver}; 28 | 29 | pub const MAX_CONFIG_SIZE_LIMIT: usize = 8072; 30 | pub const MAX_IOURING_ENTRIES: u32 = 32768; 31 | pub const ACME_URI_PREFIX: &str = "/.well-known"; 32 | 33 | #[cfg(feature = "acme")] 34 | lazy_static! { 35 | /// editable acme dir 36 | pub static ref ACME_DIR: String = String::from("/var/monoio-gateway/acme"); 37 | /// ssl 38 | pub static ref CERTIFICATE_MAP: Arc>>> = Arc::new(RwLock::new(HashMap::new())); 39 | pub static ref CERTIFICATE_RESOLVER: Arc = Arc::new(CertificateResolver::new()); 40 | pub static ref DEFAULT_SSL_CLIENT_CONFIG: Arc = { 41 | let mut root_store = RootCertStore::empty(); 42 | root_store.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| { 43 | OwnedTrustAnchor::from_subject_spki_name_constraints( 44 | ta.subject, 45 | ta.spki, 46 | ta.name_constraints, 47 | ) 48 | })); 49 | let config = rustls::ClientConfig::builder() 50 | .with_safe_defaults() 51 | .with_root_certificates(root_store) 52 | .with_no_client_auth(); 53 | Arc::new(config) 54 | }; 55 | } 56 | 57 | lazy_static! { 58 | /// Service Discover 59 | /// 60 | /// Note: 61 | /// A thread-shared map 62 | pub static ref DISCOVERED: Arc>> = Arc::new(RwLock::new(HashMap::new())); 63 | } 64 | 65 | pub trait Builder { 66 | fn build_with_config(config: Config) -> Self; 67 | } 68 | 69 | pub fn print_logo() { 70 | let standard_font = FIGfont::standand().unwrap(); 71 | if let Some(figure) = standard_font.convert("Monoio Gateway") { 72 | println!("{}", figure); 73 | } 74 | } 75 | 76 | pub fn max_parallel_count() -> NonZeroUsize { 77 | std::thread::available_parallelism().unwrap_or(unsafe { NonZeroUsize::new_unchecked(1) }) 78 | } 79 | -------------------------------------------------------------------------------- /monoio-gateway/src/main.rs: -------------------------------------------------------------------------------- 1 | #![feature(type_alias_impl_trait)] 2 | 3 | use std::thread; 4 | 5 | use anyhow::{bail, Result}; 6 | use clap::Parser; 7 | 8 | use log::info; 9 | use monoio::RuntimeBuilder; 10 | use monoio_gateway::{ 11 | gateway::{Gateway, Gatewayable, Servable}, 12 | init_env, 13 | }; 14 | use monoio_gateway_core::{ 15 | dns::{http::Domain, Resolvable}, 16 | error::GError, 17 | http::router::{Router, RouterConfig, RoutersConfig}, 18 | max_parallel_count, print_logo, Builder, MAX_IOURING_ENTRIES, 19 | }; 20 | 21 | use serde::de::DeserializeOwned; 22 | 23 | pub mod gateway; 24 | pub mod proxy; 25 | 26 | #[derive(Parser, Debug)] 27 | #[clap(author, version, about, long_about = None)] 28 | struct Args { 29 | /// Path of the config file 30 | #[clap(short, long, value_parser)] 31 | config: String, 32 | } 33 | 34 | #[monoio::main(timer_enabled = true)] 35 | async fn main() -> Result<()> { 36 | print_logo(); 37 | init_env(); 38 | let args = Args::parse(); 39 | // read config from file 40 | let configs = load_runtime::(&args).await?; 41 | // build runtime 42 | let router = Router::build_with_config(configs); 43 | // start service 44 | let gws = Gateway::from_router(router); 45 | serve_gateway(gws); 46 | Ok(()) 47 | } 48 | 49 | async fn load_runtime(config: &Args) -> Result, GError> 50 | where 51 | A: Resolvable + DeserializeOwned, 52 | { 53 | let path = config.config.to_owned(); 54 | match RouterConfig::::read_from_file(path).await { 55 | Ok(confs) => Ok(confs), 56 | Err(err) => { 57 | log::error!("{}", err); 58 | bail!("{}", err); 59 | } 60 | } 61 | } 62 | 63 | /// Serve Monoio-Gateway with maximum parallel count 64 | fn serve_gateway(gws: Vec>) 65 | where 66 | A: Resolvable + Send + 'static, 67 | Gateway: Gatewayable, 68 | { 69 | let mut handlers = vec![]; 70 | let parallel_cnt = max_parallel_count().get(); 71 | info!( 72 | "🚀 boost monoio-gateway with maximum {} worker(s).", 73 | parallel_cnt 74 | ); 75 | for _ in 0..parallel_cnt { 76 | let local_gws = gws.clone(); 77 | let handler = thread::spawn(move || { 78 | let mut rt = RuntimeBuilder::::new() 79 | .enable_timer() 80 | .with_entries(MAX_IOURING_ENTRIES) 81 | .build() 82 | .unwrap(); 83 | rt.block_on(async move { 84 | match local_gws.serve().await { 85 | Ok(_) => {} 86 | Err(err) => { 87 | log::error!("Gateway Error: {}", err); 88 | } 89 | } 90 | }); 91 | }); 92 | handlers.push(handler); 93 | } 94 | for handler in handlers.into_iter() { 95 | let _ = handler.join(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/http/ssl.rs: -------------------------------------------------------------------------------- 1 | use std::{fmt::Debug, fs::File, io::BufReader, path::Path}; 2 | 3 | use anyhow::bail; 4 | use monoio_rustls::TlsConnector; 5 | use rustls::server::ResolvesServerCert; 6 | 7 | use crate::{error::GError, CERTIFICATE_MAP, DEFAULT_SSL_CLIENT_CONFIG}; 8 | 9 | #[derive(Default)] 10 | pub struct CertificateResolver; 11 | 12 | impl CertificateResolver { 13 | pub fn new() -> Self { 14 | CertificateResolver::default() 15 | } 16 | } 17 | 18 | /// Certificate of Monoio Gateway 19 | /// (pem_file, private key) 20 | pub type GatewayCertificate = (Vec, Vec); 21 | 22 | impl ResolvesServerCert for CertificateResolver { 23 | fn resolve( 24 | &self, 25 | client_hello: rustls::server::ClientHello, 26 | ) -> Option> { 27 | match client_hello.server_name() { 28 | Some(server_name) => { 29 | let map = CERTIFICATE_MAP.read().unwrap(); 30 | let item = map.get(server_name); 31 | match item { 32 | Some(item) => Some(item.to_owned()), 33 | None => None, 34 | } 35 | } 36 | None => None, 37 | } 38 | } 39 | } 40 | 41 | pub fn read_pem_chain_file(path: impl AsRef + Debug + Clone) -> Result>, GError> { 42 | let f = File::open(path.clone())?; 43 | let mut reader = BufReader::new(f); 44 | let pems = rustls_pemfile::certs(&mut reader)?; 45 | Ok(pems) 46 | } 47 | 48 | pub fn read_pem_chain(read: R) -> Result>, GError> 49 | where 50 | R: std::io::Read, 51 | { 52 | let mut reader = BufReader::new(read); 53 | let pems = rustls_pemfile::certs(&mut reader)?; 54 | log::info!("read pem chain length: {}", pems.len()); 55 | Ok(pems) 56 | } 57 | 58 | /// read only one pem 59 | pub fn read_pem_file(path: impl AsRef + Debug + Clone) -> Result, GError> { 60 | let f = File::open(path.clone())?; 61 | read_pem_certificate(f) 62 | } 63 | 64 | pub fn read_pem_certificate(read: R) -> Result, GError> 65 | where 66 | R: std::io::Read, 67 | { 68 | let mut reader = BufReader::new(read); 69 | let mut pems = rustls_pemfile::certs(&mut reader)?; 70 | match pems.pop() { 71 | Some(pem) => Ok(pem), 72 | None => bail!("pem file validate failed"), 73 | } 74 | } 75 | 76 | pub fn read_private_key_file(path: impl AsRef + Debug + Clone) -> Result, GError> { 77 | let f = File::open(path.clone())?; 78 | read_private_key(f) 79 | } 80 | 81 | pub fn read_private_key(read: R) -> Result, GError> 82 | where 83 | R: std::io::Read, 84 | { 85 | let mut reader = BufReader::new(read); 86 | let mut pems = rustls_pemfile::pkcs8_private_keys(&mut reader)?; 87 | if pems.is_empty() { 88 | bail!("no private key read"); 89 | } 90 | match pems.pop() { 91 | Some(pem) => Ok(pem), 92 | None => bail!("private key validate failed"), 93 | } 94 | } 95 | 96 | #[inline] 97 | pub fn get_default_tls_connector() -> TlsConnector { 98 | TlsConnector::from(DEFAULT_SSL_CLIENT_CONFIG.clone()) 99 | } 100 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Monoio Gateway 2 | 3 | A high performance gateway based on [Monoio](http://github.com/bytedance/monoio). 4 | 5 | ## Installation 6 | 7 | ```shell 8 | # clone this repo 9 | git clone https://github.com/monoio-rs/monoio-gateway.git 10 | # change work dir to executable crate 11 | cd monoio-gateway/monoio-gateway 12 | # install gateway to system wide 13 | cargo install --path . 14 | ``` 15 | 16 | ## Basic Usage 17 | 18 | ```shell 19 | monoio-gateway --config path/to/config.json 20 | ``` 21 | 22 | ## Configuration 23 | 24 | The configuration of `monoio-gateway` is formed by a `json` file. 25 | 26 | ### Configuration Option 27 | 28 | #### Base 29 | 30 | | field | type | description | required | 31 | | ----------- | --------- | ------------------------------- | -------- | 32 | | server_name | String | server domain | true | 33 | | listen_port | [u16] | port to bind, usually [80, 443] | true | 34 | | rules | [Rules] | proxy pass rules | true | 35 | | tls | TlsConfig | configuration for tls or acme | false | 36 | 37 | #### Rules 38 | 39 | | field | type | description | required | 40 | | ---------- | ------ | ----------------------------- | -------- | 41 | | path | String | request path started with '/' | true | 42 | | proxy_pass | String | endpoint url | true | 43 | 44 | #### TlsConfig 45 | 46 | | field | type | description | required | 47 | | ----------- | ------ | --------------------------------------------------------------------- | -------- | 48 | | mail | String | email used to request SSL certificate(acme) | false | 49 | | chain | String | pem file chained with root ca and server cert | false | 50 | | private_key | String | `pkcs8` encoded private key(start with `-----BEGIN PRIVATE KEY-----`) | false | 51 | 52 | Note: If defined `TlsConfig`, which means the server can also be served as `https`. Users should ensure one of the following parameters exist in `TlsConfig`, or `monoio-gateway` will fail to start: 53 | 54 | - `mail` 55 | - if defined `mail`, the gateway will automatically request acme service (Let's Encrypt) to get a free certificate, download and deploy to runtime if there's no valid certificate. Users should ensure the corresponding dns record is pointed to current server. 56 | - `chain`, `private_key` 57 | - the gateway will use certificates provided in config file, disable acme service for this `server_name`. `mail` will be ignored and nullable. 58 | 59 | ### Example 60 | an example configuration is shown below. 61 | 62 | ```json 63 | { 64 | "configs": [ 65 | { 66 | "server_name": "gateway.monoio.rs", 67 | "listen_port": [80, 443], 68 | "rules": [ 69 | { 70 | "path": "/", 71 | "proxy_pass": { 72 | "uri": "https://www.google.com" 73 | } 74 | }, 75 | { 76 | "path": "/apple_captive", 77 | "proxy_pass": { 78 | "uri": "http://captive.apple.com" 79 | } 80 | } 81 | ], 82 | "tls": { 83 | "mail": "me@monoio.rs" 84 | } 85 | } 86 | ] 87 | } 88 | ``` 89 | 90 | -------------------------------------------------------------------------------- /examples/cert/rootCA.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | 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 51 | -----END RSA PRIVATE KEY----- 52 | -------------------------------------------------------------------------------- /examples/cert/server.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | 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 51 | -----END RSA PRIVATE KEY----- 52 | -------------------------------------------------------------------------------- /monoio-gateway/src/proxy/tcp.rs: -------------------------------------------------------------------------------- 1 | use std::{future::Future, net::SocketAddr, str::FromStr}; 2 | 3 | use monoio::{ 4 | io::Splitable, 5 | net::{ListenerConfig, TcpListener, TcpStream}, 6 | }; 7 | use monoio_gateway_core::{ 8 | dns::tcp::TcpAddress, error::GError, http::router::RouterConfig, transfer::copy_data, 9 | }; 10 | 11 | use super::Proxy; 12 | 13 | pub type TcpProxyConfig = RouterConfig; 14 | 15 | pub struct TcpProxy { 16 | config: TcpProxyConfig, 17 | listener_config: ListenerConfig, 18 | } 19 | 20 | impl Proxy for TcpProxy { 21 | type Error = anyhow::Error; 22 | type OutputFuture<'a> = impl Future> + 'a where Self: 'a; 23 | 24 | fn io_loop(&self) -> Self::OutputFuture<'_> { 25 | async { 26 | println!("starting a new tcp proxy"); 27 | // bind inbound port 28 | let local_addr = self.inbound_addr().await?; 29 | let peer_addr = self.outbound_addr().await?; 30 | let listener = TcpListener::bind_with_config(local_addr, &self.listener_config) 31 | .expect(&format!("cannot bind with address: {}", local_addr)); 32 | // start io loop 33 | loop { 34 | let accept = listener.accept().await; 35 | match accept { 36 | Ok((mut conn, _)) => { 37 | // async accept logic 38 | monoio::spawn(async move { 39 | let remote_conn = TcpStream::connect(peer_addr).await; 40 | match remote_conn { 41 | Ok(mut remote) => { 42 | let (mut local_read, mut local_write) = conn.split(); 43 | let (mut remote_read, mut remote_write) = remote.split(); 44 | let _ = monoio::join!( 45 | copy_data(&mut local_read, &mut remote_write), 46 | copy_data(&mut remote_read, &mut local_write) 47 | ); 48 | } 49 | Err(_) => { 50 | eprintln!("unable to connect addr: {}", peer_addr) 51 | } 52 | } 53 | }); 54 | } 55 | Err(_) => eprintln!("failed to accept connections."), 56 | } 57 | } 58 | } 59 | } 60 | } 61 | 62 | impl TcpProxy { 63 | pub fn build_with_config(config: &Vec) -> Self { 64 | assert!(config.len() == 1, "tcp proxy can only have one endpoint!"); 65 | Self { 66 | config: config.first().unwrap().to_owned(), 67 | listener_config: ListenerConfig::default(), 68 | } 69 | } 70 | 71 | #[inline] 72 | pub async fn inbound_addr(&self) -> Result { 73 | let addr = format!("0.0.0.0:{}", self.config.listen_port.first().unwrap()); 74 | Ok(TcpAddress::new( 75 | SocketAddr::from_str(&addr).expect(&format!("addr {} is not valid", addr)), 76 | )) 77 | } 78 | 79 | #[inline] 80 | pub async fn outbound_addr(&self) -> Result { 81 | Ok(self.config.rules.first().unwrap().proxy_pass) 82 | } 83 | 84 | pub fn configure(&mut self) {} 85 | } 86 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/http/router.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap, path::Path}; 2 | 3 | use anyhow::bail; 4 | use log::info; 5 | use monoio_http::ParamRef; 6 | use serde::de::DeserializeOwned; 7 | use serde_derive::{Deserialize, Serialize}; 8 | 9 | use crate::{dns::Resolvable, error::GError, Builder, MAX_CONFIG_SIZE_LIMIT}; 10 | 11 | type RouterMap = HashMap>>; 12 | 13 | #[derive(Clone, Serialize, Deserialize)] 14 | pub struct RoutersConfig { 15 | pub configs: Vec>, 16 | } 17 | 18 | #[derive(Clone, Serialize, Deserialize)] 19 | pub struct RouterConfig { 20 | pub server_name: String, 21 | pub listen_port: Vec, 22 | pub rules: Vec>, 23 | pub tls: Option, 24 | } 25 | 26 | #[derive(Clone, Serialize, Deserialize)] 27 | pub struct TlsConfig { 28 | pub mail: String, 29 | pub chain: Option, 30 | pub private_key: Option, 31 | } 32 | 33 | impl RouterConfig { 34 | pub fn get_rules(&self) -> &Vec> { 35 | &self.rules 36 | } 37 | } 38 | 39 | #[derive(Clone, Serialize, Deserialize)] 40 | pub struct RouterRule { 41 | pub path: String, 42 | pub proxy_pass: A, 43 | // TODO 44 | } 45 | 46 | impl RouterRule { 47 | pub fn get_path(&self) -> &String { 48 | &self.path 49 | } 50 | 51 | pub fn get_proxy_pass(&self) -> &A { 52 | &self.proxy_pass 53 | } 54 | } 55 | 56 | #[derive(Clone, Serialize, Deserialize)] 57 | pub struct Router { 58 | map: RouterMap, 59 | } 60 | 61 | impl Builder> for Router 62 | where 63 | A: Resolvable, 64 | { 65 | fn build_with_config(config: RoutersConfig) -> Self { 66 | let mut rule_map = RouterMap::new(); 67 | for conf in config.configs { 68 | info!("building {}", conf.server_name); 69 | for listen_port in conf.listen_port.iter() { 70 | if !rule_map.contains_key(listen_port) { 71 | rule_map.insert(*listen_port, vec![]); 72 | } 73 | let mut cloned = conf.clone(); 74 | cloned.listen_port = vec![*listen_port]; 75 | rule_map 76 | .entry(*listen_port) 77 | .and_modify(|conf_vec| conf_vec.push(cloned)); 78 | } 79 | } 80 | Self { map: rule_map } 81 | } 82 | } 83 | 84 | impl ParamRef> for Router { 85 | fn param_ref(&self) -> &RouterMap { 86 | &self.map 87 | } 88 | } 89 | 90 | impl<'cx, A> RouterConfig 91 | where 92 | A: Resolvable + DeserializeOwned, 93 | { 94 | pub async fn read_from_file(path: impl AsRef) -> Result, GError> { 95 | match monoio::fs::File::open(path).await { 96 | Ok(f) => { 97 | let buf = vec![0; MAX_CONFIG_SIZE_LIMIT]; 98 | let (sz, buf) = f.read_at(buf, 0).await; 99 | let len = sz?; 100 | info!("read {} bytes from config", len); 101 | let raw = &buf[..len]; 102 | let router_config = serde_json::from_slice::>(raw)?; 103 | info!("gateway count: {}", router_config.configs.len()); 104 | Ok(router_config) 105 | } 106 | Err(err) => bail!("Error open file: {}", err), 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/endpoint.rs: -------------------------------------------------------------------------------- 1 | use std::{cell::UnsafeCell, future::Future, rc::Rc}; 2 | 3 | use anyhow::bail; 4 | use log::info; 5 | use monoio::{ 6 | io::{AsyncWriteRent, OwnedReadHalf, OwnedWriteHalf, Splitable}, 7 | net::TcpStream, 8 | }; 9 | use monoio_gateway_core::{ 10 | dns::{http::Domain, Resolvable}, 11 | error::GError, 12 | http::ssl::get_default_tls_connector, 13 | service::Service, 14 | }; 15 | use monoio_http::h1::codec::{decoder::ResponseDecoder, encoder::GenericEncoder}; 16 | 17 | use rustls::ServerName; 18 | 19 | pub struct EndpointRequestParams { 20 | pub(crate) endpoint: EndPoint, 21 | } 22 | 23 | impl EndpointRequestParams { 24 | pub fn new(endpoint: Endpoint) -> Self { 25 | Self { endpoint } 26 | } 27 | } 28 | 29 | #[derive(Default, Clone)] 30 | pub struct ConnectEndpoint; 31 | 32 | pub enum ClientConnectionType { 33 | Http( 34 | Rc>>>, 35 | Rc>>>, 36 | ), 37 | Tls( 38 | Rc>>>, 39 | Rc>>>, 40 | ), 41 | } 42 | 43 | impl Service> for ConnectEndpoint { 44 | type Response = Option>; 45 | 46 | type Error = GError; 47 | 48 | type Future<'cx> = impl Future> 49 | where 50 | Self: 'cx; 51 | 52 | fn call(&mut self, req: EndpointRequestParams) -> Self::Future<'_> { 53 | async move { 54 | info!("trying to connect to endpoint"); 55 | let resolved = req.endpoint.resolve().await?; 56 | match resolved { 57 | Some(addr) => { 58 | info!("resolved addr: {}", addr); 59 | match TcpStream::connect(addr).await { 60 | Ok(stream) => match req.endpoint.version() { 61 | monoio_gateway_core::http::version::Type::HTTP => { 62 | // no need to handshake 63 | let (r, w) = stream.into_split(); 64 | return Ok(Some(ClientConnectionType::Http( 65 | Rc::new(UnsafeCell::new(ResponseDecoder::new(r))), 66 | Rc::new(UnsafeCell::new(GenericEncoder::new(w))), 67 | ))); 68 | } 69 | monoio_gateway_core::http::version::Type::HTTPS => { 70 | info!("establishing https connection to endpoint"); 71 | let tls_connector = get_default_tls_connector(); 72 | let server_name = 73 | ServerName::try_from(req.endpoint.host().as_ref())?; 74 | match tls_connector.connect(server_name, stream).await { 75 | Ok(endpoint_stream) => { 76 | let (r, w) = endpoint_stream.split(); 77 | return Ok(Some(ClientConnectionType::Tls( 78 | Rc::new(UnsafeCell::new(ResponseDecoder::new(r))), 79 | Rc::new(UnsafeCell::new(GenericEncoder::new(w))), 80 | ))); 81 | } 82 | Err(tls_error) => bail!("{}", tls_error), 83 | } 84 | } 85 | }, 86 | Err(err) => bail!("error connect endpoint: {}", err), 87 | } 88 | } 89 | _ => {} 90 | } 91 | Ok(None) 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /monoio-gateway/src/gateway.rs: -------------------------------------------------------------------------------- 1 | use std::future::Future; 2 | 3 | use log::info; 4 | 5 | use monoio_gateway_core::{ 6 | config::{Config, InBoundConfig, OutBoundConfig}, 7 | dns::{http::Domain, tcp::TcpAddress, Resolvable}, 8 | error::GError, 9 | http::router::{Router, RouterConfig}, 10 | }; 11 | use monoio_http::ParamRef; 12 | 13 | use crate::proxy::{h1::HttpProxy, tcp::TcpProxy, Proxy}; 14 | 15 | pub trait Gatewayable { 16 | type GatewayFuture<'cx>: Future> 17 | where 18 | Self: 'cx; 19 | 20 | fn new(config: Vec>) -> Self; 21 | 22 | fn from_router(router: Router) -> Vec>; 23 | 24 | fn serve(&self) -> Self::GatewayFuture<'_>; 25 | } 26 | 27 | #[derive(Clone)] 28 | pub struct Gateway { 29 | config: Vec>, 30 | } 31 | 32 | impl Gatewayable for Gateway { 33 | type GatewayFuture<'cx> = impl Future> + 'cx where Self: 'cx; 34 | 35 | fn new(config: Vec>) -> Self { 36 | Self { config } 37 | } 38 | 39 | fn serve(&self) -> Self::GatewayFuture<'_> { 40 | async move { 41 | let proxy = TcpProxy::build_with_config(&self.config); 42 | proxy.io_loop().await 43 | } 44 | } 45 | 46 | fn from_router(router: Router) -> Vec> 47 | where 48 | Self: Sized, 49 | { 50 | let m = router.param_ref(); 51 | info!("starting {} services", m.len()); 52 | let mut agent_vec = vec![]; 53 | for (port, v) in m { 54 | info!("port: {}, gateway payload count: {}", port, v.len()); 55 | let config_vec = v.clone(); 56 | agent_vec.push(Gateway::new(config_vec)); 57 | } 58 | agent_vec 59 | } 60 | } 61 | 62 | impl Gatewayable for Gateway { 63 | type GatewayFuture<'cx> = impl Future> + 'cx where Self: 'cx; 64 | 65 | fn new(config: Vec>) -> Self { 66 | Self { config } 67 | } 68 | 69 | fn serve<'cx>(&self) -> Self::GatewayFuture<'_> { 70 | async move { 71 | let proxy = HttpProxy::build_with_config(&self.config); 72 | proxy.io_loop().await?; 73 | Ok(()) 74 | } 75 | } 76 | 77 | fn from_router(router: Router) -> Vec> { 78 | let m = router.param_ref(); 79 | info!("starting {} services", m.len()); 80 | let mut agent_vec = vec![]; 81 | for (port, v) in m { 82 | info!("port: {}, gateway payload count: {}", port, v.len()); 83 | let config_vec = v.clone(); 84 | agent_vec.push(Gateway::new(config_vec)); 85 | } 86 | agent_vec 87 | } 88 | } 89 | 90 | pub type TcpInBoundConfig = InBoundConfig; 91 | pub type TcpOutBoundConfig = OutBoundConfig; 92 | 93 | pub type HttpInBoundConfig = InBoundConfig; 94 | pub type HttpOutBoundConfig = OutBoundConfig; 95 | 96 | pub type TcpConfig = Config; 97 | pub type HttpConfig = Config; 98 | 99 | pub trait Servable { 100 | type Future<'a>: Future> 101 | where 102 | Self: 'a; 103 | 104 | fn serve(&self) -> Self::Future<'_>; 105 | } 106 | 107 | impl Servable for Vec> 108 | where 109 | A: Resolvable + Send + 'static, 110 | Gateway: Gatewayable, 111 | { 112 | type Future<'a> = impl Future> + 'a 113 | where Self: 'a; 114 | 115 | fn serve(&self) -> Self::Future<'_> { 116 | async { 117 | let mut handler_vec = vec![]; 118 | for gw in self.iter() { 119 | let cloned = gw.clone(); 120 | let handler = monoio::spawn(async move { 121 | match cloned.serve().await { 122 | Ok(_) => {} 123 | Err(err) => { 124 | log::error!("Gateway Error: {}", err); 125 | } 126 | } 127 | }); 128 | handler_vec.push(handler); 129 | } 130 | // wait to exit 131 | for handle in handler_vec.into_iter() { 132 | let _ = handle.await; 133 | } 134 | Ok(()) 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/tls.rs: -------------------------------------------------------------------------------- 1 | use std::{future::Future, marker::PhantomData, net::SocketAddr}; 2 | 3 | use anyhow::bail; 4 | use log::info; 5 | use monoio::io::{AsyncReadRent, AsyncWriteRent, Split}; 6 | use monoio_gateway_core::{ 7 | error::GError, 8 | http::ssl::{read_pem_file, read_private_key_file}, 9 | service::{Layer, Service}, 10 | CERTIFICATE_RESOLVER, 11 | }; 12 | use monoio_rustls::{ServerTlsStream, TlsAcceptor}; 13 | use rustls::{Certificate, PrivateKey, ServerConfig}; 14 | 15 | use super::accept::Accept; 16 | 17 | pub type CertItem = (Vec, PrivateKey); 18 | pub type TlsAccept = (ServerTlsStream, SocketAddr, PhantomData); 19 | 20 | #[derive(Clone)] 21 | pub struct TlsService { 22 | // enable_client_auth: bool, 23 | // cert 24 | config: Option, 25 | inner: T, 26 | } 27 | 28 | /// Reserved TLS trait 29 | pub trait Tls { 30 | type Response<'cx>: Future> 31 | where 32 | Self: 'cx; 33 | 34 | fn get_server_certs(&self) -> Self::Response<'_>; 35 | } 36 | 37 | impl Service> for TlsService 38 | where 39 | T: Service>, 40 | S: Split + AsyncReadRent + AsyncWriteRent + 'static, 41 | { 42 | type Response = T::Response; 43 | 44 | type Error = GError; 45 | 46 | type Future<'cx> = impl Future> + 'cx 47 | where 48 | Self: 'cx; 49 | 50 | fn call(&mut self, accept: Accept) -> Self::Future<'_> { 51 | let tls_config = self.config.clone(); 52 | async move { 53 | info!("begin handshake"); 54 | let tls_acceptor: TlsAcceptor; 55 | match tls_config { 56 | Some(tls_config) => { 57 | tls_acceptor = TlsAcceptor::from(tls_config); 58 | } 59 | None => { 60 | // default acme cert 61 | let config = ServerConfig::builder() 62 | .with_safe_defaults() 63 | .with_no_client_auth() 64 | .with_cert_resolver(CERTIFICATE_RESOLVER.clone()); 65 | 66 | tls_acceptor = TlsAcceptor::from(config); 67 | } 68 | } 69 | match tls_acceptor.accept(accept.0).await { 70 | Ok(stream) => match self.inner.call((stream, accept.1, PhantomData)).await { 71 | Ok(resp) => Ok(resp), 72 | Err(err) => { 73 | bail!("{}", err) 74 | } 75 | }, 76 | Err(err) => bail!("tls error: {:?}", err), 77 | } 78 | } 79 | } 80 | } 81 | 82 | #[derive(Clone)] 83 | pub struct TlsLayer { 84 | enable_client_auth: bool, 85 | // cert 86 | config: Option, 87 | } 88 | 89 | impl TlsLayer { 90 | pub fn new_with_cert( 91 | ca_cert: String, 92 | crt_cert: String, 93 | private_key: String, 94 | ) -> Result { 95 | let ca = read_pem_file(ca_cert)?; 96 | let ca_cert = Certificate(ca); 97 | let crt = read_pem_file(crt_cert)?; 98 | let crt_cert = Certificate(crt); 99 | let private = read_private_key_file(private_key)?; 100 | let private_cert = PrivateKey(private); 101 | 102 | let config = ServerConfig::builder() 103 | .with_safe_defaults() 104 | .with_no_client_auth() 105 | .with_single_cert(vec![crt_cert, ca_cert], private_cert) 106 | .expect("invalid server ssl cert. Please check validity of cert provided."); 107 | Ok(Self { 108 | config: Some(config), 109 | enable_client_auth: false, 110 | }) 111 | } 112 | 113 | pub fn enable_client_auth(mut self, enable: bool) -> Self { 114 | self.enable_client_auth = enable; 115 | self 116 | } 117 | 118 | pub fn new() -> Self { 119 | Self { 120 | config: None, 121 | enable_client_auth: false, 122 | } 123 | } 124 | } 125 | 126 | impl Layer for TlsLayer { 127 | type Service = TlsService; 128 | 129 | fn layer(&self, service: S) -> Self::Service { 130 | TlsService { 131 | // enable_client_auth: self.enable_client_auth, 132 | config: self.config.clone(), 133 | inner: service, 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/transfer/mod.rs: -------------------------------------------------------------------------------- 1 | use std::{cell::UnsafeCell, rc::Rc}; 2 | 3 | use http::{header::HOST, StatusCode}; 4 | use monoio::{ 5 | io::{ 6 | sink::{Sink, SinkExt}, 7 | stream::Stream, 8 | AsyncReadRent, AsyncWriteRent, AsyncWriteRentExt, PrefixedReadIo, 9 | }, 10 | net::TcpStream, 11 | }; 12 | use monoio_http::{ 13 | common::{request::Request, response::Response, IntoParts}, 14 | h1::{ 15 | codec::decoder::{DecodeError, FillPayload}, 16 | payload::Payload, 17 | }, 18 | }; 19 | 20 | use crate::{dns::http::Domain, http::Rewrite}; 21 | 22 | pub type TcpPrefixedIo = PrefixedReadIo>; 23 | 24 | pub async fn copy_data( 25 | local: &mut Read, 26 | remote: &mut Write, 27 | ) -> Result, std::io::Error> { 28 | let mut buf = vec![0; 1024]; 29 | loop { 30 | let (res, read_buffer) = local.read(buf).await; 31 | buf = read_buffer; 32 | let read_len = res?; 33 | if read_len == 0 { 34 | // no 35 | return Ok(buf); 36 | } 37 | // write to remote 38 | let (res, write_buffer) = remote.write_all(buf).await; 39 | buf = write_buffer; 40 | let _ = res?; 41 | buf.clear(); 42 | } 43 | } 44 | 45 | pub async fn copy_stream_sink( 46 | local: &mut Read, 47 | remote: &mut Write, 48 | ) -> Result<(), std::io::Error> 49 | where 50 | Read: Stream> + FillPayload, 51 | Write: Sink, 52 | I: IntoParts + 'static, 53 | { 54 | loop { 55 | match local.next().await { 56 | Some(Ok(data)) => { 57 | log::debug!("sending data"); 58 | let _ = monoio::join!(local.fill_payload(), remote.send_and_flush(data)); 59 | log::debug!("data sent"); 60 | } 61 | Some(Err(decode_error)) => { 62 | log::warn!("DecodeError: {}", decode_error); 63 | } 64 | None => { 65 | log::info!("reached EOF, bye"); 66 | let _ = remote.close().await; 67 | break; 68 | } 69 | } 70 | } 71 | Ok(()) 72 | } 73 | 74 | pub async fn copy_request( 75 | local: &mut Read, 76 | remote: &mut Write, 77 | domain: &Domain, 78 | ) -> Result<(), std::io::Error> 79 | where 80 | Read: Stream, DecodeError>> + FillPayload, 81 | Write: Sink>, 82 | { 83 | loop { 84 | match local.next().await { 85 | Some(Ok(request)) => { 86 | let mut request: Request = request; 87 | Rewrite::rewrite_request(&mut request, domain); 88 | log::info!( 89 | "request: {}, host: {:?}", 90 | request.uri(), 91 | request.headers().get(HOST) 92 | ); 93 | let _ = monoio::join!(local.fill_payload(), remote.send_and_flush(request)); 94 | log::debug!("request sent"); 95 | } 96 | Some(Err(decode_error)) => { 97 | log::warn!("Decode Error: {}", decode_error); 98 | } 99 | None => { 100 | log::info!("forward reached EOF, bye"); 101 | let _ = remote.close().await; 102 | break; 103 | } 104 | } 105 | } 106 | Ok(()) 107 | } 108 | 109 | pub async fn copy_response( 110 | local: &mut Read, 111 | remote: &mut Write, 112 | domain: &Domain, 113 | ) -> Result<(), std::io::Error> 114 | where 115 | Read: Stream, DecodeError>> + FillPayload, 116 | Write: Sink>, 117 | { 118 | loop { 119 | match local.next().await { 120 | Some(Ok(response)) => { 121 | let mut response: Response = response; 122 | Rewrite::rewrite_response(&mut response, domain); 123 | log::info!( 124 | "response code: {},{:?}", 125 | response.status(), 126 | response.headers(), 127 | ); 128 | let _ = monoio::join!(local.fill_payload(), remote.send_and_flush(response)); 129 | } 130 | Some(Err(decode_error)) => { 131 | log::warn!("DecodeError: {}", decode_error); 132 | } 133 | None => { 134 | log::info!("backward reached EOF, bye"); 135 | let _ = remote.close().await; 136 | break; 137 | } 138 | } 139 | } 140 | Ok(()) 141 | } 142 | 143 | pub async fn copy_response_lock( 144 | local: Rc>, 145 | remote: Rc>, 146 | domain: Domain, 147 | ) -> Result<(), std::io::Error> 148 | where 149 | Read: Stream, DecodeError>> + FillPayload, 150 | Write: Sink>, 151 | { 152 | let local = unsafe { &mut *local.get() }; 153 | let remote = unsafe { &mut *remote.get() }; 154 | loop { 155 | match local.next().await { 156 | Some(Ok(response)) => { 157 | let mut response: Response = response; 158 | Rewrite::rewrite_response(&mut response, &domain); 159 | log::info!( 160 | "response code: {},{:?}", 161 | response.status(), 162 | response.headers(), 163 | ); 164 | let _ = monoio::join!(local.fill_payload(), remote.send_and_flush(response)); 165 | } 166 | Some(Err(decode_error)) => { 167 | log::warn!("DecodeError: {}", decode_error); 168 | break; 169 | } 170 | None => { 171 | log::info!("backward reached EOF, bye"); 172 | break; 173 | } 174 | } 175 | } 176 | let _ = remote.close().await; 177 | Ok(()) 178 | } 179 | 180 | pub fn generate_response(status_code: StatusCode) -> Response { 181 | let mut resp = Response::builder(); 182 | resp = resp.status(status_code); 183 | resp.body(Payload::None).unwrap() 184 | } 185 | -------------------------------------------------------------------------------- /monoio-gateway-core/src/acme/acme.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | future::Future, 3 | io::{Cursor, Write}, 4 | path::Path, 5 | sync::Arc, 6 | }; 7 | 8 | use acme_lib::{create_rsa_key, persist::FilePersist, Certificate, Directory, DirectoryUrl}; 9 | use anyhow::bail; 10 | use log::{debug, info}; 11 | use rustls::sign::CertifiedKey; 12 | 13 | use crate::{ 14 | acme::Acmed, 15 | error::GError, 16 | http::ssl::{read_pem_chain, read_private_key}, 17 | CERTIFICATE_MAP, 18 | }; 19 | 20 | use super::Acme; 21 | 22 | const LETSENCRYPT: &str = "https://acme-v02.api.letsencrypt.org/directory"; 23 | const LETSENCRYPT_STAGING: &str = "https://acme-staging-v02.api.letsencrypt.org/directory"; 24 | 25 | pub struct GenericAcme { 26 | domain: String, 27 | mail: String, 28 | validate_delay: u64, 29 | finalize_delay: u64, 30 | validate_retry_times: u8, 31 | 32 | request_url: String, 33 | } 34 | 35 | impl GenericAcme { 36 | pub fn new(domain: String, request_url: String, mail: String) -> Self { 37 | Self { 38 | domain, 39 | mail, 40 | validate_delay: 5000, 41 | finalize_delay: 10000, 42 | validate_retry_times: 5, 43 | 44 | request_url: request_url, 45 | } 46 | } 47 | 48 | pub fn new_lets_encrypt(domain: String, mail: String) -> Self { 49 | GenericAcme::new(domain, get_lets_encrypt_url(false).to_owned(), mail) 50 | } 51 | 52 | pub fn new_lets_encrypt_staging(domain: String, mail: String) -> Self { 53 | GenericAcme::new(domain, get_lets_encrypt_url(true).to_owned(), mail) 54 | } 55 | 56 | async fn write_proof(&self, token: &str, proof: String) -> Result<(), GError> { 57 | let path_str = Path::new(&self.domain.get_acme_path()?) 58 | .join(Path::new(&format!(".well-known/acme-challenge/{}", token))); 59 | info!("writing proof to {:?}", path_str); 60 | // create if not exist 61 | let path = Path::new(&path_str); 62 | let parent = path.parent().unwrap(); 63 | if !parent.exists() { 64 | std::fs::create_dir_all(parent.to_owned())?; 65 | } 66 | info!("creating challenge file {:?}", path_str); 67 | let mut out = std::fs::File::create(path)?; 68 | info!("writing challenge file {:?}", path_str); 69 | let _ = out.write_all(proof.as_bytes()); 70 | info!("proof wrote to {:?}", path_str); 71 | Ok(()) 72 | } 73 | } 74 | 75 | impl Acme for GenericAcme { 76 | type Response = Certificate; 77 | 78 | type Error = GError; 79 | 80 | type Future<'cx> = impl Future, Self::Error>> + 'cx 81 | where Self: 'cx; 82 | 83 | fn acme(&self, _: ()) -> Self::Future<'_> { 84 | async move { 85 | let url = DirectoryUrl::Other(&self.request_url); 86 | let persist = FilePersist::new(self.domain.get_acme_path()?); 87 | match Directory::from_url(persist, url) { 88 | Ok(directory) => { 89 | // create new order 90 | let acc = directory.account(&self.mail)?; 91 | let mut order = acc.new_order(&self.domain, &[])?; 92 | debug!("acme: created new order"); 93 | // try [curr_times] times 94 | let mut curr_times = 0; 95 | let ord_csr = loop { 96 | if curr_times > self.validate_retry_times { 97 | bail!("acme: failed after {} requests", self.validate_retry_times); 98 | } 99 | info!("try {} times for {}", curr_times, self.domain); 100 | if let Some(ord_csr) = order.confirm_validations() { 101 | break ord_csr; 102 | } 103 | // only one element per domain 104 | let auths = order.authorizations()?; 105 | let challenge = auths[0].http_challenge(); 106 | let (token, proof) = (challenge.http_token(), challenge.http_proof()); 107 | self.write_proof(token, proof).await?; 108 | challenge.validate(self.validate_delay)?; 109 | order.refresh()?; 110 | curr_times += 1; 111 | }; 112 | // validate success 113 | info!("🚀 acme validate success, downloading certificate"); 114 | let pkey_pri = create_rsa_key(3072); 115 | let ord_cert = ord_csr.finalize_pkey(pkey_pri, self.finalize_delay)?; 116 | let cert = ord_cert.download_and_save_cert()?; 117 | return Ok(Some(cert)); 118 | } 119 | Err(err) => { 120 | log::error!("get acme directory failed"); 121 | bail!("{}", err) 122 | } 123 | } 124 | } 125 | } 126 | } 127 | 128 | fn get_lets_encrypt_url(staging: bool) -> &'static str { 129 | if staging { 130 | LETSENCRYPT_STAGING 131 | } else { 132 | LETSENCRYPT 133 | } 134 | } 135 | 136 | /// This function is used to fetch Let's Encrypt Certificate from staging server 137 | pub async fn start_acme(server_name: String, mail: String) -> Result<(), GError> { 138 | let location = server_name.get_acme_path()?; 139 | let acme = GenericAcme::new_lets_encrypt(server_name.to_string(), mail.to_string()); 140 | match acme.acme(()).await { 141 | Ok(Some(cert)) => { 142 | // lint 143 | let cert: Certificate = cert; 144 | info!("private key: {}", cert.private_key()); 145 | update_certificate( 146 | server_name.to_owned(), 147 | Cursor::new(cert.certificate().as_bytes()), 148 | Cursor::new(cert.private_key().as_bytes()), 149 | ); 150 | info!("get cert, location: {:?}", location); 151 | // sync to disk 152 | save_cert_to_path(server_name, cert)?; 153 | } 154 | Err(err) => { 155 | bail!("{}", err) 156 | } 157 | _ => { 158 | // TODO: retry 159 | } 160 | } 161 | Ok(()) 162 | } 163 | 164 | /// update certificate to global certificate map 165 | pub fn update_certificate(server_name: String, chain: R, priv_key: R) 166 | where 167 | R: std::io::Read, 168 | { 169 | log::info!("updating ssl certificate for {}", server_name); 170 | let key = read_private_key(priv_key); 171 | let chain = read_pem_chain(chain); 172 | if let Err(e) = key { 173 | log::error!("private key of {} validate failed: {}", server_name, e); 174 | return; 175 | } 176 | let key = rustls::sign::any_supported_type(&rustls::PrivateKey(key.unwrap())); 177 | let mut certs = vec![]; 178 | if key.is_ok() && chain.is_ok() { 179 | let chain = chain.unwrap(); 180 | for cert in chain.into_iter() { 181 | let cert = rustls::Certificate(cert); 182 | certs.push(cert); 183 | } 184 | let certified_key = CertifiedKey::new(certs, key.unwrap()); 185 | CERTIFICATE_MAP 186 | .write() 187 | .unwrap() 188 | .insert(server_name, Arc::new(certified_key)); 189 | } else { 190 | log::warn!( 191 | "update ssl for {} failed. chain: {}, key: {}", 192 | server_name, 193 | chain.is_ok(), 194 | key.is_ok() 195 | ); 196 | } 197 | } 198 | 199 | /// save cert to disk 200 | fn save_cert_to_path(server_name: String, cert: Certificate) -> Result<(), GError> { 201 | let path = server_name.get_acme_path()?; 202 | let pem_file_path = Path::new(&path).join("pem"); 203 | let priv_file_path = Path::new(&path).join("priv"); 204 | let mut pem = std::fs::File::create(pem_file_path).unwrap(); 205 | let mut private = std::fs::File::create(priv_file_path).unwrap(); 206 | pem.write_all(cert.certificate().as_ref())?; 207 | private.write_all(cert.private_key().as_ref())?; 208 | info!( 209 | "🚀 acme cert for {} is last for {} days.", 210 | server_name, 211 | cert.valid_days_left() 212 | ); 213 | Ok(()) 214 | } 215 | -------------------------------------------------------------------------------- /monoio-gateway/src/proxy/h1.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | use std::future::Future; 3 | use std::io::{self, Cursor}; 4 | use std::path::Path; 5 | use std::rc::Rc; 6 | 7 | use std::thread; 8 | 9 | use anyhow::bail; 10 | use log::info; 11 | use monoio::net::{ListenerConfig, TcpListener}; 12 | use monoio_gateway_core::acme::{start_acme, update_certificate, Acmed}; 13 | use monoio_gateway_core::config::ProxyConfig; 14 | use monoio_gateway_core::dns::http::Domain; 15 | 16 | use monoio_gateway_core::error::GError; 17 | use monoio_gateway_core::http::router::RouterConfig; 18 | 19 | use monoio_gateway_core::service::{Service, ServiceBuilder}; 20 | 21 | use monoio_gateway_services::layer::accept::{Accept, TcpAcceptService}; 22 | use monoio_gateway_services::layer::detect::DetectService; 23 | use monoio_gateway_services::layer::router::RouterService; 24 | use monoio_gateway_services::layer::tls::TlsLayer; 25 | 26 | use super::Proxy; 27 | 28 | pub type HttpProxyConfig = ProxyConfig; 29 | 30 | pub struct HttpProxy { 31 | config: Vec>, 32 | } 33 | 34 | impl Proxy for HttpProxy { 35 | type Error = GError; 36 | type OutputFuture<'a> = impl Future> + 'a where Self: 'a; 37 | 38 | fn io_loop(&self) -> Self::OutputFuture<'_> { 39 | async { 40 | let mut route_map = HashMap::>::new(); 41 | for route in self.config.iter() { 42 | route_map.insert(route.server_name.to_owned(), route.to_owned()); 43 | } 44 | let route_wrapper = Rc::new(route_map); 45 | let listen_addr = format!("0.0.0.0:{}", self.get_listen_port().unwrap()); 46 | let listener = TcpListener::bind_with_config(listen_addr, &ListenerConfig::default()); 47 | if let Err(e) = listener { 48 | bail!("Error when binding address({})", e); 49 | } 50 | let listener = listener.unwrap(); 51 | let listener_wrapper = Rc::new(listener); 52 | let mut svc = ServiceBuilder::default().service(TcpAcceptService::default()); 53 | loop { 54 | log::info!( 55 | "📈 new accept avaliable for {:?}, waiting", 56 | self.get_listen_port() 57 | ); 58 | let route_cloned = route_wrapper.clone(); 59 | match svc.call(listener_wrapper.clone()).await { 60 | Ok(accept) => { 61 | monoio::spawn(async move { 62 | let mut detect = DetectService::new_http_detect(); 63 | match detect.call(accept).await { 64 | Ok(ty) => match ty { 65 | Some(detect) => { 66 | let (ty, stream, socketaddr) = detect; 67 | let handler = ServiceBuilder::default(); 68 | let acc = Accept::from((stream, socketaddr)); 69 | match ty { 70 | monoio_gateway_core::http::version::Type::HTTP => { 71 | info!("a http client detected"); 72 | let mut handler = handler 73 | .service(RouterService::new(route_cloned)); 74 | match handler.call(acc).await { 75 | Ok(_) => { 76 | info!("✔ complete connection"); 77 | } 78 | Err(e) => { 79 | log::error!("{}", e); 80 | } 81 | } 82 | } 83 | monoio_gateway_core::http::version::Type::HTTPS => { 84 | info!("a https client detected"); 85 | let mut handler = ServiceBuilder::new() 86 | .layer(TlsLayer::new()) 87 | .service(RouterService::new(route_cloned)); 88 | match handler.call(acc).await { 89 | Ok(_) => { 90 | info!("✔ complete connection"); 91 | } 92 | Err(e) => { 93 | log::error!("{}", e); 94 | } 95 | } 96 | } 97 | } 98 | } 99 | None => { 100 | log::info!("cannot detect http version"); 101 | } 102 | }, 103 | Err(err) => { 104 | log::error!("{}", err) 105 | } 106 | }; 107 | }); 108 | let _detect = DetectService::new_http_detect(); 109 | } 110 | Err(e) => { 111 | log::warn!("tcp accept failed: {}", e); 112 | } 113 | } 114 | } 115 | } 116 | } 117 | } 118 | 119 | impl HttpProxy { 120 | pub fn build_with_config(config: &Vec>) -> Self { 121 | configure_acme(config); 122 | Self { 123 | config: config.clone(), 124 | } 125 | } 126 | 127 | pub fn get_listen_port(&self) -> Option { 128 | match self.config.first() { 129 | Some(port) => Some(*port.listen_port.first().unwrap()), 130 | None => None, 131 | } 132 | } 133 | } 134 | 135 | /// acme support 136 | fn configure_acme(config: &Vec>) { 137 | // load local certificate 138 | for conf in config.iter() { 139 | if conf.listen_port.contains(&80) { 140 | continue; 141 | } 142 | info!("acme: load {}", conf.server_name); 143 | if let Some(tls) = &conf.tls { 144 | let pem_content: io::Result>; 145 | let key_content: io::Result>; 146 | if tls.private_key.is_some() && tls.chain.is_some() { 147 | // check config private key 148 | (pem_content, key_content) = ( 149 | std::fs::read(tls.chain.clone().unwrap()), 150 | std::fs::read(tls.private_key.clone().unwrap()), 151 | ); 152 | } else { 153 | // check local ssl 154 | let path = conf.server_name.get_acme_path().unwrap(); 155 | let (pem, key) = (Path::new(&path).join("pem"), Path::new(&path).join("priv")); 156 | (pem_content, key_content) = 157 | (std::fs::read(pem.clone()), std::fs::read(key.clone())); 158 | } 159 | 160 | if pem_content.is_ok() && key_content.is_ok() { 161 | info!( 162 | "🚀 ssl certificates for {} existed, let's load it.", 163 | conf.server_name 164 | ); 165 | let content = key_content.unwrap(); 166 | update_certificate( 167 | conf.server_name.to_owned(), 168 | Cursor::new(pem_content.unwrap()), 169 | Cursor::new(content), 170 | ); 171 | info!("🚀 ssl certificates for {} loaded.", conf.server_name); 172 | continue; 173 | } 174 | info!( 175 | "{} has no local ssl certificate, prepare requesting acme.", 176 | conf.server_name 177 | ); 178 | // prepare acme 179 | let server_name = conf.server_name.to_owned(); 180 | let mail = tls.mail.to_owned(); 181 | thread::spawn(move || { 182 | monoio::start::(async move { 183 | info!( 184 | "{} is requesting certificate using email {}", 185 | server_name, mail 186 | ); 187 | match start_acme(server_name, mail).await { 188 | Err(err) => { 189 | log::error!("requesting certificate failed: {}", err); 190 | } 191 | _ => {} 192 | }; 193 | }); 194 | }); 195 | } 196 | } 197 | } 198 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /monoio-gateway-services/src/layer/router.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | borrow::Borrow, cell::UnsafeCell, collections::HashMap, future::Future, path::Path, rc::Rc, 3 | }; 4 | 5 | use async_channel::Receiver; 6 | use bytes::Bytes; 7 | use http::{response::Builder, StatusCode}; 8 | use log::{debug, info}; 9 | use monoio::{ 10 | io::{ 11 | sink::{Sink, SinkExt}, 12 | stream::Stream, 13 | AsyncReadRent, AsyncWriteRent, Split, Splitable, 14 | }, 15 | net::TcpStream, 16 | }; 17 | use monoio_gateway_core::{ 18 | acme::Acmed, 19 | dns::{http::Domain, Resolvable}, 20 | error::GError, 21 | http::{ 22 | router::{RouterConfig, RouterRule}, 23 | Rewrite, 24 | }, 25 | service::Service, 26 | transfer::{copy_response_lock, generate_response}, 27 | ACME_URI_PREFIX, 28 | }; 29 | use monoio_http::{ 30 | common::{request::Request, response::Response}, 31 | h1::{ 32 | codec::{decoder::RequestDecoder, encoder::GenericEncoder}, 33 | payload::{FixedPayload, Payload}, 34 | }, 35 | }; 36 | 37 | use crate::layer::endpoint::ConnectEndpoint; 38 | 39 | use super::{ 40 | accept::Accept, 41 | endpoint::{ClientConnectionType, EndpointRequestParams}, 42 | tls::TlsAccept, 43 | }; 44 | 45 | pub type SharedTcpConnectPool = 46 | Rc>>>>; 47 | 48 | pub struct RouterService { 49 | routes: Rc>>, 50 | 51 | connect_pool: SharedTcpConnectPool, 52 | } 53 | 54 | impl Clone for RouterService 55 | where 56 | O: AsyncWriteRent, 57 | { 58 | fn clone(&self) -> Self { 59 | Self { 60 | routes: self.routes.clone(), 61 | connect_pool: self.connect_pool.clone(), 62 | } 63 | } 64 | } 65 | 66 | /// Direct use router before Accept 67 | impl Service> for RouterService 68 | where 69 | S: Split + AsyncReadRent + AsyncWriteRent + 'static, 70 | { 71 | type Response = (); 72 | 73 | type Error = GError; 74 | 75 | type Future<'a> = impl Future> + 'a 76 | where 77 | Self: 'a; 78 | 79 | fn call(&mut self, local_stream: Accept) -> Self::Future<'_> { 80 | async move { 81 | let (stream, socketaddr) = local_stream; 82 | let (local_read, local_write) = stream.into_split(); 83 | let mut local_decoder = RequestDecoder::new(local_read); 84 | let local_encoder = Rc::new(UnsafeCell::new(GenericEncoder::new(local_write))); 85 | let (tx, rx) = async_channel::bounded(1); 86 | loop { 87 | let connect_pool = self.connect_pool.clone(); 88 | match local_decoder.next().await { 89 | Some(Ok(req)) => { 90 | let req: Request = req; 91 | let host = get_host(&req); 92 | match host { 93 | Some(host) => { 94 | let domain = Domain::with_uri(host.parse()?); 95 | let target = self.match_target(&host.to_owned()); 96 | match target { 97 | Some(target) => { 98 | let m = longest_match(req.uri().path(), target.get_rules()); 99 | if let Some(rule) = m { 100 | // parsed rule for this request and spawn task to handle endpoint connection 101 | let proxy_pass = rule.get_proxy_pass().to_owned(); 102 | handle_endpoint_connection( 103 | connect_pool, 104 | &proxy_pass, 105 | local_encoder.clone(), 106 | req, 107 | rx.clone(), 108 | ) 109 | .await; 110 | continue; 111 | } else { 112 | // no match router rule, is acme? 113 | if let Ok(handled) = self 114 | .handle_acme_verification( 115 | req, 116 | target, 117 | local_encoder.clone(), 118 | ) 119 | .await 120 | { 121 | // no, is not acme, not find handler 122 | if handled { 123 | continue; 124 | } 125 | } 126 | debug!("no matching router rule, {}", domain); 127 | let local_encoder = 128 | unsafe { &mut *local_encoder.get() }; 129 | let _ = local_encoder.send_and_flush( 130 | generate_response(StatusCode::NOT_FOUND), 131 | ); 132 | } 133 | } 134 | None => { 135 | debug!("no matching endpoint, ignoring {}", domain); 136 | let local_encoder = unsafe { &mut *local_encoder.get() }; 137 | let _ = local_encoder.send_and_flush(generate_response( 138 | StatusCode::NOT_FOUND, 139 | )); 140 | } 141 | } 142 | } 143 | None => { 144 | debug!("request has no host, uri: {}", req.uri()); 145 | let local_encoder = unsafe { &mut *local_encoder.get() }; 146 | let _ = local_encoder 147 | .send_and_flush(generate_response(StatusCode::FORBIDDEN)); 148 | } 149 | }; 150 | } 151 | Some(Err(err)) => { 152 | // TODO: fallback to tcp 153 | log::warn!("{}", err); 154 | break; 155 | } 156 | None => { 157 | info!("http client {} closed", socketaddr); 158 | break; 159 | } 160 | } 161 | } 162 | // notify disconnect from endpoints 163 | rx.close(); 164 | let _ = tx.send(()).await; 165 | Ok(()) 166 | } 167 | } 168 | } 169 | 170 | /// Direct use router before Accept 171 | /// 172 | /// TODO: less copy code 173 | impl Service> for RouterService 174 | where 175 | S: Split + AsyncReadRent + AsyncWriteRent + 'static, 176 | { 177 | type Response = (); 178 | 179 | type Error = GError; 180 | 181 | type Future<'a> = impl Future> + 'a 182 | where 183 | Self: 'a; 184 | 185 | fn call(&mut self, local_stream: TlsAccept) -> Self::Future<'_> { 186 | async move { 187 | let (stream, socketaddr, _) = local_stream; 188 | let (local_read, local_write) = stream.split(); 189 | let mut local_decoder = RequestDecoder::new(local_read); 190 | let local_encoder = Rc::new(UnsafeCell::new(GenericEncoder::new(local_write))); 191 | // exit notifier 192 | let (tx, rx) = async_channel::bounded(1); 193 | loop { 194 | let connect_pool = self.connect_pool.clone(); 195 | match local_decoder.next().await { 196 | Some(Ok(req)) => { 197 | let req: Request = req; 198 | let host = get_host(&req); 199 | match host { 200 | Some(host) => { 201 | let domain = Domain::with_uri(host.parse()?); 202 | let target = self.match_target(&host.to_owned()); 203 | match target { 204 | Some(target) => { 205 | let m = longest_match(req.uri().path(), target.get_rules()); 206 | if let Some(rule) = m { 207 | // parsed rule for this request and spawn task to handle endpoint connection 208 | let proxy_pass = rule.get_proxy_pass().to_owned(); 209 | handle_endpoint_connection( 210 | connect_pool, 211 | &proxy_pass, 212 | local_encoder.clone(), 213 | req, 214 | rx.clone(), 215 | ) 216 | .await; 217 | continue; 218 | } else { 219 | // no match router rule, is acme? 220 | if let Ok(handled) = self 221 | .handle_acme_verification( 222 | req, 223 | target, 224 | local_encoder.clone(), 225 | ) 226 | .await 227 | { 228 | // no, is not acme, not find handler 229 | if handled { 230 | continue; 231 | } 232 | } 233 | debug!("no matching router rule, {}", domain); 234 | let local_encoder = 235 | unsafe { &mut *local_encoder.get() }; 236 | let _ = local_encoder.send_and_flush( 237 | generate_response(StatusCode::NOT_FOUND), 238 | ); 239 | } 240 | } 241 | None => { 242 | debug!("no matching endpoint, ignoring {}", domain); 243 | let local_encoder = unsafe { &mut *local_encoder.get() }; 244 | let _ = local_encoder.send_and_flush(generate_response( 245 | StatusCode::NOT_FOUND, 246 | )); 247 | } 248 | } 249 | } 250 | None => { 251 | debug!("request has no host, uri: {}", req.uri()); 252 | let local_encoder = unsafe { &mut *local_encoder.get() }; 253 | let _ = local_encoder 254 | .send_and_flush(generate_response(StatusCode::FORBIDDEN)); 255 | } 256 | }; 257 | } 258 | Some(Err(err)) => { 259 | log::warn!("{}", err); 260 | break; 261 | } 262 | None => { 263 | info!("https client {} closed", socketaddr); 264 | break; 265 | } 266 | } 267 | } 268 | log::info!("bye {}! Now we remove router", socketaddr); 269 | // notify disconnect from endpoints 270 | rx.close(); 271 | let _ = tx.send(()).await; 272 | Ok(()) 273 | } 274 | } 275 | } 276 | 277 | impl RouterService 278 | where 279 | A: Resolvable, 280 | O: AsyncWriteRent, 281 | { 282 | pub fn new(routes: Rc>>) -> Self { 283 | Self { 284 | routes, 285 | connect_pool: Default::default(), 286 | } 287 | } 288 | 289 | #[inline] 290 | fn match_target(&self, host: &String) -> Option<&RouterConfig> { 291 | self.routes.get(host) 292 | } 293 | 294 | /// if not handled, return false to continue handler 295 | async fn handle_acme_verification>( 296 | &self, 297 | req: Request, 298 | conf: &RouterConfig, 299 | encoder: Rc>, 300 | ) -> Result { 301 | let encoder = unsafe { &mut *encoder.get() }; 302 | let name = conf.server_name.get_acme_path()?; 303 | let p = Path::new(&name); 304 | match &conf.tls { 305 | Some(_) => { 306 | let req_path = req.uri().path().to_string(); 307 | log::info!("acme: request path: {}", req_path); 308 | if req_path.starts_with(ACME_URI_PREFIX) { 309 | // read files 310 | let abs_path = p.join(&req_path[1..]); 311 | log::info!("acme: read path: {:?}", abs_path); 312 | let mut file_bytes = vec![]; 313 | match monoio::fs::File::open(Path::new(&abs_path)).await { 314 | Ok(challenge_file) => { 315 | let mut pos = 0; 316 | loop { 317 | let buf = vec![0 as u8; 1024]; 318 | let (n, mut read) = challenge_file.read_at(buf, pos).await; 319 | let n = n? as u64; 320 | if n == 0 { 321 | // EOF, let's send our challenge now. 322 | break; 323 | } 324 | pos += n; 325 | unsafe { read.set_len(n as usize) }; 326 | file_bytes.append(&mut read); 327 | } 328 | let bytes = Bytes::from(file_bytes); 329 | let response = Builder::new() 330 | .body(Payload::Fixed(FixedPayload::new(bytes))) 331 | .unwrap(); 332 | let _ = encoder.send_and_flush(response).await; 333 | info!("acme challenge replied"); 334 | return Ok(true); 335 | } 336 | Err(e) => { 337 | log::warn!("find acme file error: {}", e); 338 | let data = Bytes::from_static(b"404 not found --- Monoio Gateway."); 339 | let response = Builder::new() 340 | .body(Payload::Fixed(FixedPayload::new(data))) 341 | .unwrap(); 342 | let _ = encoder.send_and_flush(response).await; 343 | } 344 | } 345 | } 346 | } 347 | _ => {} 348 | } 349 | Ok(false) 350 | } 351 | } 352 | 353 | #[inline] 354 | fn longest_match<'cx>( 355 | req_path: &'cx str, 356 | routes: &'cx Vec>, 357 | ) -> Option<&'cx RouterRule> { 358 | log::info!("request path: {}", req_path); 359 | // TODO: opt progress 360 | if req_path.starts_with(ACME_URI_PREFIX) { 361 | return None; 362 | } 363 | let mut target_route = None; 364 | let mut route_len = 0; 365 | for route in routes.iter() { 366 | let route_path = route.get_path(); 367 | let route_path_len = route_path.len(); 368 | if req_path.starts_with(route_path) && route_path_len > route_len { 369 | target_route = Some(route); 370 | route_len = route_path_len; 371 | } 372 | } 373 | target_route 374 | } 375 | 376 | #[inline] 377 | fn get_host(req: &Request) -> Option<&str> { 378 | match req.headers().get("host") { 379 | Some(host) => Some(host.to_str().unwrap_or("")), 380 | None => None, 381 | } 382 | } 383 | 384 | /// handle backward connections and send request to endpoint. 385 | /// This function use spawn feature of monoio and will not block caller. 386 | async fn handle_endpoint_connection( 387 | connect_pool: SharedTcpConnectPool, 388 | proxy_pass: &Domain, 389 | encoder: Rc>>, 390 | mut request: Request, 391 | rx: Receiver<()>, 392 | ) where 393 | O: AsyncWriteRent + 'static, 394 | GenericEncoder: monoio::io::sink::Sink>, 395 | { 396 | // we add a write lock to prevent multiple context execute into block below. 397 | { 398 | let connect_pool = unsafe { &mut *connect_pool.get() }; 399 | // critical code start 400 | if !connect_pool.contains_key(proxy_pass.host()) { 401 | // hold endpoint request, prevent 402 | log::info!( 403 | "{} endpoint connections not exists, try connect now. [{:?}]", 404 | proxy_pass.host(), 405 | connect_pool.keys() 406 | ); 407 | // open channel 408 | let proxy_pass_domain = proxy_pass.clone(); 409 | let local_encoder_clone = encoder.clone(); 410 | // no connections 411 | let mut connect_svc = ConnectEndpoint::default(); 412 | if let Ok(Some(conn)) = connect_svc 413 | .call(EndpointRequestParams { 414 | endpoint: proxy_pass.clone(), 415 | }) 416 | .await 417 | { 418 | let conn = Rc::new(conn); 419 | connect_pool.insert(proxy_pass_domain.host().to_owned(), conn.clone()); 420 | // endpoint -> proxy -> client 421 | let _connect_pool_cloned = connect_pool.clone(); 422 | let rx_clone = rx.clone(); 423 | monoio::spawn(async move { 424 | match conn.borrow() { 425 | ClientConnectionType::Http(i, _) => { 426 | let cloned = Rc::downgrade(&local_encoder_clone); 427 | monoio::select! { 428 | _ = copy_response_lock(i.clone(), local_encoder_clone, proxy_pass_domain.clone()) => {} 429 | _ = rx_clone.recv() => { 430 | log::info!("client exit, now cancelling endpoint connection"); 431 | if let Some(sender) = cloned.upgrade() { 432 | let sender = unsafe{&mut *sender.get()}; 433 | let _ = sender.close().await; 434 | } 435 | } 436 | }; 437 | } 438 | ClientConnectionType::Tls(i, _) => { 439 | let cloned = Rc::downgrade(&local_encoder_clone); 440 | monoio::select! { 441 | _ = copy_response_lock(i.clone(), local_encoder_clone, proxy_pass_domain.clone()) => {} 442 | _ = rx_clone.recv() => { 443 | log::info!("client exit, now cancelling endpoint connection"); 444 | if let Some(sender) = cloned.upgrade() { 445 | let sender = unsafe{&mut *sender.get()}; 446 | let _ = sender.close().await; 447 | } 448 | } 449 | }; 450 | } 451 | } 452 | // remove proxy pass endpoint 453 | connect_pool.remove(proxy_pass_domain.host()); 454 | log::info!("🗑 remove {} from endpoint pool", &proxy_pass_domain); 455 | }); 456 | } else { 457 | // connect endpoint failed 458 | let encoder = unsafe { &mut *encoder.get() }; 459 | let _ = encoder 460 | .send_and_flush(generate_response(StatusCode::NOT_FOUND)) 461 | .await; 462 | } 463 | } else { 464 | log::info!("🚀 endpoint connection found for {}!", proxy_pass); 465 | } 466 | } 467 | let connect_pool = unsafe { &mut *connect_pool.get() }; 468 | if let Some(conn) = connect_pool.get(proxy_pass.host()) { 469 | // send this request to endpoint 470 | let conn = conn.clone(); 471 | let proxy_pass_domain = proxy_pass.clone(); 472 | monoio::spawn(async move { 473 | Rewrite::rewrite_request(&mut request, &proxy_pass_domain); 474 | match conn.borrow() { 475 | ClientConnectionType::Http(_, sender) => { 476 | let sender = unsafe { &mut *sender.get() }; 477 | let _ = sender.send_and_flush(request).await; 478 | } 479 | ClientConnectionType::Tls(_, sender) => { 480 | let sender = unsafe { &mut *sender.get() }; 481 | let _ = sender.send_and_flush(request).await; 482 | } 483 | } 484 | }); 485 | } 486 | } 487 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "acme-lib" 7 | version = "0.8.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "292ac9d513052341a7f5bdae61f31c4dc93c1dce2598508f52709df08cecc8b0" 10 | dependencies = [ 11 | "base64", 12 | "lazy_static", 13 | "log", 14 | "openssl", 15 | "serde", 16 | "serde_json", 17 | "time 0.1.44", 18 | "ureq", 19 | ] 20 | 21 | [[package]] 22 | name = "aho-corasick" 23 | version = "0.7.18" 24 | source = "registry+https://github.com/rust-lang/crates.io-index" 25 | checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" 26 | dependencies = [ 27 | "memchr", 28 | ] 29 | 30 | [[package]] 31 | name = "anyhow" 32 | version = "1.0.63" 33 | source = "registry+https://github.com/rust-lang/crates.io-index" 34 | checksum = "a26fa4d7e3f2eebadf743988fc8aec9fa9a9e82611acafd77c1462ed6262440a" 35 | 36 | [[package]] 37 | name = "async-channel" 38 | version = "1.7.1" 39 | source = "registry+https://github.com/rust-lang/crates.io-index" 40 | checksum = "e14485364214912d3b19cc3435dde4df66065127f05fa0d75c712f36f12c2f28" 41 | dependencies = [ 42 | "concurrent-queue", 43 | "event-listener", 44 | "futures-core", 45 | ] 46 | 47 | [[package]] 48 | name = "autocfg" 49 | version = "1.1.0" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" 52 | 53 | [[package]] 54 | name = "base-x" 55 | version = "0.2.11" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" 58 | 59 | [[package]] 60 | name = "base64" 61 | version = "0.13.0" 62 | source = "registry+https://github.com/rust-lang/crates.io-index" 63 | checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" 64 | 65 | [[package]] 66 | name = "bitflags" 67 | version = "1.3.2" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 70 | 71 | [[package]] 72 | name = "bumpalo" 73 | version = "3.11.0" 74 | source = "registry+https://github.com/rust-lang/crates.io-index" 75 | checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" 76 | 77 | [[package]] 78 | name = "byteorder" 79 | version = "1.4.3" 80 | source = "registry+https://github.com/rust-lang/crates.io-index" 81 | checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" 82 | 83 | [[package]] 84 | name = "bytes" 85 | version = "1.2.1" 86 | source = "registry+https://github.com/rust-lang/crates.io-index" 87 | checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" 88 | 89 | [[package]] 90 | name = "cache-padded" 91 | version = "1.2.0" 92 | source = "registry+https://github.com/rust-lang/crates.io-index" 93 | checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" 94 | 95 | [[package]] 96 | name = "cc" 97 | version = "1.0.73" 98 | source = "registry+https://github.com/rust-lang/crates.io-index" 99 | checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" 100 | 101 | [[package]] 102 | name = "cfg-if" 103 | version = "1.0.0" 104 | source = "registry+https://github.com/rust-lang/crates.io-index" 105 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 106 | 107 | [[package]] 108 | name = "chunked_transfer" 109 | version = "1.4.0" 110 | source = "registry+https://github.com/rust-lang/crates.io-index" 111 | checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" 112 | 113 | [[package]] 114 | name = "clap" 115 | version = "4.0.29" 116 | source = "registry+https://github.com/rust-lang/crates.io-index" 117 | checksum = "4d63b9e9c07271b9957ad22c173bae2a4d9a81127680962039296abcd2f8251d" 118 | dependencies = [ 119 | "bitflags", 120 | "clap_derive", 121 | "clap_lex", 122 | "is-terminal", 123 | "once_cell", 124 | "strsim", 125 | "termcolor", 126 | ] 127 | 128 | [[package]] 129 | name = "clap_derive" 130 | version = "4.0.21" 131 | source = "registry+https://github.com/rust-lang/crates.io-index" 132 | checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" 133 | dependencies = [ 134 | "heck", 135 | "proc-macro-error", 136 | "proc-macro2", 137 | "quote", 138 | "syn", 139 | ] 140 | 141 | [[package]] 142 | name = "clap_lex" 143 | version = "0.3.0" 144 | source = "registry+https://github.com/rust-lang/crates.io-index" 145 | checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" 146 | dependencies = [ 147 | "os_str_bytes", 148 | ] 149 | 150 | [[package]] 151 | name = "concurrent-queue" 152 | version = "1.2.4" 153 | source = "registry+https://github.com/rust-lang/crates.io-index" 154 | checksum = "af4780a44ab5696ea9e28294517f1fffb421a83a25af521333c838635509db9c" 155 | dependencies = [ 156 | "cache-padded", 157 | ] 158 | 159 | [[package]] 160 | name = "const_fn" 161 | version = "0.4.9" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | checksum = "fbdcdcb6d86f71c5e97409ad45898af11cbc995b4ee8112d59095a28d376c935" 164 | 165 | [[package]] 166 | name = "cookie" 167 | version = "0.14.4" 168 | source = "registry+https://github.com/rust-lang/crates.io-index" 169 | checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" 170 | dependencies = [ 171 | "percent-encoding", 172 | "time 0.2.27", 173 | "version_check", 174 | ] 175 | 176 | [[package]] 177 | name = "cookie_store" 178 | version = "0.12.0" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "3818dfca4b0cb5211a659bbcbb94225b7127407b2b135e650d717bfb78ab10d3" 181 | dependencies = [ 182 | "cookie", 183 | "idna", 184 | "log", 185 | "publicsuffix", 186 | "serde", 187 | "serde_json", 188 | "time 0.2.27", 189 | "url", 190 | ] 191 | 192 | [[package]] 193 | name = "discard" 194 | version = "1.0.4" 195 | source = "registry+https://github.com/rust-lang/crates.io-index" 196 | checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" 197 | 198 | [[package]] 199 | name = "env_logger" 200 | version = "0.10.0" 201 | source = "registry+https://github.com/rust-lang/crates.io-index" 202 | checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" 203 | dependencies = [ 204 | "humantime", 205 | "is-terminal", 206 | "log", 207 | "regex", 208 | "termcolor", 209 | ] 210 | 211 | [[package]] 212 | name = "errno" 213 | version = "0.2.8" 214 | source = "registry+https://github.com/rust-lang/crates.io-index" 215 | checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" 216 | dependencies = [ 217 | "errno-dragonfly", 218 | "libc", 219 | "winapi", 220 | ] 221 | 222 | [[package]] 223 | name = "errno-dragonfly" 224 | version = "0.1.2" 225 | source = "registry+https://github.com/rust-lang/crates.io-index" 226 | checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" 227 | dependencies = [ 228 | "cc", 229 | "libc", 230 | ] 231 | 232 | [[package]] 233 | name = "event-listener" 234 | version = "2.5.3" 235 | source = "registry+https://github.com/rust-lang/crates.io-index" 236 | checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" 237 | 238 | [[package]] 239 | name = "figlet-rs" 240 | version = "0.1.3" 241 | source = "registry+https://github.com/rust-lang/crates.io-index" 242 | checksum = "59893843a423e9726b35a3110cd2be573bc9deddc553b0ff286107189b02d1aa" 243 | 244 | [[package]] 245 | name = "fnv" 246 | version = "1.0.7" 247 | source = "registry+https://github.com/rust-lang/crates.io-index" 248 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 249 | 250 | [[package]] 251 | name = "foreign-types" 252 | version = "0.3.2" 253 | source = "registry+https://github.com/rust-lang/crates.io-index" 254 | checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" 255 | dependencies = [ 256 | "foreign-types-shared", 257 | ] 258 | 259 | [[package]] 260 | name = "foreign-types-shared" 261 | version = "0.1.1" 262 | source = "registry+https://github.com/rust-lang/crates.io-index" 263 | checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" 264 | 265 | [[package]] 266 | name = "form_urlencoded" 267 | version = "1.0.1" 268 | source = "registry+https://github.com/rust-lang/crates.io-index" 269 | checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" 270 | dependencies = [ 271 | "matches", 272 | "percent-encoding", 273 | ] 274 | 275 | [[package]] 276 | name = "futures-core" 277 | version = "0.3.24" 278 | source = "registry+https://github.com/rust-lang/crates.io-index" 279 | checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" 280 | 281 | [[package]] 282 | name = "futures-sink" 283 | version = "0.3.24" 284 | source = "registry+https://github.com/rust-lang/crates.io-index" 285 | checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" 286 | 287 | [[package]] 288 | name = "futures-task" 289 | version = "0.3.24" 290 | source = "registry+https://github.com/rust-lang/crates.io-index" 291 | checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" 292 | 293 | [[package]] 294 | name = "futures-util" 295 | version = "0.3.24" 296 | source = "registry+https://github.com/rust-lang/crates.io-index" 297 | checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" 298 | dependencies = [ 299 | "futures-core", 300 | "futures-task", 301 | "pin-project-lite", 302 | "pin-utils", 303 | ] 304 | 305 | [[package]] 306 | name = "fxhash" 307 | version = "0.2.1" 308 | source = "registry+https://github.com/rust-lang/crates.io-index" 309 | checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" 310 | dependencies = [ 311 | "byteorder", 312 | ] 313 | 314 | [[package]] 315 | name = "getrandom" 316 | version = "0.2.7" 317 | source = "registry+https://github.com/rust-lang/crates.io-index" 318 | checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" 319 | dependencies = [ 320 | "cfg-if", 321 | "libc", 322 | "wasi 0.11.0+wasi-snapshot-preview1", 323 | ] 324 | 325 | [[package]] 326 | name = "hashbrown" 327 | version = "0.12.3" 328 | source = "registry+https://github.com/rust-lang/crates.io-index" 329 | checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" 330 | 331 | [[package]] 332 | name = "hdrhistogram" 333 | version = "7.5.1" 334 | source = "registry+https://github.com/rust-lang/crates.io-index" 335 | checksum = "6ea9fe3952d32674a14e0975009a3547af9ea364995b5ec1add2e23c2ae523ab" 336 | dependencies = [ 337 | "byteorder", 338 | "num-traits", 339 | ] 340 | 341 | [[package]] 342 | name = "heck" 343 | version = "0.4.0" 344 | source = "registry+https://github.com/rust-lang/crates.io-index" 345 | checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" 346 | 347 | [[package]] 348 | name = "hermit-abi" 349 | version = "0.2.6" 350 | source = "registry+https://github.com/rust-lang/crates.io-index" 351 | checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" 352 | dependencies = [ 353 | "libc", 354 | ] 355 | 356 | [[package]] 357 | name = "http" 358 | version = "0.2.8" 359 | source = "registry+https://github.com/rust-lang/crates.io-index" 360 | checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" 361 | dependencies = [ 362 | "bytes", 363 | "fnv", 364 | "itoa", 365 | ] 366 | 367 | [[package]] 368 | name = "http-serde" 369 | version = "1.1.0" 370 | source = "registry+https://github.com/rust-lang/crates.io-index" 371 | checksum = "6d98b3d9662de70952b14c4840ee0f37e23973542a363e2275f4b9d024ff6cca" 372 | dependencies = [ 373 | "http", 374 | "serde", 375 | ] 376 | 377 | [[package]] 378 | name = "httparse" 379 | version = "1.8.0" 380 | source = "registry+https://github.com/rust-lang/crates.io-index" 381 | checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" 382 | 383 | [[package]] 384 | name = "humantime" 385 | version = "2.1.0" 386 | source = "registry+https://github.com/rust-lang/crates.io-index" 387 | checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" 388 | 389 | [[package]] 390 | name = "idna" 391 | version = "0.2.3" 392 | source = "registry+https://github.com/rust-lang/crates.io-index" 393 | checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" 394 | dependencies = [ 395 | "matches", 396 | "unicode-bidi", 397 | "unicode-normalization", 398 | ] 399 | 400 | [[package]] 401 | name = "indexmap" 402 | version = "1.9.1" 403 | source = "registry+https://github.com/rust-lang/crates.io-index" 404 | checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" 405 | dependencies = [ 406 | "autocfg", 407 | "hashbrown", 408 | ] 409 | 410 | [[package]] 411 | name = "io-lifetimes" 412 | version = "1.0.3" 413 | source = "registry+https://github.com/rust-lang/crates.io-index" 414 | checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" 415 | dependencies = [ 416 | "libc", 417 | "windows-sys 0.42.0", 418 | ] 419 | 420 | [[package]] 421 | name = "io-uring" 422 | version = "0.5.5" 423 | source = "registry+https://github.com/rust-lang/crates.io-index" 424 | checksum = "f307526c6df4dfab4067c60bc7160324d2ef41eb0dc5a64fd25d96be17ea032c" 425 | dependencies = [ 426 | "bitflags", 427 | "libc", 428 | ] 429 | 430 | [[package]] 431 | name = "is-terminal" 432 | version = "0.4.1" 433 | source = "registry+https://github.com/rust-lang/crates.io-index" 434 | checksum = "927609f78c2913a6f6ac3c27a4fe87f43e2a35367c0c4b0f8265e8f49a104330" 435 | dependencies = [ 436 | "hermit-abi", 437 | "io-lifetimes", 438 | "rustix", 439 | "windows-sys 0.42.0", 440 | ] 441 | 442 | [[package]] 443 | name = "itoa" 444 | version = "1.0.3" 445 | source = "registry+https://github.com/rust-lang/crates.io-index" 446 | checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" 447 | 448 | [[package]] 449 | name = "js-sys" 450 | version = "0.3.59" 451 | source = "registry+https://github.com/rust-lang/crates.io-index" 452 | checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" 453 | dependencies = [ 454 | "wasm-bindgen", 455 | ] 456 | 457 | [[package]] 458 | name = "lazy_static" 459 | version = "1.4.0" 460 | source = "registry+https://github.com/rust-lang/crates.io-index" 461 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 462 | 463 | [[package]] 464 | name = "libc" 465 | version = "0.2.138" 466 | source = "registry+https://github.com/rust-lang/crates.io-index" 467 | checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" 468 | 469 | [[package]] 470 | name = "linux-raw-sys" 471 | version = "0.1.4" 472 | source = "registry+https://github.com/rust-lang/crates.io-index" 473 | checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" 474 | 475 | [[package]] 476 | name = "log" 477 | version = "0.4.17" 478 | source = "registry+https://github.com/rust-lang/crates.io-index" 479 | checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" 480 | dependencies = [ 481 | "cfg-if", 482 | ] 483 | 484 | [[package]] 485 | name = "matches" 486 | version = "0.1.9" 487 | source = "registry+https://github.com/rust-lang/crates.io-index" 488 | checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" 489 | 490 | [[package]] 491 | name = "memchr" 492 | version = "2.5.0" 493 | source = "registry+https://github.com/rust-lang/crates.io-index" 494 | checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" 495 | 496 | [[package]] 497 | name = "memoffset" 498 | version = "0.6.5" 499 | source = "registry+https://github.com/rust-lang/crates.io-index" 500 | checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" 501 | dependencies = [ 502 | "autocfg", 503 | ] 504 | 505 | [[package]] 506 | name = "mio" 507 | version = "0.8.4" 508 | source = "registry+https://github.com/rust-lang/crates.io-index" 509 | checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" 510 | dependencies = [ 511 | "libc", 512 | "log", 513 | "wasi 0.11.0+wasi-snapshot-preview1", 514 | "windows-sys 0.36.1", 515 | ] 516 | 517 | [[package]] 518 | name = "monoio" 519 | version = "0.0.9" 520 | dependencies = [ 521 | "bytes", 522 | "fxhash", 523 | "io-uring", 524 | "libc", 525 | "mio", 526 | "monoio-macros", 527 | "nix", 528 | "pin-project-lite", 529 | "socket2", 530 | "windows", 531 | ] 532 | 533 | [[package]] 534 | name = "monoio-codec" 535 | version = "0.0.4" 536 | dependencies = [ 537 | "bytes", 538 | "monoio", 539 | "tokio-util", 540 | ] 541 | 542 | [[package]] 543 | name = "monoio-gateway" 544 | version = "0.1.1" 545 | dependencies = [ 546 | "anyhow", 547 | "bytes", 548 | "clap", 549 | "env_logger", 550 | "http", 551 | "httparse", 552 | "log", 553 | "monoio", 554 | "monoio-gateway-core", 555 | "monoio-gateway-services", 556 | "monoio-http", 557 | "serde", 558 | "serde_derive", 559 | "serde_json", 560 | "thiserror", 561 | "tower", 562 | ] 563 | 564 | [[package]] 565 | name = "monoio-gateway-core" 566 | version = "0.1.1" 567 | dependencies = [ 568 | "acme-lib", 569 | "anyhow", 570 | "figlet-rs", 571 | "http", 572 | "http-serde", 573 | "lazy_static", 574 | "log", 575 | "monoio", 576 | "monoio-http", 577 | "monoio-rustls", 578 | "rustls 0.20.6", 579 | "rustls-pemfile", 580 | "serde", 581 | "serde_derive", 582 | "serde_json", 583 | "thiserror", 584 | "webpki-roots 0.22.4", 585 | ] 586 | 587 | [[package]] 588 | name = "monoio-gateway-examples" 589 | version = "0.1.1" 590 | dependencies = [ 591 | "anyhow", 592 | "monoio", 593 | "monoio-gateway", 594 | "monoio-gateway-core", 595 | "monoio-gateway-services", 596 | "monoio-http", 597 | ] 598 | 599 | [[package]] 600 | name = "monoio-gateway-services" 601 | version = "0.1.1" 602 | dependencies = [ 603 | "acme-lib", 604 | "anyhow", 605 | "async-channel", 606 | "bytes", 607 | "http", 608 | "log", 609 | "monoio", 610 | "monoio-gateway-core", 611 | "monoio-http", 612 | "monoio-rustls", 613 | "rustls 0.20.6", 614 | "rustls-pemfile", 615 | "webpki-roots 0.22.4", 616 | ] 617 | 618 | [[package]] 619 | name = "monoio-http" 620 | version = "0.0.2" 621 | dependencies = [ 622 | "bytes", 623 | "http", 624 | "httparse", 625 | "monoio", 626 | "monoio-codec", 627 | "thiserror", 628 | ] 629 | 630 | [[package]] 631 | name = "monoio-macros" 632 | version = "0.0.3" 633 | dependencies = [ 634 | "proc-macro2", 635 | "quote", 636 | "syn", 637 | ] 638 | 639 | [[package]] 640 | name = "monoio-rustls" 641 | version = "0.0.7" 642 | dependencies = [ 643 | "bytes", 644 | "monoio", 645 | "rustls 0.20.6", 646 | "thiserror", 647 | ] 648 | 649 | [[package]] 650 | name = "nix" 651 | version = "0.25.0" 652 | source = "registry+https://github.com/rust-lang/crates.io-index" 653 | checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb" 654 | dependencies = [ 655 | "autocfg", 656 | "bitflags", 657 | "cfg-if", 658 | "libc", 659 | "memoffset", 660 | "pin-utils", 661 | ] 662 | 663 | [[package]] 664 | name = "num-traits" 665 | version = "0.2.15" 666 | source = "registry+https://github.com/rust-lang/crates.io-index" 667 | checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" 668 | dependencies = [ 669 | "autocfg", 670 | ] 671 | 672 | [[package]] 673 | name = "once_cell" 674 | version = "1.14.0" 675 | source = "registry+https://github.com/rust-lang/crates.io-index" 676 | checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" 677 | 678 | [[package]] 679 | name = "openssl" 680 | version = "0.10.41" 681 | source = "registry+https://github.com/rust-lang/crates.io-index" 682 | checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" 683 | dependencies = [ 684 | "bitflags", 685 | "cfg-if", 686 | "foreign-types", 687 | "libc", 688 | "once_cell", 689 | "openssl-macros", 690 | "openssl-sys", 691 | ] 692 | 693 | [[package]] 694 | name = "openssl-macros" 695 | version = "0.1.0" 696 | source = "registry+https://github.com/rust-lang/crates.io-index" 697 | checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" 698 | dependencies = [ 699 | "proc-macro2", 700 | "quote", 701 | "syn", 702 | ] 703 | 704 | [[package]] 705 | name = "openssl-sys" 706 | version = "0.9.75" 707 | source = "registry+https://github.com/rust-lang/crates.io-index" 708 | checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" 709 | dependencies = [ 710 | "autocfg", 711 | "cc", 712 | "libc", 713 | "pkg-config", 714 | "vcpkg", 715 | ] 716 | 717 | [[package]] 718 | name = "os_str_bytes" 719 | version = "6.3.0" 720 | source = "registry+https://github.com/rust-lang/crates.io-index" 721 | checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" 722 | 723 | [[package]] 724 | name = "percent-encoding" 725 | version = "2.1.0" 726 | source = "registry+https://github.com/rust-lang/crates.io-index" 727 | checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" 728 | 729 | [[package]] 730 | name = "pin-project" 731 | version = "1.0.12" 732 | source = "registry+https://github.com/rust-lang/crates.io-index" 733 | checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" 734 | dependencies = [ 735 | "pin-project-internal", 736 | ] 737 | 738 | [[package]] 739 | name = "pin-project-internal" 740 | version = "1.0.12" 741 | source = "registry+https://github.com/rust-lang/crates.io-index" 742 | checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" 743 | dependencies = [ 744 | "proc-macro2", 745 | "quote", 746 | "syn", 747 | ] 748 | 749 | [[package]] 750 | name = "pin-project-lite" 751 | version = "0.2.9" 752 | source = "registry+https://github.com/rust-lang/crates.io-index" 753 | checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" 754 | 755 | [[package]] 756 | name = "pin-utils" 757 | version = "0.1.0" 758 | source = "registry+https://github.com/rust-lang/crates.io-index" 759 | checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 760 | 761 | [[package]] 762 | name = "pkg-config" 763 | version = "0.3.25" 764 | source = "registry+https://github.com/rust-lang/crates.io-index" 765 | checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" 766 | 767 | [[package]] 768 | name = "ppv-lite86" 769 | version = "0.2.16" 770 | source = "registry+https://github.com/rust-lang/crates.io-index" 771 | checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" 772 | 773 | [[package]] 774 | name = "proc-macro-error" 775 | version = "1.0.4" 776 | source = "registry+https://github.com/rust-lang/crates.io-index" 777 | checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" 778 | dependencies = [ 779 | "proc-macro-error-attr", 780 | "proc-macro2", 781 | "quote", 782 | "syn", 783 | "version_check", 784 | ] 785 | 786 | [[package]] 787 | name = "proc-macro-error-attr" 788 | version = "1.0.4" 789 | source = "registry+https://github.com/rust-lang/crates.io-index" 790 | checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" 791 | dependencies = [ 792 | "proc-macro2", 793 | "quote", 794 | "version_check", 795 | ] 796 | 797 | [[package]] 798 | name = "proc-macro-hack" 799 | version = "0.5.19" 800 | source = "registry+https://github.com/rust-lang/crates.io-index" 801 | checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" 802 | 803 | [[package]] 804 | name = "proc-macro2" 805 | version = "1.0.43" 806 | source = "registry+https://github.com/rust-lang/crates.io-index" 807 | checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" 808 | dependencies = [ 809 | "unicode-ident", 810 | ] 811 | 812 | [[package]] 813 | name = "publicsuffix" 814 | version = "1.5.6" 815 | source = "registry+https://github.com/rust-lang/crates.io-index" 816 | checksum = "95b4ce31ff0a27d93c8de1849cf58162283752f065a90d508f1105fa6c9a213f" 817 | dependencies = [ 818 | "idna", 819 | "url", 820 | ] 821 | 822 | [[package]] 823 | name = "qstring" 824 | version = "0.7.2" 825 | source = "registry+https://github.com/rust-lang/crates.io-index" 826 | checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e" 827 | dependencies = [ 828 | "percent-encoding", 829 | ] 830 | 831 | [[package]] 832 | name = "quote" 833 | version = "1.0.21" 834 | source = "registry+https://github.com/rust-lang/crates.io-index" 835 | checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" 836 | dependencies = [ 837 | "proc-macro2", 838 | ] 839 | 840 | [[package]] 841 | name = "rand" 842 | version = "0.8.5" 843 | source = "registry+https://github.com/rust-lang/crates.io-index" 844 | checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" 845 | dependencies = [ 846 | "libc", 847 | "rand_chacha", 848 | "rand_core", 849 | ] 850 | 851 | [[package]] 852 | name = "rand_chacha" 853 | version = "0.3.1" 854 | source = "registry+https://github.com/rust-lang/crates.io-index" 855 | checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" 856 | dependencies = [ 857 | "ppv-lite86", 858 | "rand_core", 859 | ] 860 | 861 | [[package]] 862 | name = "rand_core" 863 | version = "0.6.3" 864 | source = "registry+https://github.com/rust-lang/crates.io-index" 865 | checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" 866 | dependencies = [ 867 | "getrandom", 868 | ] 869 | 870 | [[package]] 871 | name = "regex" 872 | version = "1.6.0" 873 | source = "registry+https://github.com/rust-lang/crates.io-index" 874 | checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" 875 | dependencies = [ 876 | "aho-corasick", 877 | "memchr", 878 | "regex-syntax", 879 | ] 880 | 881 | [[package]] 882 | name = "regex-syntax" 883 | version = "0.6.27" 884 | source = "registry+https://github.com/rust-lang/crates.io-index" 885 | checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" 886 | 887 | [[package]] 888 | name = "ring" 889 | version = "0.16.20" 890 | source = "registry+https://github.com/rust-lang/crates.io-index" 891 | checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" 892 | dependencies = [ 893 | "cc", 894 | "libc", 895 | "once_cell", 896 | "spin", 897 | "untrusted", 898 | "web-sys", 899 | "winapi", 900 | ] 901 | 902 | [[package]] 903 | name = "rustc_version" 904 | version = "0.2.3" 905 | source = "registry+https://github.com/rust-lang/crates.io-index" 906 | checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" 907 | dependencies = [ 908 | "semver", 909 | ] 910 | 911 | [[package]] 912 | name = "rustix" 913 | version = "0.36.5" 914 | source = "registry+https://github.com/rust-lang/crates.io-index" 915 | checksum = "a3807b5d10909833d3e9acd1eb5fb988f79376ff10fce42937de71a449c4c588" 916 | dependencies = [ 917 | "bitflags", 918 | "errno", 919 | "io-lifetimes", 920 | "libc", 921 | "linux-raw-sys", 922 | "windows-sys 0.42.0", 923 | ] 924 | 925 | [[package]] 926 | name = "rustls" 927 | version = "0.19.1" 928 | source = "registry+https://github.com/rust-lang/crates.io-index" 929 | checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" 930 | dependencies = [ 931 | "base64", 932 | "log", 933 | "ring", 934 | "sct 0.6.1", 935 | "webpki 0.21.4", 936 | ] 937 | 938 | [[package]] 939 | name = "rustls" 940 | version = "0.20.6" 941 | source = "registry+https://github.com/rust-lang/crates.io-index" 942 | checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" 943 | dependencies = [ 944 | "log", 945 | "ring", 946 | "sct 0.7.0", 947 | "webpki 0.22.0", 948 | ] 949 | 950 | [[package]] 951 | name = "rustls-pemfile" 952 | version = "1.0.1" 953 | source = "registry+https://github.com/rust-lang/crates.io-index" 954 | checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" 955 | dependencies = [ 956 | "base64", 957 | ] 958 | 959 | [[package]] 960 | name = "ryu" 961 | version = "1.0.11" 962 | source = "registry+https://github.com/rust-lang/crates.io-index" 963 | checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" 964 | 965 | [[package]] 966 | name = "sct" 967 | version = "0.6.1" 968 | source = "registry+https://github.com/rust-lang/crates.io-index" 969 | checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" 970 | dependencies = [ 971 | "ring", 972 | "untrusted", 973 | ] 974 | 975 | [[package]] 976 | name = "sct" 977 | version = "0.7.0" 978 | source = "registry+https://github.com/rust-lang/crates.io-index" 979 | checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" 980 | dependencies = [ 981 | "ring", 982 | "untrusted", 983 | ] 984 | 985 | [[package]] 986 | name = "semver" 987 | version = "0.9.0" 988 | source = "registry+https://github.com/rust-lang/crates.io-index" 989 | checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" 990 | dependencies = [ 991 | "semver-parser", 992 | ] 993 | 994 | [[package]] 995 | name = "semver-parser" 996 | version = "0.7.0" 997 | source = "registry+https://github.com/rust-lang/crates.io-index" 998 | checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" 999 | 1000 | [[package]] 1001 | name = "serde" 1002 | version = "1.0.144" 1003 | source = "registry+https://github.com/rust-lang/crates.io-index" 1004 | checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" 1005 | dependencies = [ 1006 | "serde_derive", 1007 | ] 1008 | 1009 | [[package]] 1010 | name = "serde_derive" 1011 | version = "1.0.144" 1012 | source = "registry+https://github.com/rust-lang/crates.io-index" 1013 | checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" 1014 | dependencies = [ 1015 | "proc-macro2", 1016 | "quote", 1017 | "syn", 1018 | ] 1019 | 1020 | [[package]] 1021 | name = "serde_json" 1022 | version = "1.0.85" 1023 | source = "registry+https://github.com/rust-lang/crates.io-index" 1024 | checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" 1025 | dependencies = [ 1026 | "itoa", 1027 | "ryu", 1028 | "serde", 1029 | ] 1030 | 1031 | [[package]] 1032 | name = "sha1" 1033 | version = "0.6.1" 1034 | source = "registry+https://github.com/rust-lang/crates.io-index" 1035 | checksum = "c1da05c97445caa12d05e848c4a4fcbbea29e748ac28f7e80e9b010392063770" 1036 | dependencies = [ 1037 | "sha1_smol", 1038 | ] 1039 | 1040 | [[package]] 1041 | name = "sha1_smol" 1042 | version = "1.0.0" 1043 | source = "registry+https://github.com/rust-lang/crates.io-index" 1044 | checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" 1045 | 1046 | [[package]] 1047 | name = "slab" 1048 | version = "0.4.7" 1049 | source = "registry+https://github.com/rust-lang/crates.io-index" 1050 | checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" 1051 | dependencies = [ 1052 | "autocfg", 1053 | ] 1054 | 1055 | [[package]] 1056 | name = "socket2" 1057 | version = "0.4.7" 1058 | source = "registry+https://github.com/rust-lang/crates.io-index" 1059 | checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" 1060 | dependencies = [ 1061 | "libc", 1062 | "winapi", 1063 | ] 1064 | 1065 | [[package]] 1066 | name = "spin" 1067 | version = "0.5.2" 1068 | source = "registry+https://github.com/rust-lang/crates.io-index" 1069 | checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" 1070 | 1071 | [[package]] 1072 | name = "standback" 1073 | version = "0.2.17" 1074 | source = "registry+https://github.com/rust-lang/crates.io-index" 1075 | checksum = "e113fb6f3de07a243d434a56ec6f186dfd51cb08448239fe7bcae73f87ff28ff" 1076 | dependencies = [ 1077 | "version_check", 1078 | ] 1079 | 1080 | [[package]] 1081 | name = "stdweb" 1082 | version = "0.4.20" 1083 | source = "registry+https://github.com/rust-lang/crates.io-index" 1084 | checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" 1085 | dependencies = [ 1086 | "discard", 1087 | "rustc_version", 1088 | "stdweb-derive", 1089 | "stdweb-internal-macros", 1090 | "stdweb-internal-runtime", 1091 | "wasm-bindgen", 1092 | ] 1093 | 1094 | [[package]] 1095 | name = "stdweb-derive" 1096 | version = "0.5.3" 1097 | source = "registry+https://github.com/rust-lang/crates.io-index" 1098 | checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" 1099 | dependencies = [ 1100 | "proc-macro2", 1101 | "quote", 1102 | "serde", 1103 | "serde_derive", 1104 | "syn", 1105 | ] 1106 | 1107 | [[package]] 1108 | name = "stdweb-internal-macros" 1109 | version = "0.2.9" 1110 | source = "registry+https://github.com/rust-lang/crates.io-index" 1111 | checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" 1112 | dependencies = [ 1113 | "base-x", 1114 | "proc-macro2", 1115 | "quote", 1116 | "serde", 1117 | "serde_derive", 1118 | "serde_json", 1119 | "sha1", 1120 | "syn", 1121 | ] 1122 | 1123 | [[package]] 1124 | name = "stdweb-internal-runtime" 1125 | version = "0.1.5" 1126 | source = "registry+https://github.com/rust-lang/crates.io-index" 1127 | checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" 1128 | 1129 | [[package]] 1130 | name = "strsim" 1131 | version = "0.10.0" 1132 | source = "registry+https://github.com/rust-lang/crates.io-index" 1133 | checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" 1134 | 1135 | [[package]] 1136 | name = "syn" 1137 | version = "1.0.99" 1138 | source = "registry+https://github.com/rust-lang/crates.io-index" 1139 | checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" 1140 | dependencies = [ 1141 | "proc-macro2", 1142 | "quote", 1143 | "unicode-ident", 1144 | ] 1145 | 1146 | [[package]] 1147 | name = "termcolor" 1148 | version = "1.1.3" 1149 | source = "registry+https://github.com/rust-lang/crates.io-index" 1150 | checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" 1151 | dependencies = [ 1152 | "winapi-util", 1153 | ] 1154 | 1155 | [[package]] 1156 | name = "thiserror" 1157 | version = "1.0.33" 1158 | source = "registry+https://github.com/rust-lang/crates.io-index" 1159 | checksum = "3d0a539a918745651435ac7db7a18761589a94cd7e94cd56999f828bf73c8a57" 1160 | dependencies = [ 1161 | "thiserror-impl", 1162 | ] 1163 | 1164 | [[package]] 1165 | name = "thiserror-impl" 1166 | version = "1.0.33" 1167 | source = "registry+https://github.com/rust-lang/crates.io-index" 1168 | checksum = "c251e90f708e16c49a16f4917dc2131e75222b72edfa9cb7f7c58ae56aae0c09" 1169 | dependencies = [ 1170 | "proc-macro2", 1171 | "quote", 1172 | "syn", 1173 | ] 1174 | 1175 | [[package]] 1176 | name = "time" 1177 | version = "0.1.44" 1178 | source = "registry+https://github.com/rust-lang/crates.io-index" 1179 | checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" 1180 | dependencies = [ 1181 | "libc", 1182 | "wasi 0.10.0+wasi-snapshot-preview1", 1183 | "winapi", 1184 | ] 1185 | 1186 | [[package]] 1187 | name = "time" 1188 | version = "0.2.27" 1189 | source = "registry+https://github.com/rust-lang/crates.io-index" 1190 | checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" 1191 | dependencies = [ 1192 | "const_fn", 1193 | "libc", 1194 | "standback", 1195 | "stdweb", 1196 | "time-macros", 1197 | "version_check", 1198 | "winapi", 1199 | ] 1200 | 1201 | [[package]] 1202 | name = "time-macros" 1203 | version = "0.1.1" 1204 | source = "registry+https://github.com/rust-lang/crates.io-index" 1205 | checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" 1206 | dependencies = [ 1207 | "proc-macro-hack", 1208 | "time-macros-impl", 1209 | ] 1210 | 1211 | [[package]] 1212 | name = "time-macros-impl" 1213 | version = "0.1.2" 1214 | source = "registry+https://github.com/rust-lang/crates.io-index" 1215 | checksum = "fd3c141a1b43194f3f56a1411225df8646c55781d5f26db825b3d98507eb482f" 1216 | dependencies = [ 1217 | "proc-macro-hack", 1218 | "proc-macro2", 1219 | "quote", 1220 | "standback", 1221 | "syn", 1222 | ] 1223 | 1224 | [[package]] 1225 | name = "tinyvec" 1226 | version = "1.6.0" 1227 | source = "registry+https://github.com/rust-lang/crates.io-index" 1228 | checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" 1229 | dependencies = [ 1230 | "tinyvec_macros", 1231 | ] 1232 | 1233 | [[package]] 1234 | name = "tinyvec_macros" 1235 | version = "0.1.0" 1236 | source = "registry+https://github.com/rust-lang/crates.io-index" 1237 | checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" 1238 | 1239 | [[package]] 1240 | name = "tokio" 1241 | version = "1.21.0" 1242 | source = "registry+https://github.com/rust-lang/crates.io-index" 1243 | checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42" 1244 | dependencies = [ 1245 | "autocfg", 1246 | "once_cell", 1247 | "pin-project-lite", 1248 | "socket2", 1249 | ] 1250 | 1251 | [[package]] 1252 | name = "tokio-util" 1253 | version = "0.7.3" 1254 | source = "registry+https://github.com/rust-lang/crates.io-index" 1255 | checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" 1256 | dependencies = [ 1257 | "bytes", 1258 | "futures-core", 1259 | "futures-sink", 1260 | "pin-project-lite", 1261 | "tokio", 1262 | "tracing", 1263 | ] 1264 | 1265 | [[package]] 1266 | name = "tower" 1267 | version = "0.4.13" 1268 | source = "registry+https://github.com/rust-lang/crates.io-index" 1269 | checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" 1270 | dependencies = [ 1271 | "futures-core", 1272 | "futures-util", 1273 | "hdrhistogram", 1274 | "indexmap", 1275 | "pin-project", 1276 | "pin-project-lite", 1277 | "rand", 1278 | "slab", 1279 | "tokio", 1280 | "tokio-util", 1281 | "tower-layer", 1282 | "tower-service", 1283 | "tracing", 1284 | ] 1285 | 1286 | [[package]] 1287 | name = "tower-layer" 1288 | version = "0.3.1" 1289 | source = "registry+https://github.com/rust-lang/crates.io-index" 1290 | checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" 1291 | 1292 | [[package]] 1293 | name = "tower-service" 1294 | version = "0.3.2" 1295 | source = "registry+https://github.com/rust-lang/crates.io-index" 1296 | checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" 1297 | 1298 | [[package]] 1299 | name = "tracing" 1300 | version = "0.1.36" 1301 | source = "registry+https://github.com/rust-lang/crates.io-index" 1302 | checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" 1303 | dependencies = [ 1304 | "cfg-if", 1305 | "log", 1306 | "pin-project-lite", 1307 | "tracing-core", 1308 | ] 1309 | 1310 | [[package]] 1311 | name = "tracing-core" 1312 | version = "0.1.29" 1313 | source = "registry+https://github.com/rust-lang/crates.io-index" 1314 | checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" 1315 | dependencies = [ 1316 | "once_cell", 1317 | ] 1318 | 1319 | [[package]] 1320 | name = "unicode-bidi" 1321 | version = "0.3.8" 1322 | source = "registry+https://github.com/rust-lang/crates.io-index" 1323 | checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" 1324 | 1325 | [[package]] 1326 | name = "unicode-ident" 1327 | version = "1.0.3" 1328 | source = "registry+https://github.com/rust-lang/crates.io-index" 1329 | checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" 1330 | 1331 | [[package]] 1332 | name = "unicode-normalization" 1333 | version = "0.1.21" 1334 | source = "registry+https://github.com/rust-lang/crates.io-index" 1335 | checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" 1336 | dependencies = [ 1337 | "tinyvec", 1338 | ] 1339 | 1340 | [[package]] 1341 | name = "untrusted" 1342 | version = "0.7.1" 1343 | source = "registry+https://github.com/rust-lang/crates.io-index" 1344 | checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" 1345 | 1346 | [[package]] 1347 | name = "ureq" 1348 | version = "1.5.5" 1349 | source = "registry+https://github.com/rust-lang/crates.io-index" 1350 | checksum = "2b8b063c2d59218ae09f22b53c42eaad0d53516457905f5235ca4bc9e99daa71" 1351 | dependencies = [ 1352 | "base64", 1353 | "chunked_transfer", 1354 | "cookie", 1355 | "cookie_store", 1356 | "log", 1357 | "once_cell", 1358 | "qstring", 1359 | "rustls 0.19.1", 1360 | "url", 1361 | "webpki 0.21.4", 1362 | "webpki-roots 0.21.1", 1363 | ] 1364 | 1365 | [[package]] 1366 | name = "url" 1367 | version = "2.2.2" 1368 | source = "registry+https://github.com/rust-lang/crates.io-index" 1369 | checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" 1370 | dependencies = [ 1371 | "form_urlencoded", 1372 | "idna", 1373 | "matches", 1374 | "percent-encoding", 1375 | ] 1376 | 1377 | [[package]] 1378 | name = "vcpkg" 1379 | version = "0.2.15" 1380 | source = "registry+https://github.com/rust-lang/crates.io-index" 1381 | checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" 1382 | 1383 | [[package]] 1384 | name = "version_check" 1385 | version = "0.9.4" 1386 | source = "registry+https://github.com/rust-lang/crates.io-index" 1387 | checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" 1388 | 1389 | [[package]] 1390 | name = "wasi" 1391 | version = "0.10.0+wasi-snapshot-preview1" 1392 | source = "registry+https://github.com/rust-lang/crates.io-index" 1393 | checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" 1394 | 1395 | [[package]] 1396 | name = "wasi" 1397 | version = "0.11.0+wasi-snapshot-preview1" 1398 | source = "registry+https://github.com/rust-lang/crates.io-index" 1399 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 1400 | 1401 | [[package]] 1402 | name = "wasm-bindgen" 1403 | version = "0.2.82" 1404 | source = "registry+https://github.com/rust-lang/crates.io-index" 1405 | checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" 1406 | dependencies = [ 1407 | "cfg-if", 1408 | "wasm-bindgen-macro", 1409 | ] 1410 | 1411 | [[package]] 1412 | name = "wasm-bindgen-backend" 1413 | version = "0.2.82" 1414 | source = "registry+https://github.com/rust-lang/crates.io-index" 1415 | checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" 1416 | dependencies = [ 1417 | "bumpalo", 1418 | "log", 1419 | "once_cell", 1420 | "proc-macro2", 1421 | "quote", 1422 | "syn", 1423 | "wasm-bindgen-shared", 1424 | ] 1425 | 1426 | [[package]] 1427 | name = "wasm-bindgen-macro" 1428 | version = "0.2.82" 1429 | source = "registry+https://github.com/rust-lang/crates.io-index" 1430 | checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" 1431 | dependencies = [ 1432 | "quote", 1433 | "wasm-bindgen-macro-support", 1434 | ] 1435 | 1436 | [[package]] 1437 | name = "wasm-bindgen-macro-support" 1438 | version = "0.2.82" 1439 | source = "registry+https://github.com/rust-lang/crates.io-index" 1440 | checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" 1441 | dependencies = [ 1442 | "proc-macro2", 1443 | "quote", 1444 | "syn", 1445 | "wasm-bindgen-backend", 1446 | "wasm-bindgen-shared", 1447 | ] 1448 | 1449 | [[package]] 1450 | name = "wasm-bindgen-shared" 1451 | version = "0.2.82" 1452 | source = "registry+https://github.com/rust-lang/crates.io-index" 1453 | checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" 1454 | 1455 | [[package]] 1456 | name = "web-sys" 1457 | version = "0.3.59" 1458 | source = "registry+https://github.com/rust-lang/crates.io-index" 1459 | checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" 1460 | dependencies = [ 1461 | "js-sys", 1462 | "wasm-bindgen", 1463 | ] 1464 | 1465 | [[package]] 1466 | name = "webpki" 1467 | version = "0.21.4" 1468 | source = "registry+https://github.com/rust-lang/crates.io-index" 1469 | checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" 1470 | dependencies = [ 1471 | "ring", 1472 | "untrusted", 1473 | ] 1474 | 1475 | [[package]] 1476 | name = "webpki" 1477 | version = "0.22.0" 1478 | source = "registry+https://github.com/rust-lang/crates.io-index" 1479 | checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" 1480 | dependencies = [ 1481 | "ring", 1482 | "untrusted", 1483 | ] 1484 | 1485 | [[package]] 1486 | name = "webpki-roots" 1487 | version = "0.21.1" 1488 | source = "registry+https://github.com/rust-lang/crates.io-index" 1489 | checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" 1490 | dependencies = [ 1491 | "webpki 0.21.4", 1492 | ] 1493 | 1494 | [[package]] 1495 | name = "webpki-roots" 1496 | version = "0.22.4" 1497 | source = "registry+https://github.com/rust-lang/crates.io-index" 1498 | checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" 1499 | dependencies = [ 1500 | "webpki 0.22.0", 1501 | ] 1502 | 1503 | [[package]] 1504 | name = "winapi" 1505 | version = "0.3.9" 1506 | source = "registry+https://github.com/rust-lang/crates.io-index" 1507 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 1508 | dependencies = [ 1509 | "winapi-i686-pc-windows-gnu", 1510 | "winapi-x86_64-pc-windows-gnu", 1511 | ] 1512 | 1513 | [[package]] 1514 | name = "winapi-i686-pc-windows-gnu" 1515 | version = "0.4.0" 1516 | source = "registry+https://github.com/rust-lang/crates.io-index" 1517 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1518 | 1519 | [[package]] 1520 | name = "winapi-util" 1521 | version = "0.1.5" 1522 | source = "registry+https://github.com/rust-lang/crates.io-index" 1523 | checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" 1524 | dependencies = [ 1525 | "winapi", 1526 | ] 1527 | 1528 | [[package]] 1529 | name = "winapi-x86_64-pc-windows-gnu" 1530 | version = "0.4.0" 1531 | source = "registry+https://github.com/rust-lang/crates.io-index" 1532 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 1533 | 1534 | [[package]] 1535 | name = "windows" 1536 | version = "0.43.0" 1537 | source = "registry+https://github.com/rust-lang/crates.io-index" 1538 | checksum = "04662ed0e3e5630dfa9b26e4cb823b817f1a9addda855d973a9458c236556244" 1539 | dependencies = [ 1540 | "windows_aarch64_gnullvm", 1541 | "windows_aarch64_msvc 0.42.0", 1542 | "windows_i686_gnu 0.42.0", 1543 | "windows_i686_msvc 0.42.0", 1544 | "windows_x86_64_gnu 0.42.0", 1545 | "windows_x86_64_gnullvm", 1546 | "windows_x86_64_msvc 0.42.0", 1547 | ] 1548 | 1549 | [[package]] 1550 | name = "windows-sys" 1551 | version = "0.36.1" 1552 | source = "registry+https://github.com/rust-lang/crates.io-index" 1553 | checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" 1554 | dependencies = [ 1555 | "windows_aarch64_msvc 0.36.1", 1556 | "windows_i686_gnu 0.36.1", 1557 | "windows_i686_msvc 0.36.1", 1558 | "windows_x86_64_gnu 0.36.1", 1559 | "windows_x86_64_msvc 0.36.1", 1560 | ] 1561 | 1562 | [[package]] 1563 | name = "windows-sys" 1564 | version = "0.42.0" 1565 | source = "registry+https://github.com/rust-lang/crates.io-index" 1566 | checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" 1567 | dependencies = [ 1568 | "windows_aarch64_gnullvm", 1569 | "windows_aarch64_msvc 0.42.0", 1570 | "windows_i686_gnu 0.42.0", 1571 | "windows_i686_msvc 0.42.0", 1572 | "windows_x86_64_gnu 0.42.0", 1573 | "windows_x86_64_gnullvm", 1574 | "windows_x86_64_msvc 0.42.0", 1575 | ] 1576 | 1577 | [[package]] 1578 | name = "windows_aarch64_gnullvm" 1579 | version = "0.42.0" 1580 | source = "registry+https://github.com/rust-lang/crates.io-index" 1581 | checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" 1582 | 1583 | [[package]] 1584 | name = "windows_aarch64_msvc" 1585 | version = "0.36.1" 1586 | source = "registry+https://github.com/rust-lang/crates.io-index" 1587 | checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" 1588 | 1589 | [[package]] 1590 | name = "windows_aarch64_msvc" 1591 | version = "0.42.0" 1592 | source = "registry+https://github.com/rust-lang/crates.io-index" 1593 | checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" 1594 | 1595 | [[package]] 1596 | name = "windows_i686_gnu" 1597 | version = "0.36.1" 1598 | source = "registry+https://github.com/rust-lang/crates.io-index" 1599 | checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" 1600 | 1601 | [[package]] 1602 | name = "windows_i686_gnu" 1603 | version = "0.42.0" 1604 | source = "registry+https://github.com/rust-lang/crates.io-index" 1605 | checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" 1606 | 1607 | [[package]] 1608 | name = "windows_i686_msvc" 1609 | version = "0.36.1" 1610 | source = "registry+https://github.com/rust-lang/crates.io-index" 1611 | checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" 1612 | 1613 | [[package]] 1614 | name = "windows_i686_msvc" 1615 | version = "0.42.0" 1616 | source = "registry+https://github.com/rust-lang/crates.io-index" 1617 | checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" 1618 | 1619 | [[package]] 1620 | name = "windows_x86_64_gnu" 1621 | version = "0.36.1" 1622 | source = "registry+https://github.com/rust-lang/crates.io-index" 1623 | checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" 1624 | 1625 | [[package]] 1626 | name = "windows_x86_64_gnu" 1627 | version = "0.42.0" 1628 | source = "registry+https://github.com/rust-lang/crates.io-index" 1629 | checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" 1630 | 1631 | [[package]] 1632 | name = "windows_x86_64_gnullvm" 1633 | version = "0.42.0" 1634 | source = "registry+https://github.com/rust-lang/crates.io-index" 1635 | checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" 1636 | 1637 | [[package]] 1638 | name = "windows_x86_64_msvc" 1639 | version = "0.36.1" 1640 | source = "registry+https://github.com/rust-lang/crates.io-index" 1641 | checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" 1642 | 1643 | [[package]] 1644 | name = "windows_x86_64_msvc" 1645 | version = "0.42.0" 1646 | source = "registry+https://github.com/rust-lang/crates.io-index" 1647 | checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" 1648 | --------------------------------------------------------------------------------