diff --git a/message/Cargo.toml b/message/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..651db081ffc014c98cf4872000c37506a5ab4dac --- /dev/null +++ b/message/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "duniter-message" +version = "0.1.0" +authors = ["librelois <elois@duniter.org>"] +description = "message model for the Duniter project." +license = "AGPL-3.0" + +[lib] +path = "lib.rs" + +[dependencies] +duniter-crypto = { path = "../crypto" } +duniter-dal = { path = "../dal" } +duniter-documents = { path = "../documents" } +duniter-module = { path = "../module" } +duniter-network = { path = "../network" } +serde = "1.0.24" +serde_derive = "1.0.24" +serde_json = "1.0.9" \ No newline at end of file diff --git a/message/lib.rs b/message/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..f99560f56c18f75c029bdec43ac648b762d5fdd1 --- /dev/null +++ b/message/lib.rs @@ -0,0 +1,75 @@ +// Copyright (C) 2018 The Duniter Project Developers. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Defined the few global types used by all modules, +//! as well as the DuniterModule trait that all modules must implement. + +#![cfg_attr(feature = "strict", deny(warnings))] +#![deny( + missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts, + trivial_numeric_casts, unsafe_code, unstable_features, unused_import_braces, + unused_qualifications +)] + +extern crate duniter_crypto; +extern crate duniter_dal; +extern crate duniter_documents; +extern crate duniter_module; +extern crate duniter_network; +extern crate serde; +extern crate serde_json; + +use std::sync::mpsc; + +use duniter_crypto::keys::ed25519; +use duniter_dal::dal_event::DALEvent; +use duniter_dal::dal_requests::{DALRequest, DALResponse}; +use duniter_documents::blockchain::BlockchainProtocol; +use duniter_documents::{BlockId, Hash}; +use duniter_module::ModuleMessage; +use duniter_network::{NetworkEvent, NetworkRequest}; + +#[derive(Debug, Clone)] +/// Message exchanged between Duniter-rs modules +pub enum DuniterMessage { + /// Brut text message + Text(String), + /// Brut json message + Json(serde_json::Value), + /// Brut binary message + Binary(Vec<u8>), + /// Subscriptions to the module feed + Followers(Vec<mpsc::Sender<DuniterMessage>>), + /// Blockchain datas request + DALRequest(DALRequest), + /// Response of DALRequest + DALResponse(DALResponse), + /// Blockchain event + DALEvent(DALEvent), + /// Request to the network module + NetworkRequest(NetworkRequest), + /// Network event + NetworkEvent(NetworkEvent), + /// Request to the pow module + ProverRequest(BlockId, Hash), + /// Pow module response + ProverResponse(BlockId, ed25519::Signature, u64), + /// Client API event + ReceiveDocsFromClient(Vec<BlockchainProtocol>), + /// Stop signal + Stop(), +} + +impl ModuleMessage for DuniterMessage {}