Skip to content

Commit

Permalink
Slowly adding markdown files
Browse files Browse the repository at this point in the history
  • Loading branch information
manforowicz committed Mar 24, 2024
1 parent 16f36f3 commit 67863f2
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 7 deletions.
Empty file added gday/README.md
Empty file.
32 changes: 32 additions & 0 deletions gday_contact_exchange_protocol/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# gday_contact_exchange_protocol

This protocol lets two users exchange their public and (optionally) private socket addresses via a server.
On it's own, this crate doesn't do anything other than define a shared protocol, and functions to
send and receive messages of this protocol.

## Process

Using this protocol goes something like this:

1. Peer A connects to a server via the internet
and requests a new room with `room_code` using [`ClientMsg::CreateRoom`].

2. The server replies to peer A with [`ServerMsg::RoomCreated`] or [`ServerMsg::ErrorRoomTaken`]
depending on if this `room_code` is in use.

3. Peer A externally tells peer B their `room_code` (by phone call, text message, carrier pigeon, etc.).

4. Both peers send this `room_code` and optionally their local/private socket addresses to the server
via [`ClientMsg::SendAddr`] messages. The server determines their public addresses from the internet connections.
The server replies with [`ServerMsg::ReceivedAddr`] after each of these messages.

5. Both peers send [`ClientMsg::DoneSending`] once they are ready to receive the contact info of each other.

6. The server immediately replies to [`ClientMsg::DoneSending`]
with [`ServerMsg::ClientContact`] which contains the [`FullContact`] of this peer.

7. Once both peers are ready, the server sends (on the same stream where [`ClientMsg::DoneSending`] came from)
each peer [`ServerMsg::PeerContact`] which contains the [`FullContact`] of the other peer..

8. On their own, the peers use this info to connect directly to each other by using
[hole punching](https://en.wikipedia.org/wiki/Hole_punching_(networking)).
1 change: 1 addition & 0 deletions gday_contact_exchange_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
//! 8. On their own, the peers use this info to connect directly to each other by using
//! [hole punching](https://en.wikipedia.org/wiki/Hole_punching_(networking)).
//!
#![doc = include_str!("../README.md")]
#![forbid(unsafe_code)]
#![warn(clippy::all)]

Expand Down
Empty file added gday_encryption/README.md
Empty file.
12 changes: 6 additions & 6 deletions gday_encryption/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ pub fn encryption_bench(c: &mut Criterion) {
rng.fill_bytes(&mut key);

// generate random encrypted data
let mut random_data = vec![0; 10_000_000];
let mut random_data = vec![0; 1_000_000];
rng.fill_bytes(&mut random_data);
let mut encrypted_data = vec![0; 20_000_000];
let mut encrypted_data = vec![0; 2_000_000];

c.bench_function("EncryptedStream write 10,000,000 bytes", |b| {
c.bench_function("EncryptedStream write 1,000,000 bytes", |b| {
b.iter(|| {
let mut encryptor: EncryptedStream<&mut [u8]> =
EncryptedStream::new(&mut encrypted_data[..], &key, &nonce);
Expand All @@ -40,7 +40,7 @@ pub fn decryption_bench(c: &mut Criterion) {
rng.fill_bytes(&mut key);

// generate random encrypted data
let mut random_data = vec![0; 10_000_000];
let mut random_data = vec![0; 1_000_000];
rng.fill_bytes(&mut random_data);
let mut encrypted_data = Vec::new();
let mut encryptor: EncryptedStream<&mut Vec<u8>> =
Expand All @@ -49,9 +49,9 @@ pub fn decryption_bench(c: &mut Criterion) {
encryptor.flush().unwrap();

// read this encrypted data
let mut read_data = vec![0; 10_000_000];
let mut read_data = vec![0; 1_000_000];

c.bench_function("EncryptedStream read 10,000,000 bytes", |b| {
c.bench_function("EncryptedStream read 1,000,000 bytes", |b| {
b.iter(|| {
let mut decryptor = EncryptedStream::new(&encrypted_data[..], &key, &nonce);
EncryptedStream::read_exact(black_box(&mut decryptor), black_box(&mut read_data))
Expand Down
2 changes: 1 addition & 1 deletion gday_encryption/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn test_small_messages() {

for msg in test_data {
stream.write_all(msg).unwrap();
stream.flush_write_buf().unwrap();
stream.flush().unwrap();
let mut buf = vec![0; msg.len()];
stream.read_exact(&mut buf).unwrap();
assert_eq!(buf, msg[..]);
Expand Down
Empty file added gday_encryption_async/README.md
Empty file.
Empty file.
Empty file added gday_hole_punch/README.md
Empty file.
Empty file added gday_server/README.md
Empty file.

0 comments on commit 67863f2

Please sign in to comment.