Skip to content

Commit 2aed087

Browse files
committed
update to latest libp2p changes
1 parent ad24f43 commit 2aed087

3 files changed

Lines changed: 42 additions & 44 deletions

File tree

gossipsub-interop/rust-libp2p/Cargo.lock

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gossipsub-interop/rust-libp2p/src/bitmap.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use libp2p_gossipsub::{
2-
partial::{Metadata, PublishAction},
3-
Partial, PartialMessageError,
4-
};
1+
use libp2p_gossipsub::partial_messages::{Metadata, Partial, PartialAction, PartialError};
52

63
/// A fixed-size bitmap composed of `TOTAL_FIELDS` fields,
74
/// each field storing `FIELD_SIZE` bytes (i.e., `FIELD_SIZE * 8` bits).
@@ -49,22 +46,22 @@ impl Bitmap {
4946
pub(crate) fn extend_from_encoded_partial_message(
5047
&mut self,
5148
data: &[u8],
52-
) -> Result<(), PartialMessageError> {
49+
) -> Result<(), PartialError> {
5350
if data.len() < 1 + self.group_id.len() {
54-
return Err(PartialMessageError::InvalidFormat);
51+
return Err(PartialError::InvalidFormat);
5552
}
5653

5754
let bitmap = data[0];
5855
let data = &data[1..];
5956
let (data, group_id) = data.split_at(data.len() - self.group_id.len());
6057
if group_id != self.group_id {
61-
return Err(PartialMessageError::WrongGroup {
58+
return Err(PartialError::WrongGroup {
6259
received: group_id.to_vec(),
6360
});
6461
}
6562

6663
if data.len() % 1024 != 0 {
67-
return Err(PartialMessageError::InvalidFormat);
64+
return Err(PartialError::InvalidFormat);
6865
}
6966

7067
let mut offset = 0;
@@ -78,7 +75,7 @@ impl Bitmap {
7875
}
7976

8077
if offset + 1024 > data.len() {
81-
return Err(PartialMessageError::InvalidFormat);
78+
return Err(PartialError::InvalidFormat);
8279
}
8380

8481
self.set |= 1 << i;
@@ -101,9 +98,9 @@ impl Metadata for PeerBitmap {
10198
self.bitmap.as_slice()
10299
}
103100

104-
fn update(&mut self, data: &[u8]) -> Result<bool, PartialMessageError> {
101+
fn update(&mut self, data: &[u8]) -> Result<bool, PartialError> {
105102
if data.len() != 1 {
106-
return Err(PartialMessageError::InvalidFormat);
103+
return Err(PartialError::InvalidFormat);
107104
}
108105

109106
let before = self.bitmap[0];
@@ -121,14 +118,15 @@ impl Partial for Bitmap {
121118
[self.set; 1].to_vec()
122119
}
123120

124-
fn partial_message_bytes_from_metadata(
121+
fn partial_action_from_metadata(
125122
&self,
123+
_peer_id: libp2p::PeerId,
126124
metadata: Option<&[u8]>,
127-
) -> Result<PublishAction, PartialMessageError> {
125+
) -> Result<PartialAction, PartialError> {
128126
let metadata = metadata.unwrap_or(&[0u8]);
129127

130128
if metadata.len() != 1 {
131-
return Err(PartialMessageError::InvalidFormat);
129+
return Err(PartialError::InvalidFormat);
132130
}
133131

134132
let bitmap = metadata[0];
@@ -161,7 +159,7 @@ impl Partial for Bitmap {
161159
}
162160

163161
if response_bitmap == 0 {
164-
return Ok(PublishAction {
162+
return Ok(PartialAction {
165163
need: peer_has_useful_data,
166164
send: None,
167165
});
@@ -174,7 +172,7 @@ impl Partial for Bitmap {
174172
bitmap: [metadata[0] | response_bitmap],
175173
};
176174

177-
Ok(PublishAction {
175+
Ok(PartialAction {
178176
need: peer_has_useful_data,
179177
send: Some((data, Box::new(bitmap))),
180178
})

gossipsub-interop/rust-libp2p/src/experiment.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use futures::channel::mpsc;
33
use futures::{SinkExt, StreamExt};
44
use libp2p::swarm::{NetworkBehaviour, SwarmEvent};
55
use libp2p::{identify, Swarm};
6-
use libp2p_gossipsub::{self as gossipsub, IdentTopic, Partial};
6+
use libp2p_gossipsub::{self as gossipsub, partial_messages::Partial, IdentTopic};
77
use slog::{error, info, Logger};
88
use std::collections::HashMap;
99
use std::time::{Duration, Instant};
@@ -181,12 +181,12 @@ impl ScriptedNode {
181181
}).await.unwrap();
182182
}
183183
}
184-
SwarmEvent::Behaviour(MyBehaviorEvent::Gossipsub(gossipsub::Event::Partial {group_id, topic_id, propagation_source, message, metadata })) => {
185-
info!(self.stdout_logger, "Received partial message for topic {topic_id} and group {group_id:?}");
184+
SwarmEvent::Behaviour(MyBehaviorEvent::Gossipsub(gossipsub::Event::Partial {group_id, topic_hash, peer_id, message, metadata })) => {
185+
info!(self.stdout_logger, "Received partial message for topic {topic_hash} and group {group_id:?}");
186186

187187
let topic_partials = self
188188
.partials
189-
.entry(topic_id.to_string())
189+
.entry(topic_hash.to_string())
190190
.or_default();
191191
let group_id_array: [u8; 8] = group_id
192192
.as_slice()
@@ -212,7 +212,7 @@ impl ScriptedNode {
212212
info!(self.stdout_logger, "All parts received";
213213
// "topic" => topic_id,
214214
// "group_id" => group_id,
215-
"from" => propagation_source.to_string());
215+
"from" => peer_id.to_string());
216216
}
217217

218218
should_republish = true;
@@ -228,7 +228,7 @@ impl ScriptedNode {
228228
self.swarm
229229
.behaviour_mut()
230230
.gossipsub
231-
.publish_partial(topic_id, partial.clone())?;
231+
.publish_partial(topic_hash, partial.clone())?;
232232
}
233233
}
234234
ev => {
@@ -277,7 +277,7 @@ impl ScriptedNode {
277277
.swarm
278278
.behaviour_mut()
279279
.gossipsub
280-
.subscribe(&topic, partial, partial)
280+
.subscribe_partial(&topic, partial)
281281
{
282282
Ok(_) => {
283283
info!(self.stderr_logger, "Subscribed to topic {}", topic_id);

0 commit comments

Comments
 (0)