Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by mail.sr.ht (Postfix) with ESMTPS id A15804043D for <~qaul/community@lists.sr.ht>; Thu, 24 Oct 2019 16:26:17 +0000 (UTC) Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 46zXgD269jzKmkb for <~qaul/community@lists.sr.ht>; Thu, 24 Oct 2019 18:26:16 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id iMj2g19IdkPa for <~qaul/community@lists.sr.ht>; Thu, 24 Oct 2019 18:26:12 +0200 (CEST) From: Katharina Fey To: ~qaul/community@lists.sr.ht Subject: [PATCH 2/2] Exposing `send` interface on Router structure Date: Thu, 24 Oct 2019 16:26:04 +0000 Message-Id: <20191024162604.7994-2-kookie@spacekookie.de> In-Reply-To: <20191024162604.7994-1-kookie@spacekookie.de> References: <20191024162604.7994-1-kookie@spacekookie.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable --- ratman/netmod/src/frame.rs | 1 + ratman/netmod/src/seq.rs | 1 + ratman/src/core.rs | 15 ++++++------ ratman/src/lib.rs | 49 ++++++++++++++++++++++++++++++++++---- 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/ratman/netmod/src/frame.rs b/ratman/netmod/src/frame.rs index 97e92dc..c832d56 100644 --- a/ratman/netmod/src/frame.rs +++ b/ratman/netmod/src/frame.rs @@ -22,6 +22,7 @@ pub enum Recipient { /// Because a `Frame` is usually created in a sequence, the /// constructors assume chainable operations, such as a `Vec` /// can be returned with all sequence ID information correctly setup. +#[derive(Clone)] pub struct Frame { /// Sender information pub sender: Identity, diff --git a/ratman/netmod/src/seq.rs b/ratman/netmod/src/seq.rs index 456e147..8d9afd6 100644 --- a/ratman/netmod/src/seq.rs +++ b/ratman/netmod/src/seq.rs @@ -23,6 +23,7 @@ pub struct XxSignature { /// was transmitted without error. /// /// Check the `netmod` crate documentation for more details. +#[derive(Clone)] pub struct SeqId { /// A hash signature of the payload pub sig: XxSignature, diff --git a/ratman/src/core.rs b/ratman/src/core.rs index 4792a13..a45bc92 100644 --- a/ratman/src/core.rs +++ b/ratman/src/core.rs @@ -53,13 +53,7 @@ impl Worker { }); }); =20 - ( - Self { - _thread, - to_send, - }, - received, - ) + (Self { _thread, to_send }, received) } } =20 @@ -116,7 +110,12 @@ impl Core { =20 /// Remove a list of interface names and their unique IDs pub(crate) fn get_ifs(&self) -> Vec<(u8, String)> { - vec![] + self.ifs + .lock() + .unwrap() + .keys() + .map(|k| (*k, "".into())) + .collect() } =20 pub(crate) fn id_reachable(&self, id: Identity, ifid: u8) { diff --git a/ratman/src/lib.rs b/ratman/src/lib.rs index 2005134..a6bb571 100644 --- a/ratman/src/lib.rs +++ b/ratman/src/lib.rs @@ -1,5 +1,6 @@ -//! RATMAN decentralised routing protocol +//! `R.A.T.M.A.N.` decentralised routing protocol //! +//! Nananananananana Nananananananana RAT MAN! //! A modern approach to fully delay-tolerant mesh routing, //! implemented network agnostically and entirely in userspace. =20 @@ -15,18 +16,35 @@ pub use crate::{ }; pub use netmod; =20 -use crate::{core::Core, journal::Journal}; -use netmod::Endpoint; +use crate::{ + core::{Core, Envelope}, + journal::Journal, + slicer::Slicer, +}; +use netmod::{Endpoint, Recipient}; +use std::sync::{mpsc::Receiver, Arc, Mutex}; =20 -use std::sync::{Arc, Mutex}; +/// A temporary structure used to initialise a `R.A.T.M.A.N.` `Router` +/// +/// Use this structure only for destructuring, it has no useful +/// attributes beyond named fields. +pub struct RouterInit { + router: Router, + channel: Receiver, +} =20 -/// A `RATMAN` router context +/// A `R.A.T.M.A.N.` routing context +/// +/// Handles `Message` splicing, `Frame` sequencing, routing tables, +/// journal keeping, re-transmissions of non-local frames, as well as +/// the discovery protocol. pub struct Router { core: Arc>, journal: Arc, } =20 impl Router { + /// Create a new `Router` with internal mutability pub fn new() -> Self { let (core, j_rcv) =3D Some(Core::new()) .map(|(c, r)| (Arc::new(Mutex::new(c)), r)) @@ -42,4 +60,25 @@ impl Router { pub fn add_ep(&self, ep: impl Endpoint + 'static + Send) { self.core.lock().unwrap().add_if(ep); } + + /// Queue a `R.A.T.M.A.N.` message for sending + pub fn send(&self, msg: Message) { + // FIXME: This is so pointless... + let recp =3D msg.recipient.clone(); + + let frames =3D Slicer::slice(0, msg); + let core =3D self.core.lock().unwrap(); + + core.send(match recp { + Recipient::User(ref id) =3D> core.lookup(id, frames), + Recipient::Flood =3D> core + .get_ifs() + .into_iter() + .fold(vec![], |mut vec, (ifid, _)| { + let mut set =3D frames.iter().cloned().map(|f| Envel= ope(ifid, f)).collect(); + vec.append(&mut set); + vec + }), + }); + } } --=20 2.23.0