Skip to content

Commit 37040ee

Browse files
authored
feat(gossipsub): remove Rpc from the public API
Pull-Request: #6091.
1 parent 1aa4337 commit 37040ee

File tree

9 files changed

+33
-141
lines changed

9 files changed

+33
-141
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ libp2p-core = { version = "0.43.1", path = "core" }
8282
libp2p-dcutr = { version = "0.14.0", path = "protocols/dcutr" }
8383
libp2p-dns = { version = "0.44.0", path = "transports/dns" }
8484
libp2p-floodsub = { version = "0.47.0", path = "protocols/floodsub" }
85-
libp2p-gossipsub = { version = "0.49.0", path = "protocols/gossipsub" }
85+
libp2p-gossipsub = { version = "0.50.0", path = "protocols/gossipsub" }
8686
libp2p-identify = { version = "0.47.0", path = "protocols/identify" }
8787
libp2p-identity = { version = "0.2.12" }
8888
libp2p-kad = { version = "0.48.1", path = "protocols/kad" }

protocols/gossipsub/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.50.0
2+
3+
- Remove `Rpc` from the public API.
4+
See [PR 6091](https://github.com/libp2p/rust-libp2p/pull/6091)
5+
16
## 0.49.0
27

38
- Feature gate metrics related code. This changes some `Behaviour` constructor methods.

protocols/gossipsub/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "libp2p-gossipsub"
33
edition.workspace = true
44
rust-version = { workspace = true }
55
description = "Gossipsub protocol for libp2p"
6-
version = "0.49.0"
6+
version = "0.50.0"
77
authors = ["Age Manning <[email protected]>"]
88
license = "MIT"
99
repository = "https://github.com/libp2p/rust-libp2p"

protocols/gossipsub/src/behaviour/tests.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::{
3434
protocol::GossipsubCodec,
3535
rpc::Receiver,
3636
subscription_filter::WhitelistSubscriptionFilter,
37-
types::Rpc,
37+
types::RpcIn,
3838
IdentTopic as Topic,
3939
};
4040

@@ -313,7 +313,7 @@ where
313313
}
314314

315315
// Converts a protobuf message into a gossipsub message for reading the Gossipsub event queue.
316-
fn proto_to_message(rpc: &proto::RPC) -> Rpc {
316+
fn proto_to_message(rpc: &proto::RPC) -> RpcIn {
317317
// Store valid messages.
318318
let mut messages = Vec::with_capacity(rpc.publish.len());
319319
let rpc = rpc.clone();
@@ -403,7 +403,7 @@ fn proto_to_message(rpc: &proto::RPC) -> Rpc {
403403
control_msgs.extend(prune_msgs);
404404
}
405405

406-
Rpc {
406+
RpcIn {
407407
messages,
408408
subscriptions: rpc
409409
.subscriptions
@@ -1243,7 +1243,7 @@ fn test_handle_iwant_msg_but_already_sent_idontwant() {
12431243
gs.mcache.put(&msg_id, raw_message);
12441244

12451245
// Receive IDONTWANT from Peer 1.
1246-
let rpc = Rpc {
1246+
let rpc = RpcIn {
12471247
messages: vec![],
12481248
subscriptions: vec![],
12491249
control_msgs: vec![ControlAction::IDontWant(IDontWant {
@@ -3137,7 +3137,7 @@ fn test_ignore_rpc_from_peers_below_graylist_threshold() {
31373137
p1,
31383138
ConnectionId::new_unchecked(0),
31393139
HandlerEvent::Message {
3140-
rpc: Rpc {
3140+
rpc: RpcIn {
31413141
messages: vec![raw_message1],
31423142
subscriptions: vec![subscription.clone()],
31433143
control_msgs: vec![control_action],
@@ -3163,7 +3163,7 @@ fn test_ignore_rpc_from_peers_below_graylist_threshold() {
31633163
p2,
31643164
ConnectionId::new_unchecked(0),
31653165
HandlerEvent::Message {
3166-
rpc: Rpc {
3166+
rpc: RpcIn {
31673167
messages: vec![raw_message3],
31683168
subscriptions: vec![subscription],
31693169
control_msgs: vec![control_action],
@@ -3773,7 +3773,7 @@ fn test_scoring_p4_invalid_signature() {
37733773
peers[0],
37743774
ConnectionId::new_unchecked(0),
37753775
HandlerEvent::Message {
3776-
rpc: Rpc {
3776+
rpc: RpcIn {
37773777
messages: vec![],
37783778
subscriptions: vec![],
37793779
control_msgs: vec![],
@@ -5530,7 +5530,7 @@ fn parses_idontwant() {
55305530
.create_network();
55315531

55325532
let message_id = MessageId::new(&[0, 1, 2, 3]);
5533-
let rpc = Rpc {
5533+
let rpc = RpcIn {
55345534
messages: vec![],
55355535
subscriptions: vec![],
55365536
control_msgs: vec![ControlAction::IDontWant(IDontWant {
@@ -6619,7 +6619,7 @@ fn test_validation_error_message_size_too_large_topic_specific() {
66196619
peers[0],
66206620
ConnectionId::new_unchecked(0),
66216621
HandlerEvent::Message {
6622-
rpc: Rpc {
6622+
rpc: RpcIn {
66236623
messages: vec![raw_message],
66246624
subscriptions: vec![],
66256625
control_msgs: vec![],
@@ -6723,7 +6723,7 @@ fn test_validation_message_size_within_topic_specific() {
67236723
peers[0],
67246724
ConnectionId::new_unchecked(0),
67256725
HandlerEvent::Message {
6726-
rpc: Rpc {
6726+
rpc: RpcIn {
67276727
messages: vec![raw_message],
67286728
subscriptions: vec![],
67296729
control_msgs: vec![],

protocols/gossipsub/src/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::{
3939
protocol::{GossipsubCodec, ProtocolConfig},
4040
rpc::Receiver,
4141
rpc_proto::proto,
42-
types::{PeerKind, RawMessage, Rpc, RpcOut},
42+
types::{PeerKind, RawMessage, RpcIn, RpcOut},
4343
ValidationError,
4444
};
4545

@@ -51,7 +51,7 @@ pub enum HandlerEvent {
5151
/// any) that were received.
5252
Message {
5353
/// The GossipsubRPC message excluding any invalid messages.
54-
rpc: Rpc,
54+
rpc: RpcIn,
5555
/// Any invalid messages that were received in the RPC, along with the associated
5656
/// validation error.
5757
invalid_messages: Vec<(RawMessage, ValidationError)>,

protocols/gossipsub/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,5 @@ pub use self::{
134134
types::{FailedMessages, Message, MessageAcceptance, MessageId, RawMessage},
135135
};
136136

137-
#[deprecated(note = "Will be removed from the public API.")]
138-
pub type Rpc = self::types::Rpc;
139-
140137
pub type IdentTopic = Topic<self::topic::IdentityHash>;
141138
pub type Sha256Topic = Topic<self::topic::Sha256Hash>;

protocols/gossipsub/src/protocol.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use crate::{
3636
topic::TopicHash,
3737
types::{
3838
ControlAction, Graft, IDontWant, IHave, IWant, MessageId, PeerInfo, PeerKind, Prune,
39-
RawMessage, Rpc, Subscription, SubscriptionAction,
39+
RawMessage, RpcIn, Subscription, SubscriptionAction,
4040
},
4141
ValidationError,
4242
};
@@ -564,7 +564,7 @@ impl Decoder for GossipsubCodec {
564564
}
565565

566566
Ok(Some(HandlerEvent::Message {
567-
rpc: Rpc {
567+
rpc: RpcIn {
568568
messages,
569569
subscriptions: rpc
570570
.subscriptions
@@ -587,12 +587,16 @@ impl Decoder for GossipsubCodec {
587587

588588
#[cfg(test)]
589589
mod tests {
590+
use std::time::Duration;
591+
592+
use futures_timer::Delay;
590593
use libp2p_identity::Keypair;
591594
use quickcheck::*;
592595

593596
use super::*;
594597
use crate::{
595-
config::Config, Behaviour, ConfigBuilder, IdentTopic as Topic, MessageAuthenticity, Version,
598+
config::Config, types::RpcOut, Behaviour, ConfigBuilder, IdentTopic as Topic,
599+
MessageAuthenticity, Version,
596600
};
597601

598602
#[derive(Clone, Debug)]
@@ -652,10 +656,9 @@ mod tests {
652656
fn prop(message: Message) {
653657
let message = message.0;
654658

655-
let rpc = Rpc {
656-
messages: vec![message.clone()],
657-
subscriptions: vec![],
658-
control_msgs: vec![],
659+
let rpc = RpcOut::Publish {
660+
message: message.clone(),
661+
timeout: Delay::new(Duration::from_secs(1)),
659662
};
660663

661664
let mut codec =

protocols/gossipsub/src/types.rs

Lines changed: 3 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ impl From<RpcOut> for proto::RPC {
472472
}
473473
}
474474

475-
/// An RPC received/sent.
475+
/// A Gossipsub RPC message received.
476476
#[derive(Clone, PartialEq, Eq, Hash)]
477-
pub struct Rpc {
477+
pub struct RpcIn {
478478
/// List of messages that were part of this RPC query.
479479
pub messages: Vec<RawMessage>,
480480
/// List of subscriptions.
@@ -483,120 +483,7 @@ pub struct Rpc {
483483
pub control_msgs: Vec<ControlAction>,
484484
}
485485

486-
impl Rpc {
487-
/// Converts the GossipsubRPC into its protobuf format.
488-
// A convenience function to avoid explicitly specifying types.
489-
pub fn into_protobuf(self) -> proto::RPC {
490-
self.into()
491-
}
492-
}
493-
494-
impl From<Rpc> for proto::RPC {
495-
/// Converts the RPC into protobuf format.
496-
fn from(rpc: Rpc) -> Self {
497-
// Messages
498-
let mut publish = Vec::new();
499-
500-
for message in rpc.messages.into_iter() {
501-
let message = proto::Message {
502-
from: message.source.map(|m| m.to_bytes()),
503-
data: Some(message.data),
504-
seqno: message.sequence_number.map(|s| s.to_be_bytes().to_vec()),
505-
topic: TopicHash::into_string(message.topic),
506-
signature: message.signature,
507-
key: message.key,
508-
};
509-
510-
publish.push(message);
511-
}
512-
513-
// subscriptions
514-
let subscriptions = rpc
515-
.subscriptions
516-
.into_iter()
517-
.map(|sub| proto::SubOpts {
518-
subscribe: Some(sub.action == SubscriptionAction::Subscribe),
519-
topic_id: Some(sub.topic_hash.into_string()),
520-
})
521-
.collect::<Vec<_>>();
522-
523-
// control messages
524-
let mut control = proto::ControlMessage {
525-
ihave: Vec::new(),
526-
iwant: Vec::new(),
527-
graft: Vec::new(),
528-
prune: Vec::new(),
529-
idontwant: Vec::new(),
530-
};
531-
532-
let empty_control_msg = rpc.control_msgs.is_empty();
533-
534-
for action in rpc.control_msgs {
535-
match action {
536-
// collect all ihave messages
537-
ControlAction::IHave(IHave {
538-
topic_hash,
539-
message_ids,
540-
}) => {
541-
let rpc_ihave = proto::ControlIHave {
542-
topic_id: Some(topic_hash.into_string()),
543-
message_ids: message_ids.into_iter().map(|msg_id| msg_id.0).collect(),
544-
};
545-
control.ihave.push(rpc_ihave);
546-
}
547-
ControlAction::IWant(IWant { message_ids }) => {
548-
let rpc_iwant = proto::ControlIWant {
549-
message_ids: message_ids.into_iter().map(|msg_id| msg_id.0).collect(),
550-
};
551-
control.iwant.push(rpc_iwant);
552-
}
553-
ControlAction::Graft(Graft { topic_hash }) => {
554-
let rpc_graft = proto::ControlGraft {
555-
topic_id: Some(topic_hash.into_string()),
556-
};
557-
control.graft.push(rpc_graft);
558-
}
559-
ControlAction::Prune(Prune {
560-
topic_hash,
561-
peers,
562-
backoff,
563-
}) => {
564-
let rpc_prune = proto::ControlPrune {
565-
topic_id: Some(topic_hash.into_string()),
566-
peers: peers
567-
.into_iter()
568-
.map(|info| proto::PeerInfo {
569-
peer_id: info.peer_id.map(|id| id.to_bytes()),
570-
// TODO, see https://github.com/libp2p/specs/pull/217
571-
signed_peer_record: None,
572-
})
573-
.collect(),
574-
backoff,
575-
};
576-
control.prune.push(rpc_prune);
577-
}
578-
ControlAction::IDontWant(IDontWant { message_ids }) => {
579-
let rpc_idontwant = proto::ControlIDontWant {
580-
message_ids: message_ids.into_iter().map(|msg_id| msg_id.0).collect(),
581-
};
582-
control.idontwant.push(rpc_idontwant);
583-
}
584-
}
585-
}
586-
587-
proto::RPC {
588-
subscriptions,
589-
publish,
590-
control: if empty_control_msg {
591-
None
592-
} else {
593-
Some(control)
594-
},
595-
}
596-
}
597-
}
598-
599-
impl fmt::Debug for Rpc {
486+
impl fmt::Debug for RpcIn {
600487
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
601488
let mut b = f.debug_struct("GossipsubRpc");
602489
if !self.messages.is_empty() {

0 commit comments

Comments
 (0)