8 个版本 (5 个破坏性更新)

0.6.0 2023 年 6 月 16 日
0.5.1 2022 年 4 月 3 日
0.4.0 2022 年 4 月 2 日
0.3.0 2022 年 3 月 23 日
0.1.0 2016 年 12 月 20 日

#549异步

Download history 136/week @ 2024-03-11 146/week @ 2024-03-18 65/week @ 2024-03-25 123/week @ 2024-04-01 78/week @ 2024-04-08 57/week @ 2024-04-15 123/week @ 2024-04-22 176/week @ 2024-04-29 96/week @ 2024-05-06 104/week @ 2024-05-13 213/week @ 2024-05-20 57/week @ 2024-05-27 122/week @ 2024-06-03 70/week @ 2024-06-10 44/week @ 2024-06-17 111/week @ 2024-06-24

每月 349 次下载
用于 2 crate

MIT 许可证

125KB
3K SLoC

erl_dist

erl_dist Documentation Actions Status Coverage Status License: MIT

Rust 实现 Erlang 分布式协议

该分布式协议用于与分布式 Erlang 节点通信。

示例

从 EPMD 获取节点条目

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");
}

向 Erlang 节点发送消息

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?;

示例命令

  • erl_rpc: Rust 的 Erlang RPC 客户端
  • erldash: 基于终端的 Erlang 仪表板

依赖关系

~2.3–3MB
~63K SLoC