https://github.com/lucab/mitch-rs
mitch: asynchronous membership-gossiping library, based on SWIM/Lifeguard
https://github.com/lucab/mitch-rs
Last synced: 13 days ago
JSON representation
mitch: asynchronous membership-gossiping library, based on SWIM/Lifeguard
- Host: GitHub
- URL: https://github.com/lucab/mitch-rs
- Owner: lucab
- Created: 2018-11-02T15:27:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-07-26T04:16:17.000Z (over 4 years ago)
- Last Synced: 2025-10-27T12:38:58.259Z (4 months ago)
- Language: Rust
- Homepage:
- Size: 64.5 KB
- Stars: 3
- Watchers: 0
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Mitch
[](https://travis-ci.org/lucab/mitch-rs)
[](https://crates.io/crates/mitch)
[](https://docs.rs/mitch)
Asynchronous membership-gossiping library, based on SWIM/Lifeguard.
This crate provides a [tokio]-based swarm membership library, with
gossiping behavior and weak consistency. Its protocol is based on
[SWIM][swim] / [Lifeguard][lifeguard], using protobuf and TLS for
transport.
[tokio]: https://tokio.rs/
[swim]: http://www.cs.cornell.edu/projects/Quicksilver/public_pdfs/SWIM.pdf
[lifeguard]: https://arxiv.org/abs/1707.00788
## Example
```rust
extern crate mitch;
extern crate futures;
extern crate tokio;
use futures::prelude::*;
fn main() {
let mut runner = tokio::runtime::Runtime::new().unwrap();
// Start running a swarm, waiting for other peers to reach us.
let cfg = mitch::MitchConfig::default();
let fut_swarm = cfg.build();
let swarm = runner.block_on(fut_swarm).unwrap();
// Snapshot and print swarm members every 5 secs.
let membership = futures::stream::repeat(swarm.membership());
let period = std::time::Duration::from_secs(5);
let fut_snapshot = tokio::timer::Interval::new_interval(period)
.from_err()
.zip(membership)
.and_then(move |(_, mems)| mems.snapshot())
.map_err(|_| ())
.for_each(|mems| Ok(println!(" * Swarm members: {:#?}", mems)));
runner.spawn(fut_snapshot);
// Keep running for 45 secs.
let delay = std::time::Instant::now() + std::time::Duration::from_secs(45);
let fut_stop = swarm.stop();
let fut_delayed_stop = tokio::timer::Delay::new(delay)
.map_err(|e| format!("{}", e).into())
.and_then(|_| fut_stop);
runner.block_on_all(fut_delayed_stop);
}
```
Some more examples are available under [examples](examples).
## License
Licensed under either of
* MIT license -
* Apache License, Version 2.0 -
at your option.