Skip to content

Commit 26a8b27

Browse files
committed
address age's review
1 parent 4a10beb commit 26a8b27

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
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: 1 addition & 20 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
{
@@ -3166,16 +3167,6 @@ where
31663167
connected_peer.connections.push(connection_id);
31673168
let receiver = connected_peer.sender.new_receiver();
31683169

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-
31793170
Ok(Handler::new(self.config.protocol_config(), receiver))
31803171
}
31813172

@@ -3202,16 +3193,6 @@ where
32023193
connected_peer.connections.push(connection_id);
32033194
let receiver = connected_peer.sender.new_receiver();
32043195

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-
}
3214-
32153196
Ok(Handler::new(self.config.protocol_config(), receiver))
32163197
}
32173198

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)