@@ -115,12 +115,16 @@ pub struct Behaviour {
115115///
116116/// Returns a configured [`Gossipsub`] instance or an error string if configuration fails.
117117#[ cfg( feature = "gossipsub" ) ]
118+ #[ expect( clippy:: too_many_arguments, reason = "We need these" ) ]
118119fn create_gossipsub (
119120 keypair : & Keypair ,
120121 topic : & Sha256Topic ,
121122 gossipsub_score_params : & Option < PeerScoreParams > ,
122123 gossipsub_score_thresholds : & Option < PeerScoreThresholds > ,
123124 max_transmit_size : usize ,
125+ mesh_n : Option < usize > ,
126+ mesh_n_low : Option < usize > ,
127+ mesh_n_high : Option < usize > ,
124128) -> Result < Gossipsub < IdentityTransform , WhitelistSubscriptionFilter > , & ' static str > {
125129 let mut filter = HashSet :: new ( ) ;
126130 filter. insert ( topic. hash ( ) ) ; // Target topic for subscription.
@@ -138,13 +142,26 @@ fn create_gossipsub(
138142
139143 let peer_score_thresholds = gossipsub_score_thresholds. clone ( ) . unwrap_or_default ( ) ;
140144
145+ let mut config_builder = gossipsub:: ConfigBuilder :: default ( ) ;
146+ config_builder
147+ . validation_mode ( ValidationMode :: Permissive )
148+ . validate_messages ( )
149+ . max_transmit_size ( max_transmit_size)
150+ . idontwant_on_publish ( true ) ;
151+
152+ if let Some ( n) = mesh_n {
153+ config_builder. mesh_n ( n) ;
154+ }
155+ if let Some ( n_low) = mesh_n_low {
156+ config_builder. mesh_n_low ( n_low) ;
157+ }
158+ if let Some ( n_high) = mesh_n_high {
159+ config_builder. mesh_n_high ( n_high) ;
160+ }
161+
141162 let gossipsub = Gossipsub :: new_with_subscription_filter (
142163 MessageAuthenticity :: Author ( PeerId :: from_public_key ( & keypair. public ( ) . clone ( ) ) ) ,
143- gossipsub:: ConfigBuilder :: default ( )
144- . validation_mode ( ValidationMode :: Permissive )
145- . validate_messages ( )
146- . max_transmit_size ( max_transmit_size)
147- . idontwant_on_publish ( true )
164+ config_builder
148165 . build ( )
149166 . expect ( "gossipsub config at this stage must be valid" ) ,
150167 WhitelistSubscriptionFilter ( filter) ,
@@ -237,6 +254,9 @@ impl Behaviour {
237254 #[ cfg( feature = "gossipsub" ) ] gossipsub_score_params : & Option < PeerScoreParams > ,
238255 #[ cfg( feature = "gossipsub" ) ] gossipsub_score_thresholds : & Option < PeerScoreThresholds > ,
239256 #[ cfg( feature = "gossipsub" ) ] gossipsub_max_transmit_size : usize ,
257+ #[ cfg( feature = "gossipsub" ) ] gossipsub_mesh_n : Option < usize > ,
258+ #[ cfg( feature = "gossipsub" ) ] gossipsub_mesh_n_low : Option < usize > ,
259+ #[ cfg( feature = "gossipsub" ) ] gossipsub_mesh_n_high : Option < usize > ,
240260 #[ cfg( feature = "byos" ) ] signer : Arc < dyn ApplicationSigner > ,
241261 #[ cfg( feature = "byos" ) ] envelope_max_age : std:: time:: Duration ,
242262 #[ cfg( feature = "byos" ) ] max_clock_skew : std:: time:: Duration ,
@@ -253,6 +273,9 @@ impl Behaviour {
253273 gossipsub_score_params,
254274 gossipsub_score_thresholds,
255275 gossipsub_max_transmit_size,
276+ gossipsub_mesh_n,
277+ gossipsub_mesh_n_low,
278+ gossipsub_mesh_n_high,
256279 ) ?;
257280
258281 #[ cfg( feature = "kad" ) ]
0 commit comments