1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! 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](https://github.com/Prototype-Aether/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`][Aether]. In order to initialize
//! a client, you also need to have a tracker server. The tracker server implementation
//! can be found [here](https://github.com/Prototype-Aether/Aether-Tracker).
//!
//! ```rust,no_run
//! 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
//!
//! ```rust,no_run
//! 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()`
//!
//! ```rust,no_run
//! 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()`
//!
//! ```rust,no_run
//! 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();
//! ```
//!
//! [Aether]: crate::peer::Aether
//! [identity]: crate::identity

pub mod acknowledgement;
pub mod config;
pub mod encryption;
pub mod error;
pub mod identity;
pub mod link;
pub mod packet;
pub mod peer;
pub mod tracker;
pub mod util;