Expand 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. However, Aether Service is the recommended way to interact with Aether.

Basic Usage

Following examples demonstrate the basic usage including connecting to a peer and sending and receiving bytes from the peer.

Initializing a client

A client can be initialized using Aether. In order to initialize a client, you also need to have a tracker server. The tracker server implementation can be found here.

use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use aether_lib::peer::Aether;

// address of the tracker server to be used
// one is hosted on 149.129.129.226:8982
let tracker_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(149, 129, 129, 226)), 8982);
// initialize the client
let aether = Aether::new(tracker_addr);

// start the client
aether.start();

Connecting to a peer

In order to connect to a peer, you need the other peer’s UID. This UID is unique to each client and is generated on the first run and saved on the file system (see identity).

You can use the peer’s UID to connect as follows

use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use aether_lib::peer::Aether;

// address of the tracker server to be used
// one is hosted on 149.129.129.226:8982
let tracker_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(149, 129, 129, 226)), 8982);
// initialize the client
let aether = Aether::new(tracker_addr);

// start the client
aether.start();

// the UID of the other peer
let peer_uid = String::from("<peer-uid-here>");

// connect to the other peer
aether.connect(&peer_uid);

Sending bytes to another peer

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()

use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use aether_lib::peer::Aether;

// address of the tracker server to be used
// one is hosted on 149.129.129.226:8982
let tracker_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(149, 129, 129, 226)), 8982);
// initialize the client
let aether = Aether::new(tracker_addr);

// start the client
aether.start();

// the UID of the other peer
let peer_uid = String::from("<peer-uid-here>");

// connect to the other peer
aether.connect(&peer_uid);

// message to be sent
let message = String::from("Hello");

// convert to bytes
let bytes = message.into_bytes();

// send to peer with peer_uid
aether.send_to(&peer_uid, bytes).unwrap();

Receiving bytes from another peer

In order to receive bytes from a user peer_uid you can use recv_from()

use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use aether_lib::peer::Aether;

// address of the tracker server to be used
// one is hosted on 149.129.129.226:8982
let tracker_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(149, 129, 129, 226)), 8982);
// initialize the client
let aether = Aether::new(tracker_addr);

// start the client
aether.start();

// the UID of the other peer
let peer_uid = String::from("<peer-uid-here>");

// connect to the other peer
aether.connect(&peer_uid);

// receive bytes from peer with peer_uid
let bytes = aether.recv_from(&peer_uid).unwrap();

// decode UTF-8 encoded bytes
let message = String::from_utf8(bytes).unwrap();

Modules

Structures for facilitating storing acknowledgment numbers for verification and sending

Structures to represent configuration used by aether_lib

Primitives for symmetric encryption for Aether. Makes use of AES-256-GCM cipher. Implementation built on top of OpenSSL.

Structures to represent errors in aether_lib

Primitives for representing PKC based user identities. Used to identify and authenticate users as well as for key exchange.

Structure for representing a reliable Link between 2 peers.

Primitives for representing a unit of packet in Aether.

Structure for representing an Aether client.

Primitives for representing packets used to communicate with the tracker server

General purpose utilities used by aether_lib often.