This project illustrates a basic implementation of a distributed state management system using Rust. It demonstrates how nodes communicate, propose state changes, and reach a consensus in a distributed network.
The system models a network of nodes where each node can propose changes to its state and achieve consensus with other nodes through a simple protocol. This project aims to provide a foundational understanding of distributed systems, including node interactions, message exchanges, and consensus protocols.
- TCP Node Communication: Establishes TCP connections for nodes to exchange messages.
- Proposal Handling: Nodes can propose state changes and handle proposals from other nodes.
- Acknowledgment System: Processes and tracks acknowledgments for received proposals.
- Consensus Protocol: Uses a majority-based approach to commit proposals once a sufficient number of acknowledgments are received.
- State Updates: Nodes update their state based on proposals and consensus.
To get started with this project, you will need:
- Rust Programming Language: Ensure that Rust is installed on your machine. You can download it from the Rust official site.
-
Clone the Repository:
git clone https://github.com/juliog922/state_machine.git cd state_machine
-
Build the Project:
cargo build
-
Run the Application:
Start the application using:
cargo run
This command initiates two nodes that will simulate proposal broadcasting and consensus.
The project includes the following main components:
-
Node: Represents an individual node in the network. It handles sending and receiving messages, and processes state changes based on proposals.
-
Message: Defines the format of messages exchanged between nodes. This includes proposals, acknowledgments, and commit messages.
-
State: An enumeration describing the possible states a node can be in, such as
Init
,Running
, orStopped
. -
MessageType: An enumeration for different message types like
Proposal
,Acknowledgment
, andCommit
.
To verify the functionality of the system, run the provided tests:
cargo test