mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-02 04:03:35 +00:00
Implement gossipsub IDONTWANT (#5422)
* move gossipsub into a separate crate * Merge branch 'unstable' of github.com:sigp/lighthouse into separate-gossipsub * update rpc.proto and generate rust bindings * gossipsub: implement IDONTWANT messages * address review * move GossipPromises out of PeerScore * impl PeerKind::is_gossipsub that returns true if peer speaks any version of gossipsub * address review 2 * Merge branch 'separate-gossipsub' of github.com:sigp/lighthouse into impl-gossipsub-idontwant * Merge branch 'unstable' of github.com:sigp/lighthouse into impl-gossipsub-idontwant * add metrics * add tests * make 1.2 beta before spec is merged * Merge branch 'unstable' of github.com:sigp/lighthouse into impl-gossipsub-idontwant * cargo clippy * Collect decoded IDONTWANT messages * Use the beta tag in most places to simplify the transition * Fix failed test by using fresh message-ids * Gossipsub v1.2-beta * Merge latest unstable * Cargo update * Merge pull request #5 from ackintosh/impl-gossipsub-idontwant-ackintosh-fix-test Fix `test_ignore_too_many_messages_in_ihave` test * Merge branch 'unstable' of github.com:sigp/lighthouse into impl-gossipsub-idontwant * update CHANGELOG.md * remove beta for 1.2 IDONTWANT spec has been merged * Merge branch 'unstable' of github.com:sigp/lighthouse into impl-gossipsub-idontwant * Merge branch 'impl-gossipsub-idontwant' of github.com:jxs/lighthouse into impl-gossipsub-idontwant * Merge branch 'unstable' of github.com:sigp/lighthouse into impl-gossipsub-idontwant * improve comments wording * Merge branch 'impl-gossipsub-idontwant' of github.com:jxs/lighthouse into impl-gossipsub-idontwant
This commit is contained in:
@@ -154,6 +154,7 @@ pub struct ControlMessage {
|
||||
pub iwant: Vec<gossipsub::pb::ControlIWant>,
|
||||
pub graft: Vec<gossipsub::pb::ControlGraft>,
|
||||
pub prune: Vec<gossipsub::pb::ControlPrune>,
|
||||
pub idontwant: Vec<gossipsub::pb::ControlIDontWant>,
|
||||
}
|
||||
|
||||
impl<'a> MessageRead<'a> for ControlMessage {
|
||||
@@ -165,6 +166,7 @@ impl<'a> MessageRead<'a> for ControlMessage {
|
||||
Ok(18) => msg.iwant.push(r.read_message::<gossipsub::pb::ControlIWant>(bytes)?),
|
||||
Ok(26) => msg.graft.push(r.read_message::<gossipsub::pb::ControlGraft>(bytes)?),
|
||||
Ok(34) => msg.prune.push(r.read_message::<gossipsub::pb::ControlPrune>(bytes)?),
|
||||
Ok(42) => msg.idontwant.push(r.read_message::<gossipsub::pb::ControlIDontWant>(bytes)?),
|
||||
Ok(t) => { r.read_unknown(bytes, t)?; }
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
@@ -180,6 +182,7 @@ impl MessageWrite for ControlMessage {
|
||||
+ self.iwant.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
|
||||
+ self.graft.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
|
||||
+ self.prune.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
|
||||
+ self.idontwant.iter().map(|s| 1 + sizeof_len((s).get_size())).sum::<usize>()
|
||||
}
|
||||
|
||||
fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
|
||||
@@ -187,6 +190,7 @@ impl MessageWrite for ControlMessage {
|
||||
for s in &self.iwant { w.write_with_tag(18, |w| w.write_message(s))?; }
|
||||
for s in &self.graft { w.write_with_tag(26, |w| w.write_message(s))?; }
|
||||
for s in &self.prune { w.write_with_tag(34, |w| w.write_message(s))?; }
|
||||
for s in &self.idontwant { w.write_with_tag(42, |w| w.write_message(s))?; }
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -331,6 +335,38 @@ impl MessageWrite for ControlPrune {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Debug, Default, PartialEq, Clone)]
|
||||
pub struct ControlIDontWant {
|
||||
pub message_ids: Vec<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl<'a> MessageRead<'a> for ControlIDontWant {
|
||||
fn from_reader(r: &mut BytesReader, bytes: &'a [u8]) -> Result<Self> {
|
||||
let mut msg = Self::default();
|
||||
while !r.is_eof() {
|
||||
match r.next_tag(bytes) {
|
||||
Ok(10) => msg.message_ids.push(r.read_bytes(bytes)?.to_owned()),
|
||||
Ok(t) => { r.read_unknown(bytes, t)?; }
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
Ok(msg)
|
||||
}
|
||||
}
|
||||
|
||||
impl MessageWrite for ControlIDontWant {
|
||||
fn get_size(&self) -> usize {
|
||||
0
|
||||
+ self.message_ids.iter().map(|s| 1 + sizeof_len((s).len())).sum::<usize>()
|
||||
}
|
||||
|
||||
fn write_message<W: WriterBackend>(&self, w: &mut Writer<W>) -> Result<()> {
|
||||
for s in &self.message_ids { w.write_with_tag(10, |w| w.write_bytes(&**s))?; }
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||
#[derive(Debug, Default, PartialEq, Clone)]
|
||||
pub struct PeerInfo {
|
||||
|
||||
@@ -28,6 +28,7 @@ message ControlMessage {
|
||||
repeated ControlIWant iwant = 2;
|
||||
repeated ControlGraft graft = 3;
|
||||
repeated ControlPrune prune = 4;
|
||||
repeated ControlIDontWant idontwant = 5;
|
||||
}
|
||||
|
||||
message ControlIHave {
|
||||
@@ -49,6 +50,10 @@ message ControlPrune {
|
||||
optional uint64 backoff = 3; // gossipsub v1.1 backoff time (in seconds)
|
||||
}
|
||||
|
||||
message ControlIDontWant {
|
||||
repeated bytes message_ids = 1;
|
||||
}
|
||||
|
||||
message PeerInfo {
|
||||
optional bytes peer_id = 1;
|
||||
optional bytes signed_peer_record = 2;
|
||||
|
||||
Reference in New Issue
Block a user