| Crates.io | flmodules |
| lib.rs | flmodules |
| version | 0.9.2 |
| created_at | 2022-07-05 18:29:41.096864+00 |
| updated_at | 2025-03-17 06:01:25.958426+00 |
| description | Modules used in fledger |
| homepage | https://fledg.re |
| repository | https://github.com/ineiti/fledger |
| max_upload_size | |
| id | 619950 |
| size | 437,096 |
This crate holds the raw modules for Fledger. They are written in a way to be as reusable as possible. For this, most modules have the following structure:
broker.rs - which contains the code to interact with the other modulesmodule.rs - with the main code of the module, with at least a process_msg method
that inputs a message and outputs a vector of answerscore.rs - implementing the basic functionality of the module.The following modules are available:
random_connections to send regular messages to the connected nodes
to make sure they answer. If a node doesn't answer in due time, a failure message
is emitted.random_connections and network.This is the dependencies between the different modules:
Signal is the root of all control
Network sets up its connections using Signal
RandomConnection uses the Network to set up connectionsRouter is an abstraction of the Network or the RandomConnection
DHT_Router uses Router
DHT_Storage uses DHT_RouterWebProxy uses RouterAs described in the previous section, you should write your modules in three parts:
Core Logic: persistent data, configuration, methods. This part does not handle any messages to/from the system, but only provides the actual algorithm. This might include cryptographic calculations, caching, updating, and other tasks necessary for the functionality. Write it in a way that it can also be used by a non-fledger project. If possible, no async should be used in this implementation.
Message Handling: create all messages that this module should receive or send during its lifetime. All messages defined here must be self-contained: this part must not depend directly on any other module's message definitions.
Translation: this part defines the interactions with the other modules.
This is mostly done with defining translator methods which take incoming messages
and output messges for this module.
Testing your new module should be done in three steps:
Write tests for the core logic.
Make sure that all the necessary logic functions as it should.
Test edge-cases, and add more tests as the core logic expands.
The Message Handling part should be as simple as possible, and as
much of the logic should be here.
Then go on to test the Message Handling part.
Create multiple objects of the structure, and let them interact using
simple simulators.
In this stage, it might be enough to do all message-passing manually,
so you have full control over what is going on.
This also helps to test edge-cases, because it allows you to 'delay' messages
artificially between modules.
At the very end should you start implementing the more end-to-end tests. As a first step it is good to use the router simulator in router_simul. It abstracts the router in a useful way, while still allowing you to have some control of the message flow. Depending on what you're doing, it might also be worth using the full_simul which has an as-close-as-possible simulation of all the messages.
Once all these tests work, you can do real tests with the binaries and set them up to use a signalling server.