This is a template for a Rust project that uses Hydroflow for distributed services. It implements a simple echo server and client over UDP.
cargo generate gh:hydro-project/dfir-templateYou will be prompted to name your project. Once the command completes, you can cd into the project.
Ensure the correct nightly version of rust is installed:
rustup updateThen test the project:
cargo testThe server can be run in one terminal and one or more clients can be run in separate terminals.
% cargo run -- --role serverYou can run multiple instances of the client by running the following command:
% cargo run -- --role clientcargo run -- --helpThe src directory contains the following files:
| File | Description |
|---|---|
main.rs |
Contains main entry-point function for both client and server. Performs command-line argument parsing. |
protocol.rs |
Contains the Message enum that defines the messages that can be sent between instances. |
<role>.rs |
Contains the service for the given role. Example implementations and skeletal hydroflow spec are provided for server and client. |
helpers.rs |
Contains helper functions that are invoked from Hydroflow code in multiple services. |
No particular communication pattern is assumed by Hydroflow. The unmodified template application is designed to be used in a "star topology":
multiple independent clients talking to a single server. However, the template can be easily modified to support other topologies.
Additional examples are provided in the hydroflow repository in the hydroflow/examples directory.
This template is intended to be a starting point for your own project. You'll undoubtedly want to change it.
In our experience, when starting a Hydroflow project we recommend a four-step approach:
- Roles: Identify the roles that your services will play (in the
Optsstruct insrc/main.rs) - Messages: Define the basic message types that services will send to each other (in the
Messageenum insrc/protocol.rs). - Print Received Messages: Utilize the template logic at each service that prints out messages received.
- Exercise Sending Patterns: Make sure the right messages get to the right recipients! Write simple logic to send out messages in all the message patterns you expect to see (in the
src/<role>.rsfiles). - Service Programming: Begin writing the actual logic for each service, with plenty of
inspect(|m| println!("{:?}", m))operators peppered throughout!
Have fun!
The client and server can optionally print out a dataflow graph of their hydroflow code.
Run the following command and view the messages received by the server on stdout.
% cargo run -- --role server --graph mermaidRun the following command and type in the messages to send to the server. When the server responds, the echoed message will be printed on stdout.
% cargo run -- --role client --graph mermaid% cargo run -- --role server --graph dot% cargo run -- --role client --graph dot