Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding overlay to the modules #129

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 2 additions & 22 deletions devbox.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions flmodules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ mode - requesting list of available events from other nodes.
the signalling server.
- `web_proxy` allows sending a http GET request to another node, using the other
node as a proxy.
- `overlay` is an intermediate layer that contains all messages to be implemented
for current and future communication layers.
Currently it's implemented for `random_connections` and `network`.
Future implementations might include a `dht_router` and a `mix_net` communication
layer.

# Adding your own modules

Expand Down
37 changes: 14 additions & 23 deletions flmodules/src/gossip_events/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ use std::sync::mpsc::{channel, Receiver, Sender};

use flarch::{
broker::{Broker, BrokerError, Subsystem, SubsystemHandler},
nodeids::{NodeID, U256}, platform_async_trait,
nodeids::{NodeID, U256},
platform_async_trait,
};

use super::{
core::{Category, Event, EventsStorage},
messages::{Config, GossipEvents, GossipIn, GossipMessage, GossipOut, MessageNode},
messages::{Config, GossipEvents, GossipIn, GossipMessage, GossipOut},
};
use crate::{
random_connections::messages::{ModuleMessage, RandomIn, RandomMessage, RandomOut},
overlay::messages::NetworkWrapper,
random_connections::messages::{RandomIn, RandomMessage, RandomOut},
timer::TimerMessage,
};

Expand All @@ -23,7 +25,7 @@ pub struct GossipBroker {
pub storage: EventsStorage,
/// Represents the underlying broker.
pub broker: Broker<GossipMessage>,
/// Is used to pass the EventsStorage structure from the Transalate to the GossipLink.
/// Is used to pass the EventsStorage structure from the Translate to the GossipLink.
storage_rx: Receiver<EventsStorage>,
}

Expand Down Expand Up @@ -116,16 +118,10 @@ impl Translate {
fn link_rnd_gossip(msg: RandomMessage) -> Option<GossipMessage> {
if let RandomMessage::Output(msg_out) = msg {
match msg_out {
RandomOut::ListUpdate(list) => Some(GossipIn::NodeList(list.into()).into()),
RandomOut::NodeMessageFromNetwork(id, msg) => {
if msg.module == MODULE_NAME {
serde_yaml::from_str::<MessageNode>(&msg.msg)
.ok()
.map(|msg_node| GossipIn::Node(id, msg_node).into())
} else {
None
}
}
RandomOut::NodeIDsConnected(list) => Some(GossipIn::NodeList(list.into()).into()),
RandomOut::NodeMessageFromNetwork(id, msg) => msg
.unwrap_yaml(MODULE_NAME)
.map(|msg| GossipIn::Node(id, msg).into()),
_ => None,
}
} else {
Expand All @@ -138,10 +134,7 @@ impl Translate {
Some(
RandomIn::NodeMessageToNetwork(
id,
ModuleMessage {
module: MODULE_NAME.into(),
msg: serde_yaml::to_string(&msg_node).unwrap(),
},
NetworkWrapper::wrap_yaml(MODULE_NAME, &msg_node).unwrap(),
)
.into(),
)
Expand Down Expand Up @@ -191,6 +184,7 @@ mod tests {
use std::error::Error;

use crate::gossip_events::core::{Category, Event};
use crate::gossip_events::messages::MessageNode;
use flarch::nodeids::NodeID;
use flarch::{start_logging, tasks::now};

Expand All @@ -207,7 +201,7 @@ mod tests {
let id2 = NodeID::rnd();
let (tap_rnd, _) = broker_rnd.get_tap_sync().await?;
broker_rnd
.settle_msg(RandomMessage::Output(RandomOut::ListUpdate(
.settle_msg(RandomMessage::Output(RandomOut::NodeIDsConnected(
vec![id2].into(),
)))
.await?;
Expand All @@ -224,10 +218,7 @@ mod tests {
.settle_msg(
RandomOut::NodeMessageFromNetwork(
id2,
ModuleMessage {
module: MODULE_NAME.into(),
msg: serde_yaml::to_string(&msg).unwrap(),
},
NetworkWrapper::wrap_yaml(MODULE_NAME, &msg).unwrap(),
)
.into(),
)
Expand Down
1 change: 1 addition & 0 deletions flmodules/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ pub mod timer;
pub mod ping;
pub mod web_proxy;
pub mod network;
pub mod overlay;
13 changes: 13 additions & 0 deletions flmodules/src/overlay/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Overlay

Gives an abstraction to allow for different network overlays, e.g., random_connections, dht_network, loopix, and
others. It defines a basic set of messages and a broker, which can then be extended to work with the different
network connection modules.

Two examples are implemented:
- `OverlayRandom` uses the `RandomConnection` broker to handle the network and forwards messages as appropriate
- `OverlayDirect` uses the `Network` broker to handle the network. One problem with this is that the `Connected`
and `Disconnected` messages from the `Network` broker need to be handled here.

To implement a new example who has the `Available`, `Connected`, `Disconnected` messages, the simplest way is to
copy `OverlayRandom` into a new broker.
Loading