Send a heartbeat message when a Tributary falls behind

This commit is contained in:
Luke Parker
2023-04-23 18:55:43 -04:00
parent 72633d6421
commit 05b1fc5f05
5 changed files with 53 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ pub use tributary::P2p as TributaryP2p;
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum P2pMessageKind {
Tributary([u8; 32]),
Heartbeat([u8; 32]),
}
impl P2pMessageKind {
@@ -22,6 +23,11 @@ impl P2pMessageKind {
res.extend(genesis);
res
}
P2pMessageKind::Heartbeat(genesis) => {
let mut res = vec![1];
res.extend(genesis);
res
}
}
}
@@ -34,6 +40,11 @@ impl P2pMessageKind {
reader.read_exact(&mut genesis).ok()?;
P2pMessageKind::Tributary(genesis)
}),
1 => Some({
let mut genesis = [0; 32];
reader.read_exact(&mut genesis).ok()?;
P2pMessageKind::Heartbeat(genesis)
}),
_ => None,
}
}