elastic ping pong to adapt env with packet loss (#4)

* elastic ping pong to adapt env with packet loss
This commit is contained in:
Sijie.Sun
2024-01-29 23:21:13 +08:00
committed by GitHub
parent 6271f9a7a7
commit 118954c745
5 changed files with 389 additions and 154 deletions
+6 -6
View File
@@ -71,8 +71,8 @@ pub struct RoutePacket {
pub enum CtrlPacketBody {
HandShake(HandShake),
RoutePacket(RoutePacket),
Ping,
Pong,
Ping(u32),
Pong(u32),
TaRpc(u32, bool, Vec<u8>), // u32: service_id, bool: is_req, Vec<u8>: rpc body
}
@@ -155,19 +155,19 @@ impl Packet {
}
}
pub fn new_ping_packet(from_peer: uuid::Uuid, to_peer: uuid::Uuid) -> Self {
pub fn new_ping_packet(from_peer: uuid::Uuid, to_peer: uuid::Uuid, seq: u32) -> Self {
Packet {
from_peer: from_peer.into(),
to_peer: Some(to_peer.into()),
body: PacketBody::Ctrl(CtrlPacketBody::Ping),
body: PacketBody::Ctrl(CtrlPacketBody::Ping(seq)),
}
}
pub fn new_pong_packet(from_peer: uuid::Uuid, to_peer: uuid::Uuid) -> Self {
pub fn new_pong_packet(from_peer: uuid::Uuid, to_peer: uuid::Uuid, seq: u32) -> Self {
Packet {
from_peer: from_peer.into(),
to_peer: Some(to_peer.into()),
body: PacketBody::Ctrl(CtrlPacketBody::Pong),
body: PacketBody::Ctrl(CtrlPacketBody::Pong(seq)),
}
}