Skip to content

Commit 9cb66d8

Browse files
committed
address age's review
1 parent 4a10beb commit 9cb66d8

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

protocols/gossipsub/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ categories = ["network-programming", "asynchronous"]
1313
[features]
1414
wasm-bindgen = ["getrandom/js", "futures-timer/wasm-bindgen"]
1515
metrics = ["prometheus-client"]
16+
test-extension = []
1617

1718
[dependencies]
1819
async-channel = "2.3.1"

protocols/gossipsub/src/behaviour.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,7 @@ where
15401540

15411541
peer.extensions = Some(extensions);
15421542

1543+
#[cfg(feature = "test-extension")]
15431544
if extensions.test_extension.unwrap_or(false)
15441545
&& matches!(peer.kind, PeerKind::Gossipsubv1_3)
15451546
{
@@ -3164,19 +3165,11 @@ where
31643165
});
31653166
// Add the new connection
31663167
connected_peer.connections.push(connection_id);
3167-
let receiver = connected_peer.sender.new_receiver();
31683168

3169-
if connected_peer.connections.len() <= 1 {
3170-
// If this is the first connection send extensions message.
3171-
self.send_message(
3172-
peer_id,
3173-
RpcOut::Extensions(Extensions {
3174-
test_extension: Some(true),
3175-
}),
3176-
);
3177-
}
3178-
3179-
Ok(Handler::new(self.config.protocol_config(), receiver))
3169+
Ok(Handler::new(
3170+
self.config.protocol_config(),
3171+
connected_peer.sender.new_receiver(),
3172+
))
31803173
}
31813174

31823175
fn handle_established_outbound_connection(
@@ -3200,19 +3193,11 @@ where
32003193
});
32013194
// Add the new connection
32023195
connected_peer.connections.push(connection_id);
3203-
let receiver = connected_peer.sender.new_receiver();
3204-
3205-
if connected_peer.connections.len() <= 1 {
3206-
// If this is the first connection send extensions message.
3207-
self.send_message(
3208-
peer_id,
3209-
RpcOut::Extensions(Extensions {
3210-
test_extension: Some(true),
3211-
}),
3212-
);
3213-
}
32143196

3215-
Ok(Handler::new(self.config.protocol_config(), receiver))
3197+
Ok(Handler::new(
3198+
self.config.protocol_config(),
3199+
connected_peer.sender.new_receiver(),
3200+
))
32163201
}
32173202

32183203
fn on_connection_handler_event(

protocols/gossipsub/src/handler.rs

Lines changed: 18 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, RpcIn, RpcOut},
42+
types::{Extensions, PeerKind, RawMessage, RpcIn, RpcOut},
4343
ValidationError,
4444
};
4545

@@ -211,7 +211,23 @@ impl EnabledHandler {
211211
self.outbound_substream.is_none(),
212212
"Established an outbound substream with one already available"
213213
);
214-
self.outbound_substream = Some(OutboundSubstreamState::WaitingOutput(substream));
214+
215+
// For gossipsub 1.3 peers, immediately send Extensions message.
216+
if matches!(peer_kind, PeerKind::Gossipsubv1_3) {
217+
let test_extension = if cfg!(feature = "test-extension") {
218+
Some(true)
219+
} else {
220+
None
221+
};
222+
223+
let extensions_rpc = RpcOut::Extensions(Extensions { test_extension });
224+
self.outbound_substream = Some(OutboundSubstreamState::PendingSend(
225+
substream,
226+
extensions_rpc.into_protobuf(),
227+
));
228+
} else {
229+
self.outbound_substream = Some(OutboundSubstreamState::WaitingOutput(substream));
230+
}
215231
}
216232

217233
fn poll(

protocols/gossipsub/src/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(crate) const SIGNING_PREFIX: &[u8] = b"libp2p-pubsub:";
4545

4646
pub(crate) const GOSSIPSUB_1_3_0_PROTOCOL: ProtocolId = ProtocolId {
4747
protocol: StreamProtocol::new("/meshsub/1.3.0"),
48-
kind: PeerKind::Gossipsubv1_2,
48+
kind: PeerKind::Gossipsubv1_3,
4949
};
5050

5151
pub(crate) const GOSSIPSUB_1_2_0_PROTOCOL: ProtocolId = ProtocolId {

0 commit comments

Comments
 (0)