From fb0aa02b3c47579731708f3ca8e74132c917366c Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sun, 13 Sep 2020 10:12:07 +0100 Subject: [PATCH] move and update server+tls examples (#190) --- actix-server/Cargo.toml | 1 + actix-server/examples/basic.rs | 88 ++++++++++++++++++++++++++++++++++ actix-server/src/lib.rs | 8 ++-- actix-server/src/service.rs | 4 +- actix-server/src/worker.rs | 1 + actix-service/src/pipeline.rs | 4 +- actix-tls/Cargo.toml | 8 ++++ actix-tls/examples/basic.rs | 82 +++++++++++++++++++++++++++++++ actix-tls/examples/cert.pem | 25 ++++++++++ actix-tls/examples/key.pem | 27 +++++++++++ examples/basic.rs | 77 ----------------------------- examples/cert.pem | 31 ------------ examples/key.pem | 51 -------------------- examples/ssl.rs | 51 -------------------- 14 files changed, 241 insertions(+), 217 deletions(-) create mode 100644 actix-server/examples/basic.rs create mode 100644 actix-tls/examples/basic.rs create mode 100644 actix-tls/examples/cert.pem create mode 100644 actix-tls/examples/key.pem delete mode 100644 examples/basic.rs delete mode 100644 examples/cert.pem delete mode 100644 examples/key.pem delete mode 100644 examples/ssl.rs diff --git a/actix-server/Cargo.toml b/actix-server/Cargo.toml index 6ca75ddd..1a67f61c 100644 --- a/actix-server/Cargo.toml +++ b/actix-server/Cargo.toml @@ -41,3 +41,4 @@ mio-uds = { version = "0.6.7" } bytes = "0.5" env_logger = "0.7" actix-testing = "1.0.0" +tokio = { version = "0.2", features = ["io-util"] } diff --git a/actix-server/examples/basic.rs b/actix-server/examples/basic.rs new file mode 100644 index 00000000..45e473a9 --- /dev/null +++ b/actix-server/examples/basic.rs @@ -0,0 +1,88 @@ +//! Simple composite-service TCP echo server. +//! +//! Using the following command: +//! +//! ```sh +//! nc 127.0.0.1 8080 +//! ``` +//! +//! Start typing. When you press enter the typed line will be echoed back. The server will log +//! the length of each line it echos and the total size of data sent when the connection is closed. + +use std::sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, +}; +use std::{env, io}; + +use actix_rt::net::TcpStream; +use actix_server::Server; +use actix_service::pipeline_factory; +use bytes::BytesMut; +use futures_util::future::ok; +use log::{error, info}; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; + +#[actix_rt::main] +async fn main() -> io::Result<()> { + env::set_var("RUST_LOG", "actix=trace,basic=trace"); + env_logger::init(); + + let count = Arc::new(AtomicUsize::new(0)); + + let addr = ("127.0.0.1", 8080); + info!("starting server on port: {}", &addr.0); + + // Bind socket address and start worker(s). By default, the server uses the number of available + // logical CPU cores as the worker count. For this reason, the closure passed to bind needs + // to return a service *factory*; so it can be created once per worker. + Server::build() + .bind("echo", addr, move || { + let count = Arc::clone(&count); + let num2 = Arc::clone(&count); + + pipeline_factory(move |mut stream: TcpStream| { + let count = Arc::clone(&count); + + async move { + let num = count.fetch_add(1, Ordering::SeqCst); + let num = num + 1; + + let mut size = 0; + let mut buf = BytesMut::new(); + + loop { + match stream.read_buf(&mut buf).await { + // end of stream; bail from loop + Ok(0) => break, + + // more bytes to process + Ok(bytes_read) => { + info!("[{}] read {} bytes", num, bytes_read); + stream.write_all(&buf[size..]).await.unwrap(); + size += bytes_read; + } + + // stream error; bail from loop with error + Err(err) => { + error!("Stream Error: {:?}", err); + return Err(()); + } + } + } + + // send data down service pipeline + Ok((buf.freeze(), size)) + } + }) + .map_err(|err| error!("Service Error: {:?}", err)) + .and_then(move |(_, size)| { + let num = num2.load(Ordering::SeqCst); + info!("[{}] total bytes read: {}", num, size); + ok(size) + }) + })? + .workers(1) + .run() + .await +} diff --git a/actix-server/src/lib.rs b/actix-server/src/lib.rs index 5143164e..8efc29d3 100644 --- a/actix-server/src/lib.rs +++ b/actix-server/src/lib.rs @@ -1,6 +1,6 @@ -//! General purpose tcp server -#![deny(rust_2018_idioms, warnings)] -#![allow(clippy::type_complexity)] +//! General purpose TCP server. + +#![deny(rust_2018_idioms)] mod accept; mod builder; @@ -19,7 +19,7 @@ pub use self::service::ServiceFactory; #[doc(hidden)] pub use self::socket::FromStream; -/// Socket id token +/// Socket ID token #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub(crate) struct Token(usize); diff --git a/actix-server/src/service.rs b/actix-server/src/service.rs index bf429185..984e5228 100644 --- a/actix-server/src/service.rs +++ b/actix-server/src/service.rs @@ -17,8 +17,10 @@ use crate::socket::{FromStream, StdStream}; pub(crate) enum ServerMessage { /// New stream Connect(StdStream), - /// Gracefull shutdown + + /// Gracefully shutdown Shutdown(Duration), + /// Force shutdown ForceShutdown, } diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index 4ae3e4f3..35331757 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -303,6 +303,7 @@ enum WorkerState { Restarting( usize, Token, + #[allow(clippy::type_complexity)] Pin, ()>>>>, ), Shutdown( diff --git a/actix-service/src/pipeline.rs b/actix-service/src/pipeline.rs index 69881e4b..75cd6af9 100644 --- a/actix-service/src/pipeline.rs +++ b/actix-service/src/pipeline.rs @@ -9,7 +9,7 @@ use crate::map_init_err::MapInitErr; use crate::then::{ThenService, ThenServiceFactory}; use crate::{IntoService, IntoServiceFactory, Service, ServiceFactory}; -/// Contruct new pipeline with one service in pipeline chain. +/// Construct new pipeline with one service in pipeline chain. pub fn pipeline(service: F) -> Pipeline where F: IntoService, @@ -20,7 +20,7 @@ where } } -/// Contruct new pipeline factory with one service factory. +/// Construct new pipeline factory with one service factory. pub fn pipeline_factory(factory: F) -> PipelineFactory where T: ServiceFactory, diff --git a/actix-tls/Cargo.toml b/actix-tls/Cargo.toml index 24777fd6..801f6144 100644 --- a/actix-tls/Cargo.toml +++ b/actix-tls/Cargo.toml @@ -18,6 +18,10 @@ features = ["openssl", "rustls", "nativetls"] name = "actix_tls" path = "src/lib.rs" +[[example]] +name = "basic" +required-features = ["rustls"] + [features] default = [] @@ -53,4 +57,8 @@ tokio-tls = { version = "0.3", optional = true } [dev-dependencies] bytes = "0.5" +log = "0.4" +env_logger = "0.7" actix-testing = "1.0.0" +actix-server = "1" +actix-rt = "1" diff --git a/actix-tls/examples/basic.rs b/actix-tls/examples/basic.rs new file mode 100644 index 00000000..cd706958 --- /dev/null +++ b/actix-tls/examples/basic.rs @@ -0,0 +1,82 @@ +//! TLS Acceptor Server +//! +//! Using either HTTPie (`http`) or cURL: +//! +//! This commands will produce errors in the server log: +//! ```sh +//! curl 127.0.0.1:8443 +//! http 127.0.0.1:8443 +//! ``` +//! +//! These commands will show "empty reply" on the client but will debug print the TLS stream info +//! in the server log, indicating a successful TLS handshake: +//! ```sh +//! curl -k https://127.0.0.1:8443 +//! http --verify=false https://127.0.0.1:8443 +//! ``` + +use std::{ + env, + fs::File, + io::{self, BufReader}, + sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, + }, +}; + +use actix_server::Server; +use actix_service::pipeline_factory; +use actix_tls::rustls::Acceptor as RustlsAcceptor; +use futures_util::future::ok; +use log::info; +use rust_tls::{ + internal::pemfile::certs, internal::pemfile::rsa_private_keys, NoClientAuth, ServerConfig, +}; + +#[derive(Debug)] +struct ServiceState { + num: Arc, +} + +#[actix_rt::main] +async fn main() -> io::Result<()> { + env::set_var("RUST_LOG", "actix=trace,basic=trace"); + env_logger::init(); + + let mut tls_config = ServerConfig::new(NoClientAuth::new()); + + // Load TLS key and cert files + let cert_file = &mut BufReader::new(File::open("./examples/cert.pem").unwrap()); + let key_file = &mut BufReader::new(File::open("./examples/key.pem").unwrap()); + + let cert_chain = certs(cert_file).unwrap(); + let mut keys = rsa_private_keys(key_file).unwrap(); + tls_config + .set_single_cert(cert_chain, keys.remove(0)) + .unwrap(); + + let tls_acceptor = RustlsAcceptor::new(tls_config); + + let count = Arc::new(AtomicUsize::new(0)); + + let addr = ("127.0.0.1", 8443); + info!("starting server on port: {}", &addr.0); + + Server::build() + .bind("tls-example", addr, move || { + let count = Arc::clone(&count); + + // Set up TLS service factory + pipeline_factory(tls_acceptor.clone()) + .map_err(|err| println!("Rustls error: {:?}", err)) + .and_then(move |stream| { + let num = count.fetch_add(1, Ordering::Relaxed); + info!("[{}] Got TLS connection: {:?}", num, stream); + ok(()) + }) + })? + .workers(1) + .run() + .await +} diff --git a/actix-tls/examples/cert.pem b/actix-tls/examples/cert.pem new file mode 100644 index 00000000..34598fb2 --- /dev/null +++ b/actix-tls/examples/cert.pem @@ -0,0 +1,25 @@ +-----BEGIN CERTIFICATE----- +MIIENjCCAp6gAwIBAgIRANp+D9pBErdacw6KjrwJ+4swDQYJKoZIhvcNAQELBQAw +bTEeMBwGA1UEChMVbWtjZXJ0IGRldmVsb3BtZW50IENBMSEwHwYDVQQLDBhyb2JA +c29tYnJhLng1Mi5kZXYgKFJvYikxKDAmBgNVBAMMH21rY2VydCByb2JAc29tYnJh +Lng1Mi5kZXYgKFJvYikwHhcNMTkwNjAxMDAwMDAwWhcNMzAwOTEzMDIzNDI0WjBM +MScwJQYDVQQKEx5ta2NlcnQgZGV2ZWxvcG1lbnQgY2VydGlmaWNhdGUxITAfBgNV +BAsMGHJvYkBzb21icmEueDUyLmRldiAoUm9iKTCCASIwDQYJKoZIhvcNAQEBBQAD +ggEPADCCAQoCggEBALYAn8dsQUDTp8SptAtkiAySvQYLpAOct3/OjBn+dSYfbQcp +Ph9w/Zo83Msl7Fb1DBvADHFtyBpESATZ2chS5fwCAwUFTlKrzMk3qauEoJ3cCQa8 +ccqhTMLeT38jRlhXrMHWBfz0ipqy+yTLWeM32LX8s0jPbbsZ3gVJ/Ls4qm0CTaqb +zRdcQ7GTVKYet5DR7ZvwvAaLtWk/iiHKwnOveuF27HNlxj0Rwd/lhJ/t9x8xJwyR +MTdm852KQadI8xOSbWNK4j9419yzKjUEMKgn78wT/7DQfeKKCAreHa4MaEw4+koD +2Bqb+V4fI6T84VvXkNG3CjSpmIiYGlIE1LVgBL8CAwEAAaNyMHAwDgYDVR0PAQH/ +BAQDAgWgMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAwGA1UdEwEB/wQCMAAwHwYDVR0j +BBgwFoAUto/ox0MqZShmQpViV/gjfJKrMDkwGgYDVR0RBBMwEYIJbG9jYWxob3N0 +hwR/AAABMA0GCSqGSIb3DQEBCwUAA4IBgQBUCMzqTY0sg+61gh8gKS5TCL6qs0R1 +xys/EFFaD5JYUsfM/HyhHd0jq+x5Pd3mB2Jvhoq9xhjMwP11H8Uw5lLBHA8USdF9 +EiLW1GvT3/gLfMqb0lPk0RMRBeX8c0QbDtqdiUCE7S6zJbZ5gjFeRuFNjdcGA1Ss +8CPPts2mns5cwah6H7T/BFzj5aR9Qe14vo1Rpr5gD5CpHvk1t16q7YsczQfVMvt3 +Ydk6p0rwA8Z5okQK7y3qKPZI+//ygWL6ZBjVjl1/Al8vybG2UYjYgfMBwaVvMiDJ +j/vCdVmlvGb+MZlZID/p2veaNeEKgi1A1EOj3sNuQYXXFfSD9mdamX7JIfGi/U7v +ivvUjJUbzGrUngldt5iCKqcCQum7nlzu9sT1Tm2t/n4tz/btrI+Wimg8riSzM+Nk +dfuvv4NbWe6Th5460HH8mMvfPZSB8dCoxwm98tuqcMXLkR1RJX5Z8LYAaPTsUs/h +HxQCY4EaY7feZ/qFal9FGwvpzVr3/XjgSCU= +-----END CERTIFICATE----- diff --git a/actix-tls/examples/key.pem b/actix-tls/examples/key.pem new file mode 100644 index 00000000..59cbe8ce --- /dev/null +++ b/actix-tls/examples/key.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAtgCfx2xBQNOnxKm0C2SIDJK9BgukA5y3f86MGf51Jh9tByk+ +H3D9mjzcyyXsVvUMG8AMcW3IGkRIBNnZyFLl/AIDBQVOUqvMyTepq4SgndwJBrxx +yqFMwt5PfyNGWFeswdYF/PSKmrL7JMtZ4zfYtfyzSM9tuxneBUn8uziqbQJNqpvN +F1xDsZNUph63kNHtm/C8Bou1aT+KIcrCc6964Xbsc2XGPRHB3+WEn+33HzEnDJEx +N2bznYpBp0jzE5JtY0riP3jX3LMqNQQwqCfvzBP/sNB94ooICt4drgxoTDj6SgPY +Gpv5Xh8jpPzhW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1S+VGKXA+EjW2cDRB3jKa +45ucICcCgYBdMxB5Oj6GpdewWWaBss9dwHtDaD4oVGYIBbIc2qdyCYixWdW9NccV +fRJs0ulGrpg9OtyWbwZASu2jz55+s3hi4rnrcaXKiIh9Rs25v1irF6Dmduvo7CaN +Mf7zBg7LUttmqN6D3npIAxmBULl8KRfjnt6U2tJolF5X0qQ1uqnnTA== +-----END RSA PRIVATE KEY----- diff --git a/examples/basic.rs b/examples/basic.rs deleted file mode 100644 index 3de6d212..00000000 --- a/examples/basic.rs +++ /dev/null @@ -1,77 +0,0 @@ -//! simple composite service -//! build: cargo run --example basic --features "ssl" -//! to test: curl https://127.0.0.1:8443/ -k -use std::sync::{ - atomic::{AtomicUsize, Ordering}, - Arc, -}; -use std::{env, fmt, io}; - -use actix_codec::{AsyncRead, AsyncWrite}; -use actix_rt::System; -use actix_server::{Io, Server}; -use actix_service::{service_fn, NewService}; -use futures_util::{future, Future}; -use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod}; -use tokio_openssl::SslAcceptorExt; - -/// Simple logger service, it just prints fact of the new connections -fn logger( - stream: T, -) -> impl Future { - println!("New connection: {:?}", stream); - future::ok(stream) -} - -fn main() -> io::Result<()> { - env::set_var("RUST_LOG", "actix_net=trace"); - env_logger::init(); - - let sys = System::new("test"); - - // load ssl keys - let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap(); - builder - .set_private_key_file("./examples/key.pem", SslFiletype::PEM) - .unwrap(); - builder - .set_certificate_chain_file("./examples/cert.pem") - .unwrap(); - let acceptor = builder.build(); - - let num = Arc::new(AtomicUsize::new(0)); - - // bind socket address and start workers. By default server uses number of - // available logical cpu as threads count. actix net start separate - // instances of service pipeline in each worker. - Server::build() - .bind( - // configure service pipeline - "basic", - "0.0.0.0:8443", - move || { - let num = num.clone(); - let acceptor = acceptor.clone(); - - // service for converting incoming TcpStream to a SslStream - service_fn(move |stream: Io| { - SslAcceptorExt::accept_async(&acceptor, stream.into_parts().0) - .map_err(|e| println!("Openssl error: {}", e)) - }) - // .and_then() combinator uses other service to convert incoming `Request` to a - // `Response` and then uses that response as an input for next - // service. in this case, on success we use `logger` service - .and_then(logger) - // Next service counts number of connections - .and_then(move |_| { - let num = num.fetch_add(1, Ordering::Relaxed); - println!("got ssl connection {:?}", num); - future::ok(()) - }) - }, - ) - .unwrap() - .start(); - - sys.run() -} diff --git a/examples/cert.pem b/examples/cert.pem deleted file mode 100644 index 159aacea..00000000 --- a/examples/cert.pem +++ /dev/null @@ -1,31 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIFPjCCAyYCCQDvLYiYD+jqeTANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJV -UzELMAkGA1UECAwCQ0ExCzAJBgNVBAcMAlNGMRAwDgYDVQQKDAdDb21wYW55MQww -CgYDVQQLDANPcmcxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xODAxMjUx -NzQ2MDFaFw0xOTAxMjUxNzQ2MDFaMGExCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJD -QTELMAkGA1UEBwwCU0YxEDAOBgNVBAoMB0NvbXBhbnkxDDAKBgNVBAsMA09yZzEY -MBYGA1UEAwwPd3d3LmV4YW1wbGUuY29tMIICIjANBgkqhkiG9w0BAQEFAAOCAg8A -MIICCgKCAgEA2WzIA2IpVR9Tb9EFhITlxuhE5rY2a3S6qzYNzQVgSFggxXEPn8k1 -sQEcer5BfAP986Sck3H0FvB4Bt/I8PwOtUCmhwcc8KtB5TcGPR4fjXnrpC+MIK5U -NLkwuyBDKziYzTdBj8kUFX1WxmvEHEgqToPOZfBgsS71cJAR/zOWraDLSRM54jXy -voLZN4Ti9rQagQrvTQ44Vz5ycDQy7UxtbUGh1CVv69vNVr7/SOOh/Nw5FNOZWLWr -odGyoec5wh9iqRZgRqiTUc6Lt7V2RWc2X2gjwST2UfI+U46Ip3oaQ7ZD4eAkoqND -xdniBZAykVG3c/99ux4BAESTF8fsNch6UticBxYMuTu+ou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git a/examples/key.pem b/examples/key.pem deleted file mode 100644 index aac387c6..00000000 --- a/examples/key.pem +++ /dev/null @@ -1,51 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIJKAIBAAKCAgEA2WzIA2IpVR9Tb9EFhITlxuhE5rY2a3S6qzYNzQVgSFggxXEP -n8k1sQEcer5BfAP986Sck3H0FvB4Bt/I8PwOtUCmhwcc8KtB5TcGPR4fjXnrpC+M -IK5UNLkwuyBDKziYzTdBj8kUFX1WxmvEHEgqToPOZfBgsS71cJAR/zOWraDLSRM5 -4jXyvoLZN4Ti9rQagQrvTQ44Vz5ycDQy7UxtbUGh1CVv69vNVr7/SOOh/Nw5FNOZ -WLWrodGyoec5wh9iqRZgRqiTUc6Lt7V2RWc2X2gjwST2UfI+U46Ip3oaQ7ZD4eAk -oqNDxdniBZAykVG3c/99ux4BAESTF8fsNch6UticBxYMuTu+ouvP0psfI9wwwNli -JDmACRUTB9AgRynbL1AzhqQoDfsb98IZfjfNOpwnwuLwpMAPhbgd5KNdZaIJ4Hb6 -/stIyFElOExxd3TAxF2Gshd/lq1JcNHAZ1DSXV5MvOWT/NWgXwbIzUgQ8eIi+HuD -YX2UUuaB6R8tbd52H7rbUv6HrfinuSlKWqjSYLkiKHkwUpoMw8y9UycRSzs1E9nP -wPTOvRXb0mNCQeBCV9FvStNVXdCUTT8LGPv87xSD2pmt7LijlE6mHLG8McfcWkzA -69unCEHIFAFDimTuN7EBljc119xWFTcHMyoZAfFF+oTqwSbBGImruCxnaJECAwEA -AQKCAgAME3aoeXNCPxMrSri7u4Xnnk71YXl0Tm9vwvjRQlMusXZggP8VKN/KjP0/ -9AE/GhmoxqPLrLCZ9ZE1EIjgmZ9Xgde9+C8rTtfCG2RFUL7/5J2p6NonlocmxoJm -YkxYwjP6ce86RTjQWL3RF3s09u0inz9/efJk5O7M6bOWMQ9VZXDlBiRY5BYvbqUR -6FeSzD4MnMbdyMRoVBeXE88gTvZk8xhB6DJnLzYgc0tKiRoeKT0i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SS8b8EzmNFgyJ3XcjirzwliKTAQtn6 -I2sd0NCIooelrKRD8EJoDUwxoOctY7R97wpZ7/wEHU45cBCbRV3H4JILS5c= ------END RSA PRIVATE KEY----- diff --git a/examples/ssl.rs b/examples/ssl.rs deleted file mode 100644 index d15ed77a..00000000 --- a/examples/ssl.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::io; -use std::sync::{ - atomic::{AtomicUsize, Ordering}, - Arc, -}; - -use actix_rt::System; -use actix_server::{ssl, Server}; -use actix_service::NewService; -use futures_util::future; -use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod}; - -#[derive(Debug)] -struct ServiceState { - num: Arc, -} - -fn main() -> io::Result<()> { - let sys = System::new("test"); - - // load ssl keys - let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap(); - builder - .set_private_key_file("./examples/key.pem", SslFiletype::PEM) - .unwrap(); - builder - .set_certificate_chain_file("./examples/cert.pem") - .unwrap(); - - let num = Arc::new(AtomicUsize::new(0)); - let openssl = ssl::OpensslAcceptor::new(builder.build()); - - // server start mutiple workers, it runs supplied `Fn` in each worker. - Server::build() - .bind("test-ssl", "0.0.0.0:8443", move || { - let num = num.clone(); - - // configure service - openssl - .clone() - .map_err(|e| println!("Openssl error: {}", e)) - .and_then(move |_| { - let num = num.fetch_add(1, Ordering::Relaxed); - println!("got ssl connection {:?}", num); - future::ok(()) - }) - })? - .start(); - - sys.run() -}