#peer #server #protocols #exchange #addresses #sockets #send

gday_contact_exchange_protocol

Protocol for peers to exchange their socket addresses via a server

1 unstable release

0.1.1 Jun 7, 2024

#1791 in Network programming

Download history 147/week @ 2024-06-03 14/week @ 2024-06-10

161 downloads per month
Used in 3 crates (2 directly)

MIT license

18KB
229 lines

Note: this crate is still in early-development, so expect breaking changes.

gday_contact_exchange_protocol

Crates.io Version docs.rs

Want to send files easily, securely, and directly, without a relay or port forwarding? Then go to the gday page.

This library defines a protocol that lets two users exchange their public and/or private socket addresses via a server. This library provides functions to send and receive messages of this protocol.

This library is used by gday_hole_punch and gday_server.


lib.rs:

Note: this crate is still in early-development, so expect breaking changes.

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. In most cases, you should use one of the following crates:

  • gday: A command line tool for sending files to peers.
  • gday_hole_punch: A library for establishing a peer-to-peer TCP connection.
  • gday_server: A server binary that facilitates this protocol.

Example steps

  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 a 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. gday_hole_punch is a library that provides tools for hole punching.

Dependencies

~2.8–4.5MB
~81K SLoC