https://github.com/sile/erl_dist
Rust Implementation of Erlang Distribution Protocol
https://github.com/sile/erl_dist
asynchronous distributed erlang rust
Last synced: about 1 year ago
JSON representation
Rust Implementation of Erlang Distribution Protocol
- Host: GitHub
- URL: https://github.com/sile/erl_dist
- Owner: sile
- License: mit
- Created: 2016-12-13T18:08:07.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-03-16T02:38:07.000Z (over 1 year ago)
- Last Synced: 2025-05-14T14:40:59.950Z (about 1 year ago)
- Topics: asynchronous, distributed, erlang, rust
- Language: Rust
- Homepage:
- Size: 236 KB
- Stars: 157
- Watchers: 4
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- beamtoolbox - [erl
README
erl_dist
========
[](https://crates.io/crates/erl_dist)
[](https://docs.rs/erl_dist)
[](https://github.com/sile/erl_dist/actions)
[](LICENSE)
Rust Implementation of [Erlang Distribution Protocol](http://erlang.org/doc/apps/erts/erl_dist_protocol.html).
The distribution protocol is used to communicate with distributed erlang nodes.
Examples
---------
Gets a node entry from EPMD:
```rust
use erl_dist::epmd::{DEFAULT_EPMD_PORT, EpmdClient};
// Connect to the local EPMD.
let connection = TcpStream::connect(("localhost", DEFAULT_EPMD_PORT)).await?;
let client = EpmdClient::new(connection);
// Get the information of a node.
let node_name = "foo";
if let Some(node) = client.get_node(node_name).await? {
println!("Found: {:?}", node);
} else {
println!("Not found");
}
```
Sends a message to an Erlang node:
```rust
use erl_dist::LOWEST_DISTRIBUTION_PROTOCOL_VERSION;
use erl_dist::node::{Creation, LocalNode};
use erl_dist::handshake::ClientSideHandshake;
use erl_dist::term::{Atom, Pid};
use erl_dist::message::{channel, Message};
// Connect to a peer node.
let peer_host = "localhost";
let peer_port = 7483; // NOTE: Usually, port number is retrieved from EPMD.
let connection = TcpStream::connect((peer_host, peer_port)).await?;
// Local node information.
let creation = Creation::random();
let local_node = LocalNode::new("foo@localhost".parse()?, creation);
// Do handshake.
let mut handshake = ClientSideHandshake::new(connection, local_node.clone(), "cookie");
let _status = handshake.execute_send_name(LOWEST_DISTRIBUTION_PROTOCOL_VERSION).await?;
let (connection, peer_node) = handshake.execute_rest(true).await?;
// Create a channel.
let capability_flags = local_node.flags & peer_node.flags;
let (mut tx, _) = channel(connection, capability_flags);
// Send a message.
let from_pid = Pid::new(local_node.name.to_string(), 0, 0, local_node.creation.get());
let to_name = Atom::from("bar");
let msg = Message::reg_send(from_pid, to_name, Atom::from("hello").into());
tx.send(msg).await?;
```
Example commands:
- EPMD Client Example: [epmd_cli.rs](examples/epmd_cli.rs)
- Client Node Example: [send_msg.rs](examples/send_msg.rs)
- Server Node Example: [recv_msg.rs](examples/recv_msg.rs)
Related Crates
--------------
- [erl_rpc](https://github.com/sile/erl_rpc): Erlang RPC client for Rust
- [erldash](https://github.com/sile/erldash): Terminal-based Erlang dashboard