3个不稳定版本
0.2.1 | 2024年7月12日 |
---|---|
0.2.0 | 2024年7月8日 |
0.1.1 | 2024年6月7日 |
#15 in #contact
16KB
152 行
注意:这个crate仍然处于早期开发阶段,因此请预期会有破坏性的更改。
gday_contact_exchange_protocol
本协议允许两个用户通过服务器交换他们的公网和(可选的)私有套接字地址。
请参阅文档。
被使用于
- gday - 发送文件的命令行工具。
- gday_server - 允许两个节点共享套接字地址的服务器。
- gday_hole_punch - 建立点对点TCP连接的库。
lib.rs
:
注意:这个crate仍然处于早期开发阶段,因此请预期会有破坏性的更改。
本协议允许两个用户通过服务器交换他们的公网和(可选的)私有套接字地址。
本库仅定义了一个共享协议,自身并不做任何事情。在大多数情况下,您应使用以下crate之一
- gday: 用于向节点发送文件的命令行工具。
- gday_hole_punch: 用于建立点对点TCP连接的库。
- gday_server: 支持此协议的服务器二进制文件。
示例
首先,两个节点都连接到IPv4和IPv6(如果可能)上的gday服务器,使用DEFAULT_TLS_PORT
。然后他们像这样交换联系信息
#
let room_code = 42;
// A client tells the server to create a room.
// The server responds with ServerMsg::RoomCreated or
// ServerMsg::ErrorRoomTaken.
let request = ClientMsg::CreateRoom { room_code };
write_to(request, &mut tls_ipv4)?;
let response: ServerMsg = read_from(&mut tls_ipv4)?;
// Each peer sends ClientMsg::RecordPublicAddr
// from all their endpoints.
// The server records the client's public addresses from these connections.
// The server responds with ServerMsg::ReceivedAddr
let request = ClientMsg::RecordPublicAddr { room_code, is_creator: true };
write_to(request, &mut tls_ipv4)?;
let response: ServerMsg = read_from(&mut tls_ipv4)?;
write_to(request, &mut tls_ipv6)?;
let response: ServerMsg = read_from(&mut tls_ipv6)?;
// Both peers share their local address with the server.
// The server immediately responds with ServerMsg::ClientContact,
// containing each client's FullContact.
let local_contact = Contact {
v4: todo!("local v4 addr"),
v6: todo!("local v6 addr")
};
let request = ClientMsg::ReadyToShare { local_contact, room_code, is_creator: true };
write_to(request, &mut tls_ipv4)?;
let response: ServerMsg = read_from(&mut tls_ipv4)?;
// Once both clients have sent ClientMsg::ShareContact,
// the server sends both clients a ServerMsg::PeerContact
// containing the FullContact of the peer.
let response: ServerMsg = read_from(&mut tls_ipv4)?;
// The server then closes the room, and the peers disconnect.
// The peers then connect directly to each other using a library
// such as gday_hole_punch.
#
依赖关系
~2.9–5MB
~85K SLoC