Skip to content

Commit

Permalink
One test - 20 to go...
Browse files Browse the repository at this point in the history
  • Loading branch information
ineiti committed Feb 17, 2025
1 parent 5cfcbd8 commit 15b7de8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Here is a list of all testing harnesses and what they do:

- flmodules
- dht_storage::broker - uses NetworkBrokerSimul and creates DHTStorage - very simplistic
- dht_storage::broker - SimulStorage - uses NetworkBrokerSimul and creates DHTStorage - very simplistic
- network
- testing - NetworkBrokerSimul - quite complete, creates RouterNodes
- testing_full - TODO: implement full signal/network/flnode simulation
Expand Down
2 changes: 1 addition & 1 deletion WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- always return a structure
- should it `add_translate` with a `Self::translate...` method, or in-line with `Box::new`?
- make sure no trailing `.into()` for the messages are left
- check that all `add_translate` come in pairs
- check that all `add_translate` come in pairs - use `add_translator_link` instead of pairs
- same functionality:
- structure creates broker and `add_handler` the `message` structure
- `message` structure takes zero or more of: config, DataStorage, `tokio::sync::watch<Stats>` and is a `Subsystem::Handler`
Expand Down
3 changes: 1 addition & 2 deletions flmodules/src/dht_routing/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,9 @@ impl DHTRoutingMessages {
#[platform_async_trait()]
impl SubsystemHandler<InternIn, InternOut> for DHTRoutingMessages {
async fn messages(&mut self, msgs: Vec<InternIn>) -> Vec<InternOut> {
// let id = NodeID::rnd();
let id = self.core.root.clone();
msgs.into_iter()
.inspect(|msg| log::trace!("{}: In: {msg:?}", id))
.inspect(|msg| log::trace!("{}: DHTRoutingIn: {msg:?}", id))
.flat_map(|msg| match msg {
InternIn::Tick => self.tick(),
InternIn::DHTRouting(DHTRoutingIn::MessageBroadcast(msg)) => self
Expand Down
4 changes: 2 additions & 2 deletions flmodules/src/dht_storage/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,12 @@ impl SubsystemHandler<InternIn, InternOut> for MessageHandling {
let id = self.our_id;
inputs
.into_iter()
.inspect(|msg| log::info!("{}: In: {msg:?}", id))
.inspect(|msg| log::debug!("{}: In: {msg:?}", id))
.flat_map(|msg| match msg {
InternIn::Routing(dhtrouting_out) => self.msg_in_routing(dhtrouting_out),
InternIn::Storage(dhtstorage_in) => self.msg_in_storage(dhtstorage_in),
})
// .inspect(|msg| log::trace!("{}: Out: {msg:?}", id))
// .inspect(|msg| log::debug!("{}: Out: {msg:?}", id))
.collect()
}
}
Expand Down
24 changes: 15 additions & 9 deletions flmodules/src/router/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,15 @@ impl RouterDirect {
// A module connected to the Broker<RouterMessage> will get translations of the
// NetworkOut messages, and can send messages to NetworkIn using the Router.
direct
.add_translator_o_to(
.add_translator_o_ti(
b.clone(),
Box::new(|msg| match msg {
NetworkOut::MessageFromNode(id, msg_str) => {
serde_yaml::from_str(&msg_str).ok().map(|module_message| {
FromRouter::NetworkWrapperFromNetwork(id, module_message)
})
Some(RouterInternal::MessageFromNode(id, msg_str).to())
}
NetworkOut::NodeListFromWS(vec) => Some(RouterInternal::Available(vec).from()),
NetworkOut::Connected(id) => Some(RouterInternal::Connected(id).from()),
NetworkOut::Disconnected(id) => Some(RouterInternal::Disconnected(id).from()),
NetworkOut::NodeListFromWS(vec) => Some(RouterInternal::Available(vec).to()),
NetworkOut::Connected(id) => Some(RouterInternal::Connected(id).to()),
NetworkOut::Disconnected(id) => Some(RouterInternal::Disconnected(id).to()),
_ => None,
}),
)
Expand Down Expand Up @@ -128,6 +126,7 @@ impl RouterDirect {
impl SubsystemHandler<ToRouter, FromRouter> for RouterDirect {
async fn messages(&mut self, msgs: Vec<ToRouter>) -> Vec<FromRouter> {
let mut ret = false;
let mut out = vec![];
// Keep track of available and connected / disconnected nodes.
for msg in msgs {
if let ToRouter::Internal(internal) = msg {
Expand All @@ -148,12 +147,17 @@ impl SubsystemHandler<ToRouter, FromRouter> for RouterDirect {
self.nodes_available = vec;
ret = true;
}
RouterInternal::MessageFromNode(id, msg_str) => {
serde_yaml::from_str(&msg_str).ok().map(|module_message| {
out.push(FromRouter::NetworkWrapperFromNetwork(id, module_message))
});
}
}
}
}

// If something changed, output all relevant messages.
if ret {
out.extend(if ret {
vec![
FromRouter::NodeInfoAvailable(self.nodes_available.clone()),
FromRouter::NodeIDsConnected(self.nodes_connected.clone().into()),
Expand All @@ -170,7 +174,9 @@ impl SubsystemHandler<ToRouter, FromRouter> for RouterDirect {
.collect()
} else {
vec![]
}
});

out
}
}

Expand Down
12 changes: 4 additions & 8 deletions flmodules/src/router/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ pub enum FromRouter {
NodeIDsConnected(NodeIDs),
NodeInfosConnected(Vec<NodeInfo>),
NetworkWrapperFromNetwork(NodeID, NetworkWrapper),
Internal(RouterInternal),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub enum RouterInternal {
Connected(U256),
Disconnected(U256),
Available(Vec<NodeInfo>),
MessageFromNode(U256, String),
}

impl NetworkWrapper {
Expand All @@ -49,12 +49,8 @@ impl NetworkWrapper {
}
}

impl RouterInternal{
pub fn to(self) -> ToRouter{
impl RouterInternal {
pub fn to(self) -> ToRouter {
ToRouter::Internal(self)
}

pub fn from(self) -> FromRouter{
FromRouter::Internal(self)
}
}
}
7 changes: 2 additions & 5 deletions flmodules/src/testing/network_broker_simul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ impl NetworkBrokerSimul {
nm_broker.clone(),
Box::new(move |msg| {
let NSHubOut::ToClient(dst, net_msg) = msg;
if dst == nc_id {
return Some(net_msg);
}
None
(dst == nc_id).then_some(net_msg)
}),
)
.await?;
Expand Down Expand Up @@ -104,7 +101,7 @@ impl NetworkBrokerSimul {
.collect();
self.nsh_broker.emit_msg_out(NSHubOut::ToClient(
our_id,
NetworkOut::NodeListFromWS(our_infos.into()),
NetworkOut::NodeListFromWS(our_infos),
))?;
self.nsh_broker.settle(vec![]).await?;
}
Expand Down

0 comments on commit 15b7de8

Please sign in to comment.