1 unstable release
0.1.1 | Jun 7, 2024 |
---|
#1791 in Network programming
161 downloads per month
Used in 3 crates
(2 directly)
18KB
229 lines
Note: this crate is still in early-development, so expect breaking changes.
gday_contact_exchange_protocol
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
-
Peer A connects to a server via the internet and requests a new room with
room_code
usingClientMsg::CreateRoom
. -
The server replies to peer A with
ServerMsg::RoomCreated
orServerMsg::ErrorRoomTaken
depending on if thisroom_code
is in use. -
Peer A externally tells peer B their
room_code
(by phone call, text message, carrier pigeon, etc.). -
Both peers send this
room_code
and optionally their local/private socket addresses to the server viaClientMsg::SendAddr
messages. The server determines their public addresses from the internet connections. The server replies withServerMsg::ReceivedAddr
after each of these messages. -
Both peers send
ClientMsg::DoneSending
once they are ready to receive the contact info of each other. -
The server immediately replies to
ClientMsg::DoneSending
withServerMsg::ClientContact
which contains theFullContact
of this peer. -
Once both peers are ready, the server sends (on the same stream where
ClientMsg::DoneSending
came from) each peer aServerMsg::PeerContact
which contains theFullContact
of the other peer. -
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