From a36f94c6812f049324b1f9da62b2735b224635e3 Mon Sep 17 00:00:00 2001 From: Ben Bangert Date: Wed, 13 Feb 2019 13:40:05 -0800 Subject: [PATCH] refactor: split connection node from common for later endpoint Closes #99 --- Cargo.lock => autopush-common/Cargo.lock | 14 ++-- Cargo.toml => autopush-common/Cargo.toml | 30 ++------- {src => autopush-common/src}/db/commands.rs | 0 {src => autopush-common/src}/db/macros.rs | 0 {src => autopush-common/src}/db/mod.rs | 24 +++---- {src => autopush-common/src}/db/models.rs | 0 {src => autopush-common/src}/db/util.rs | 0 {src => autopush-common/src}/errors.rs | 0 autopush-common/src/lib.rs | 16 +++++ {src => autopush-common/src}/logging.rs | 0 {src => autopush-common/src}/protocol.rs | 0 .../src}/util/megaphone.rs | 0 {src => autopush-common/src}/util/mod.rs | 0 {src => autopush-common/src}/util/rc.rs | 0 {src => autopush-common/src}/util/send_all.rs | 0 {src => autopush-common/src}/util/timing.rs | 0 .../src}/util/user_agent.rs | 0 {src => autopush/src}/client.rs | 40 ++++++------ {src => autopush/src}/http.rs | 0 {src => autopush/src}/main.rs | 18 ++++-- {src => autopush/src}/server/dispatch.rs | 3 +- {src => autopush/src}/server/metrics.rs | 3 +- {src => autopush/src}/server/mod.rs | 31 +++++---- {src => autopush/src}/server/tls.rs | 2 +- {src => autopush/src}/server/webpush_io.rs | 0 {src => autopush/src}/settings.rs | 0 src/lib.rs | 64 ------------------- 27 files changed, 93 insertions(+), 152 deletions(-) rename Cargo.lock => autopush-common/Cargo.lock (99%) rename Cargo.toml => autopush-common/Cargo.toml (58%) rename {src => autopush-common/src}/db/commands.rs (100%) rename {src => autopush-common/src}/db/macros.rs (100%) rename {src => autopush-common/src}/db/mod.rs (96%) rename {src => autopush-common/src}/db/models.rs (100%) rename {src => autopush-common/src}/db/util.rs (100%) rename {src => autopush-common/src}/errors.rs (100%) create mode 100644 autopush-common/src/lib.rs rename {src => autopush-common/src}/logging.rs (100%) rename {src => autopush-common/src}/protocol.rs (100%) rename {src => autopush-common/src}/util/megaphone.rs (100%) rename {src => autopush-common/src}/util/mod.rs (100%) rename {src => autopush-common/src}/util/rc.rs (100%) rename {src => autopush-common/src}/util/send_all.rs (100%) rename {src => autopush-common/src}/util/timing.rs (100%) rename {src => autopush-common/src}/util/user_agent.rs (100%) rename {src => autopush/src}/client.rs (97%) rename {src => autopush/src}/http.rs (100%) rename {src => autopush/src}/main.rs (85%) rename {src => autopush/src}/server/dispatch.rs (99%) rename {src => autopush/src}/server/metrics.rs (96%) rename {src => autopush/src}/server/mod.rs (98%) rename {src => autopush/src}/server/tls.rs (99%) rename {src => autopush/src}/server/webpush_io.rs (100%) rename {src => autopush/src}/settings.rs (100%) delete mode 100644 src/lib.rs diff --git a/Cargo.lock b/autopush-common/Cargo.lock similarity index 99% rename from Cargo.lock rename to autopush-common/Cargo.lock index 321394ba0..8b8f3e5ed 100644 --- a/Cargo.lock +++ b/autopush-common/Cargo.lock @@ -90,7 +90,7 @@ dependencies = [ "sentry 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_dynamodb 0.2.0 (git+https://github.com/mockersf/serde_dynamodb?rev=240974d591466c4f9a0831162a28d690f2f6e51a)", + "serde_dynamodb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -192,7 +192,7 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.7.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1824,8 +1824,8 @@ dependencies = [ [[package]] name = "serde_dynamodb" -version = "0.2.0" -source = "git+https://github.com/mockersf/serde_dynamodb?rev=240974d591466c4f9a0831162a28d690f2f6e51a#240974d591466c4f9a0831162a28d690f2f6e51a" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rusoto_dynamodb 0.36.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1865,7 +1865,7 @@ name = "sha-1" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-buffer 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2629,7 +2629,7 @@ dependencies = [ "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" "checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" -"checksum block-buffer 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "509de513cca6d92b6aacf9c61acfe7eaa160837323a81068d690cc1f8e5740da" +"checksum block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49665c62e0e700857531fa5d3763e91b539ff1abeebd56808d378b495870d60d" "checksum block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d75255892aeb580d3c566f213a2b6fdc1c66667839f45719ee1d30ebf2aea591" "checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" @@ -2809,7 +2809,7 @@ dependencies = [ "checksum serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)" = "2e20fde37801e83c891a2dc4ebd3b81f0da4d1fb67a9e0a2a3b921e2536a58ee" "checksum serde-hjson 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0b833c5ad67d52ced5f5938b2980f32a9c1c5ef047f0b4fb3127e7a423c76153" "checksum serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)" = "633e97856567e518b59ffb2ad7c7a4fd4c5d91d9c7f32dd38a27b2bf7e8114ea" -"checksum serde_dynamodb 0.2.0 (git+https://github.com/mockersf/serde_dynamodb?rev=240974d591466c4f9a0831162a28d690f2f6e51a)" = "" +"checksum serde_dynamodb 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "86410cc410a4b31b7df3f9d24e301c031690ee692ff697726d7edcb8fde9cdc9" "checksum serde_json 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "27dce848e7467aa0e2fcaf0a413641499c0b745452aaca1194d24dedde9e13c9" "checksum serde_test 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "110b3dbdf8607ec493c22d5d947753282f3bae73c0f56d322af1e8c78e4c23d5" "checksum serde_urlencoded 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d48f9f99cd749a2de71d29da5f948de7f2764cc5a9d7f3c97e3514d4ee6eabf2" diff --git a/Cargo.toml b/autopush-common/Cargo.toml similarity index 58% rename from Cargo.toml rename to autopush-common/Cargo.toml index 0da296cf4..5dffe0e95 100644 --- a/Cargo.toml +++ b/autopush-common/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "autopush" -version = "1.53.0" +name = "autopush_common" +version = "1.0.0" authors = [ "Ben Bangert ", "JR Conlin ", @@ -10,35 +10,20 @@ authors = [ edition = "2018" [lib] -name = "autopush" - -[[bin]] -name = "autopush_rs" -path = "src/main.rs" +name = "autopush_common" [dependencies] -base64 = "0.10.0" -bytes = "0.4.11" cadence = "0.16.0" -chan-signal = "0.3.2" chrono = "0.4.6" config = "0.9.2" -docopt = "1.0.2" -env_logger = { version = "0.6.0", default-features = false } error-chain = "0.12.0" -fernet = "0.1.0" futures = "0.1.25" futures-backoff = "0.1.0" -hex = "0.3.2" httparse = "1.3.3" # XXX: pin to hyper 0.11 for now: 0.12 has many changes.. hyper = "0.11.27" lazy_static = "1.2.0" -libc = "0.2.46" -log = { version = "0.4.6", features = ["max_level_info", "release_max_level_info"] } -matches = "0.1.8" mozsvc-common = "0.1.0" -openssl = "0.10.16" rand = "0.6.3" regex = "1.1.0" reqwest = "0.9.5" @@ -48,7 +33,7 @@ rusoto_dynamodb = "0.36.0" sentry = { version = "0.13.0", features = ["with_error_chain"] } serde = "1.0.84" serde_derive = "1.0.84" -serde_dynamodb = { git = "https://github.com/mockersf/serde_dynamodb", rev = "240974d591466c4f9a0831162a28d690f2f6e51a" } +serde_dynamodb = "0.2.1" serde_json = "1.0.34" slog = { version = "2.4.1", features = ["max_level_trace", "release_max_level_info"] } slog-async = "2.3.0" @@ -56,14 +41,7 @@ slog-term = "2.4.0" slog-mozlog-json = "0.1.0" slog-scope = "4.1.1" slog-stdlog = "3.0.2" -# state_machine_future = { version = "0.1.6", features = ["debug_code_generation"] } -state_machine_future = "0.2.0" -time = "0.1.41" tokio-core = "0.1.17" -tokio-io = "0.1.10" -tokio-openssl = "0.3.0" -tokio-service = "0.1.0" -tokio-tungstenite = { version = "0.6.0", default-features = false } tungstenite = { version = "0.6.1", default-features = false } uuid = { version = "0.7.1", features = ["serde", "v4"] } # XXX: pin woothee until >= 0.8.1 diff --git a/src/db/commands.rs b/autopush-common/src/db/commands.rs similarity index 100% rename from src/db/commands.rs rename to autopush-common/src/db/commands.rs diff --git a/src/db/macros.rs b/autopush-common/src/db/macros.rs similarity index 100% rename from src/db/macros.rs rename to autopush-common/src/db/macros.rs diff --git a/src/db/mod.rs b/autopush-common/src/db/mod.rs similarity index 96% rename from src/db/mod.rs rename to autopush-common/src/db/mod.rs index dcfdd3ceb..38c3fbbc8 100644 --- a/src/db/mod.rs +++ b/autopush-common/src/db/mod.rs @@ -22,7 +22,6 @@ mod util; use crate::errors::*; use crate::protocol::Notification; -use crate::server::{Server, ServerOptions}; use crate::util::timing::sec_since_epoch; use self::commands::{ @@ -58,7 +57,6 @@ pub struct CheckStorageResponse { pub enum RegisterResponse { Success { endpoint: String }, - Error { error_msg: String, status: u32 }, } @@ -71,7 +69,11 @@ pub struct DynamoStorage { } impl DynamoStorage { - pub fn from_opts(opts: &ServerOptions, metrics: StatsdClient) -> Result { + pub fn from_opts( + message_table_name: &str, + router_table_name: &str, + metrics: StatsdClient, + ) -> Result { let ddb: Box = if let Ok(endpoint) = env::var("AWS_LOCAL_DYNAMODB") { Box::new(DynamoDbClient::new_with( HttpClient::new().chain_err(|| "TLS initialization error")?, @@ -86,7 +88,7 @@ impl DynamoStorage { }; let ddb = Rc::new(ddb); - let mut message_table_names = list_message_tables(&ddb, &opts._message_table_name) + let mut message_table_names = list_message_tables(&ddb, &message_table_name) .map_err(|_| "Failed to locate message tables")?; // Valid message months are the current and last 2 months message_table_names.sort_unstable_by(|a, b| b.cmp(a)); @@ -100,7 +102,7 @@ impl DynamoStorage { Ok(Self { ddb, metrics: Rc::new(metrics), - router_table_name: opts._router_table_name.clone(), + router_table_name: router_table_name.to_owned(), message_table_names, current_message_month, }) @@ -194,23 +196,15 @@ impl DynamoStorage { pub fn register( &self, - srv: &Rc, uaid: &Uuid, channel_id: &Uuid, message_month: &str, + endpoint: &str, key: Option, ) -> MyFuture { let ddb = self.ddb.clone(); - let endpoint = match srv.make_endpoint(uaid, channel_id, key) { - Ok(result) => result, - Err(_) => { - return Box::new(future::ok(RegisterResponse::Error { - error_msg: "Failed to generate endpoint".to_string(), - status: 400, - })); - } - }; let mut chids = HashSet::new(); + let endpoint = endpoint.to_owned(); chids.insert(channel_id.to_hyphenated().to_string()); let response = commands::save_channels(ddb, uaid, chids, message_month) .and_then(move |_| future::ok(RegisterResponse::Success { endpoint })) diff --git a/src/db/models.rs b/autopush-common/src/db/models.rs similarity index 100% rename from src/db/models.rs rename to autopush-common/src/db/models.rs diff --git a/src/db/util.rs b/autopush-common/src/db/util.rs similarity index 100% rename from src/db/util.rs rename to autopush-common/src/db/util.rs diff --git a/src/errors.rs b/autopush-common/src/errors.rs similarity index 100% rename from src/errors.rs rename to autopush-common/src/errors.rs diff --git a/autopush-common/src/lib.rs b/autopush-common/src/lib.rs new file mode 100644 index 000000000..c4ef57e86 --- /dev/null +++ b/autopush-common/src/lib.rs @@ -0,0 +1,16 @@ +#![recursion_limit = "1024"] + +#[macro_use] +extern crate error_chain; +#[macro_use] +extern crate slog; +#[macro_use] +extern crate slog_scope; + +#[macro_use] +pub mod db; +pub mod errors; +pub mod logging; +pub mod protocol; +#[macro_use] +pub mod util; diff --git a/src/logging.rs b/autopush-common/src/logging.rs similarity index 100% rename from src/logging.rs rename to autopush-common/src/logging.rs diff --git a/src/protocol.rs b/autopush-common/src/protocol.rs similarity index 100% rename from src/protocol.rs rename to autopush-common/src/protocol.rs diff --git a/src/util/megaphone.rs b/autopush-common/src/util/megaphone.rs similarity index 100% rename from src/util/megaphone.rs rename to autopush-common/src/util/megaphone.rs diff --git a/src/util/mod.rs b/autopush-common/src/util/mod.rs similarity index 100% rename from src/util/mod.rs rename to autopush-common/src/util/mod.rs diff --git a/src/util/rc.rs b/autopush-common/src/util/rc.rs similarity index 100% rename from src/util/rc.rs rename to autopush-common/src/util/rc.rs diff --git a/src/util/send_all.rs b/autopush-common/src/util/send_all.rs similarity index 100% rename from src/util/send_all.rs rename to autopush-common/src/util/send_all.rs diff --git a/src/util/timing.rs b/autopush-common/src/util/timing.rs similarity index 100% rename from src/util/timing.rs rename to autopush-common/src/util/timing.rs diff --git a/src/util/user_agent.rs b/autopush-common/src/util/user_agent.rs similarity index 100% rename from src/util/user_agent.rs rename to autopush-common/src/util/user_agent.rs diff --git a/src/client.rs b/autopush/src/client.rs similarity index 97% rename from src/client.rs rename to autopush/src/client.rs index 81e2b640f..6171cb0cb 100644 --- a/src/client.rs +++ b/autopush/src/client.rs @@ -1,14 +1,4 @@ //! Management of connected clients to a WebPush server -//! -//! This module is a pretty heavy work in progress. The intention is that -//! this'll house all the various state machine transitions and state management -//! of connected clients. Note that it's expected there'll be a lot of connected -//! clients, so this may appears relatively heavily optimized! -use std::cell::RefCell; -use std::mem; -use std::rc::Rc; -use std::time::Duration; - use cadence::{prelude::*, StatsdClient}; use error_chain::ChainedError; use futures::future::Either; @@ -22,16 +12,21 @@ use rusoto_dynamodb::UpdateItemOutput; use sentry; use sentry::integrations::error_chain::event_from_error_chain; use state_machine_future::{transition, RentToOwn, StateMachineFuture}; +use std::cell::RefCell; +use std::mem; +use std::rc::Rc; +use std::time::Duration; use tokio_core::reactor::Timeout; use uuid::Uuid; use woothee::parser::Parser; -use crate::db::{CheckStorageResponse, HelloResponse, RegisterResponse}; -use crate::errors::*; -use crate::protocol::{ClientMessage, Notification, ServerMessage, ServerNotification}; +use autopush_common::db::{CheckStorageResponse, HelloResponse, RegisterResponse}; +use autopush_common::errors::*; +use autopush_common::protocol::{ClientMessage, Notification, ServerMessage, ServerNotification}; +use autopush_common::util::megaphone::{Broadcast, BroadcastSubs}; +use autopush_common::util::{ms_since_epoch, parse_user_agent, sec_since_epoch}; + use crate::server::Server; -use crate::util::megaphone::{Broadcast, BroadcastSubs}; -use crate::util::{ms_since_epoch, parse_user_agent, sec_since_epoch}; // Created and handed to the AutopushServer pub struct RegisteredClient { @@ -862,10 +857,17 @@ where let uaid = webpush.uaid; let message_month = webpush.message_month.clone(); let srv = data.srv.clone(); - let fut = data - .srv - .ddb - .register(&srv, &uaid, &channel_id, &message_month, key); + let fut = match srv.make_endpoint(&uaid, &channel_id, key.clone()) { + Ok(endpoint) => { + data.srv + .ddb + .register(&uaid, &channel_id, &message_month, &endpoint, key) + } + Err(_) => Box::new(future::ok(RegisterResponse::Error { + error_msg: "Failed to generate endpoint".to_string(), + status: 400, + })), + }; transition!(AwaitRegister { channel_id, response: fut, diff --git a/src/http.rs b/autopush/src/http.rs similarity index 100% rename from src/http.rs rename to autopush/src/http.rs diff --git a/src/main.rs b/autopush/src/main.rs similarity index 85% rename from src/main.rs rename to autopush/src/main.rs index c6932d1b0..f53172048 100644 --- a/src/main.rs +++ b/autopush/src/main.rs @@ -1,16 +1,24 @@ #[macro_use] +extern crate slog; +#[macro_use] +extern crate slog_scope; +#[macro_use] extern crate serde_derive; -use chan_signal; - use std::env; use chan_signal::Signal; use docopt::Docopt; -use autopush::errors::{Result, ResultExt}; -use autopush::server::{AutopushServer, ServerOptions}; -use autopush::settings::Settings; +use autopush_common::errors::{Result, ResultExt}; + +mod client; +mod http; +mod server; +mod settings; + +use crate::server::{AutopushServer, ServerOptions}; +use crate::settings::Settings; const USAGE: &'static str = " Usage: autopush_rs [options] diff --git a/src/server/dispatch.rs b/autopush/src/server/dispatch.rs similarity index 99% rename from src/server/dispatch.rs rename to autopush/src/server/dispatch.rs index 083947049..36742c7fe 100644 --- a/src/server/dispatch.rs +++ b/autopush/src/server/dispatch.rs @@ -27,7 +27,8 @@ use httparse; use tokio_core::net::TcpStream; use tokio_io::AsyncRead; -use crate::errors::*; +use autopush_common::errors::*; + use crate::server::tls::MaybeTlsStream; use crate::server::webpush_io::WebpushIo; diff --git a/src/server/metrics.rs b/autopush/src/server/metrics.rs similarity index 96% rename from src/server/metrics.rs rename to autopush/src/server/metrics.rs index a58391031..f6ba7deb4 100644 --- a/src/server/metrics.rs +++ b/autopush/src/server/metrics.rs @@ -4,7 +4,8 @@ use std::net::UdpSocket; use cadence::{BufferedUdpMetricSink, NopMetricSink, QueuingMetricSink, StatsdClient}; -use crate::errors::*; +use autopush_common::errors::*; + use crate::server::ServerOptions; /// Create a cadence StatsdClient from the given options diff --git a/src/server/mod.rs b/autopush/src/server/mod.rs similarity index 98% rename from src/server/mod.rs rename to autopush/src/server/mod.rs index 6bd5dc18b..7903968fd 100644 --- a/src/server/mod.rs +++ b/autopush/src/server/mod.rs @@ -33,23 +33,24 @@ use tungstenite::handshake::server::Request; use tungstenite::Message; use uuid::Uuid; -use crate::client::{Client, RegisteredClient}; -use crate::db::DynamoStorage; -use crate::errors::*; -use crate::errors::{Error, Result}; -use crate::http; -use crate::logging; -use crate::protocol::{ +use autopush_common::db::DynamoStorage; +use autopush_common::errors::*; +use autopush_common::errors::{Error, Result}; +use autopush_common::logging; +use autopush_common::protocol::{ BroadcastValue, ClientMessage, Notification, ServerMessage, ServerNotification, }; +use autopush_common::util::megaphone::{ + Broadcast, BroadcastChangeTracker, BroadcastSubs, BroadcastSubsInit, MegaphoneAPIResponse, +}; +use autopush_common::util::{timeout, RcObject}; + +use crate::client::{Client, RegisteredClient}; +use crate::http; use crate::server::dispatch::{Dispatch, RequestType}; use crate::server::metrics::metrics_from_opts; use crate::server::webpush_io::WebpushIo; use crate::settings::Settings; -use crate::util::megaphone::{ - Broadcast, BroadcastChangeTracker, BroadcastSubs, BroadcastSubsInit, MegaphoneAPIResponse, -}; -use crate::util::{timeout, RcObject}; mod dispatch; mod metrics; @@ -294,7 +295,11 @@ impl Server { let srv = Rc::new(Server { opts: opts.clone(), broadcaster: RefCell::new(broadcaster), - ddb: DynamoStorage::from_opts(opts, metrics.clone())?, + ddb: DynamoStorage::from_opts( + &opts._message_table_name, + &opts._router_table_name, + metrics.clone(), + )?, uaids: RefCell::new(HashMap::new()), open_connections: Cell::new(0), handle: core.handle(), @@ -963,7 +968,7 @@ pub fn write_version_file(socket: WebpushIo) -> MyFuture<()> { write_json( socket, StatusCode::Ok, - serde_json::Value::from(include_str!("../../version.json")), + serde_json::Value::from(include_str!("../../../version.json")), ) } diff --git a/src/server/tls.rs b/autopush/src/server/tls.rs similarity index 99% rename from src/server/tls.rs rename to autopush/src/server/tls.rs index 59da55cdc..0ce95bef9 100644 --- a/src/server/tls.rs +++ b/autopush/src/server/tls.rs @@ -10,6 +10,7 @@ use std::io::{self, Read, Write}; use std::path::Path; use std::rc::Rc; +use autopush_common::errors::*; use futures::future; use futures::{Future, Poll}; use openssl::dh::Dh; @@ -20,7 +21,6 @@ use tokio_core::net::TcpStream; use tokio_io::{AsyncRead, AsyncWrite}; use tokio_openssl::{SslAcceptorExt, SslStream}; -use crate::errors::*; use crate::server::{Server, ServerOptions}; /// Creates an `SslAcceptor`, if needed, ready to accept TLS connections. diff --git a/src/server/webpush_io.rs b/autopush/src/server/webpush_io.rs similarity index 100% rename from src/server/webpush_io.rs rename to autopush/src/server/webpush_io.rs diff --git a/src/settings.rs b/autopush/src/settings.rs similarity index 100% rename from src/settings.rs rename to autopush/src/settings.rs diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 1babcc921..000000000 --- a/src/lib.rs +++ /dev/null @@ -1,64 +0,0 @@ -//! WIP: Implementation of Web Push ("autopush" as well) in Rust -//! -//! This crate currently provides the connection node functionality for a Web -//! Push server, and is a replacement for the -//! [`autopush`](https://github.com/mozilla-services/autopush) server. The older -//! python handler still manages the HTTP endpoint calls, since those require -//! less overhead to process. Eventually, those functions will be moved to -//! rust as well. -//! -//! # High level overview -//! -//! The entire server is written in an asynchronous fashion using the `futures` -//! crate in Rust. This basically just means that everything is exposed as a -//! future (similar to the concept in other languages) and that's how bits and -//! pieces are chained together. -//! -//! Each connected client maintains a state machine of where it is in the -//! webpush protocol (see `states.dot` at the root of this repository). Note -//! that not all states are implemented yet, this is a work in progress! All I/O -//! is managed by Rust and various state transitions are managed by Rust as -//! well. -//! -//! # Module index -//! -//! There's a number of modules that currently make up the Rust implementation, -//! and one-line summaries of these are: -//! -//! * `queue` - a MPMC queue which is used to send messages to Python and Python -//! uses to delegate work to worker threads. -//! * `server` - the main bindings for the WebPush server, where the tokio -//! `Core` is created and managed inside of the Rust thread. -//! * `client` - this is where the state machine for each connected client is -//! located, managing connections over time and sending out notifications as -//! they arrive. -//! * `protocol` - a definition of the Web Push protocol messages which are send -//! over websockets. -//! * `call` - definitions of various calls that can be made into Python, each -//! of which returning a future of the response. -//! -//! Other modules tend to be miscellaneous implementation details and likely -//! aren't as relevant to the Web Push implementation. -//! -//! Otherwise be sure to check out each module for more documentation! -// `error_chain!` can recurse deeply -#![recursion_limit = "1024"] - -#[macro_use] -extern crate error_chain; -#[macro_use] -extern crate slog; -#[macro_use] -extern crate slog_scope; - -#[macro_use] -mod db; -mod client; -pub mod errors; -mod http; -mod logging; -mod protocol; -pub mod server; -pub mod settings; -#[macro_use] -mod util;