Crates.io | aether_lib |
lib.rs | aether_lib |
version | 0.1.2 |
source | src |
created_at | 2022-05-21 06:10:45.740283 |
updated_at | 2022-05-27 06:08:57.114822 |
description | A library that provides P2P communication for Prototype Aether. Contains the implementations of the Aether Protocol. This library can be used to develop P2P applications. |
homepage | https://github.com/Prototype-Aether/Aether-Lib |
repository | https://github.com/Prototype-Aether/Aether-Lib |
max_upload_size | |
id | 590607 |
size | 160,731 |
Prototype Aether is a General Purpose Peer to Peer communication protocol. It allows developers to develop P2P applications using an easy to use library.
The Rust library aether_lib
contains the actual implementation of the protocol.
It can be used directly as a Rust library to develop applications. However, the
Aether Service which is currently
under development is recommended way to interact with Aether.
The documentation for Aether Lib can be found here
Add aether_lib
to your project in Cargo.toml
as
[dependencies]
aether_lib = "0.1.1"
The following examples show how to use aether_lib
for P2P communications.
A tracker server is required for the network to function. The tracker server helps in peer discovery and provides public identities of the peers for UDP Holepunching (peer introduction).
In order to use P2P communication, you need to initialize an Aether
instance. This
can be done as follows -
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use aether_lib::peer::Aether;
// The socker address of a tracker server to be used
let tracker_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(1, 2, 3, 4)), 8982);
// Initalize the link with a given tracker address
let aether = Aether::new(tracker_addr);
// Start the link
aether.start();
To start a P2P link to another peer, use the function connect()
in Aether
.
let peer_uid = String::from("<peer-uid-here>");
aether.connect(&peer_uid);
All communications happen in form of bytes, so you can send Vec<u8>
. For example,
strings can be converted to bytes using string.into_bytes()
(this converts to UTF-8
encoding) and from UTF-8 encoded bytes using let string = String::from_utf8(bytes)
.
In order to send bytes to a user peer_uid
you can use send_to()
let message = String::from("Hello");
let bytes = message.into_bytes();
aether.send_to(&peer_uid, bytes).unwrap();
In order to receive bytes from a user peer_uid
you can use recv_from()
let bytes = aether.recv_from(&peer_uid).unwrap();
let message = String::from_utf8(bytes).unwrap();