Added tutorial on how to send/receive message with 2 mycelium peers running the same host
Some checks failed
Rhai Tests / Run Rhai Tests (pull_request) Has been cancelled
Some checks failed
Rhai Tests / Run Rhai Tests (pull_request) Has been cancelled
This commit is contained in:
parent
771df07c25
commit
7b8b8c662e
@ -329,4 +329,60 @@ try {
|
||||
} catch(err) {
|
||||
print(`Error sending message: ${err}`);
|
||||
}
|
||||
```
|
||||
```
|
||||
|
||||
### Example: setting up 2 different Mycelium peers on same the host and sending/receiving a message
|
||||
|
||||
#### Obtain Mycelium
|
||||
|
||||
- Download the latest Mycelium binary from https://github.com/threefoldtech/mycelium/releases/
|
||||
- Or compile from source
|
||||
|
||||
#### Setup
|
||||
> `cd myceliumd && cargo build`
|
||||
|
||||
- Create two different private key files. Each key file should contain exactely 32 bytes. In this example we'll save these files as `sender.bin` and `receiver.bin`. Note: generate your own 32-byte key files, the values below are just used as examples.
|
||||
> `echo '9f3d72c1a84be6f027bba94cde015ee839cedb2ac4f2822bfc94449e3e2a1c6a' > sender.bin`
|
||||
|
||||
> `echo 'e81c5a76f42bd9a3c73fe0bb2196acdfb6348e99d0b01763a2e57ce3a4e8f5dd' > receiver.bin`
|
||||
|
||||
#### Start the nodes
|
||||
- **Sender**: this node will have the API server hosted on `127.0.0.1:1111` and the JSON-RPC server on `127.0.0.1:8991`.
|
||||
> `sudo ./mycelium --key-file sender.bin --disable-peer-discovery --disable-quic --no-tun --api-addr 127.0.0.1:1111 --jsonrpc-addr 127.0.0.1:8991`
|
||||
|
||||
- **Receiver**: this node will have the API server hosted on `127.0.0.1:2222` and the JSON-RPC server on `127.0.0.1:8992`.
|
||||
> `sudo ./mycelium --key-file receiver.bin --disable-peer-discovery --disable-quic --no-tun --api-addr 127.0.0.1:2222 --jsonrpc-addr 127.0.0.1:8992 --peers tcp://<UNDERLAY_IP_SENDER>:9651`
|
||||
- Obtain the Mycelium overlay IP by running `./mycelium --key-file receiver.bin --api-addr 127.0.0.1:2222 inspect`. **Replace this IP as destination in the [mycelium_receive_message.rhai](../../../examples/mycelium/mycelium_receive_message.rhai) example**.
|
||||
|
||||
#### Execute the examples
|
||||
- First build by executing `./build_herdo.sh` from the SAL root directory
|
||||
- `cd target/debug`
|
||||
|
||||
- Run the sender script: `sudo ./herodo --path ../../examples/mycelium/mycelium_send_message.rhai`
|
||||
```
|
||||
Executing: ../../examples/mycelium/mycelium_send_message.rhai
|
||||
|
||||
Sending a message:
|
||||
Attempting to send message to 50e:6d75:4568:366e:f75:2ac3:bbb1:3fdd on topic 'test_topic'
|
||||
result: #{"id": "bfd47dc689a7b826"}
|
||||
Message sent:
|
||||
Message ID: bfd47dc689a7b826
|
||||
Script executed successfull
|
||||
```
|
||||
|
||||
- Run the receiver script: `sudo ./herodo --path ../../examples/mycelium/mycelium_receive_message.rhai`
|
||||
```
|
||||
Executing: ../../examples/mycelium/mycelium_receive_message.rhai
|
||||
|
||||
Receiving messages:
|
||||
Listening for messages on topic 'test_topic'...
|
||||
Received a message:
|
||||
Message id: bfd47dc689a7b826
|
||||
Message from: 45d:26e1:a413:9d08:80ce:71c6:a931:4315
|
||||
Topic: dGVzdF90b3BpYw==
|
||||
Payload: SGVsbG8gZnJvbSBSaGFpIHNlbmRlciE=
|
||||
Finished attempting to receive messages.
|
||||
Script executed successfully
|
||||
```
|
||||
> Decoding the payload `SGVsbG8gZnJvbSBSaGFpIHNlbmRlciE=` results in the expected `Hello from Rhai sender!` message. Mission succesful!
|
||||
|
||||
|
@ -7,7 +7,7 @@ let api_url = "http://localhost:1111";
|
||||
// TO SEND A MESSAGE FILL IN THE DESTINATION IP ADDRESS
|
||||
// -----------------------------------------------------//
|
||||
print("\nSending a message:");
|
||||
let destination = "5af:ae6b:dcd8:ffdb:b71:7dde:d3:1033"; // IMPORTANT: Replace with the actual destination IP address
|
||||
let destination = "50e:6d75:4568:366e:f75:2ac3:bbb1:3fdd"; // IMPORTANT: Replace with the actual destination IP address
|
||||
let topic = "test_topic";
|
||||
let message = "Hello from Rhai sender!";
|
||||
let deadline_secs = -10; // Seconds we wait for a reply
|
||||
|
Loading…
Reference in New Issue
Block a user