| 
1 | 1 | // TODO(shahak): Erase main_behaviour and make this a separate module.  | 
2 | 2 | 
 
  | 
3 | 3 | use std::convert::Infallible;  | 
 | 4 | +use std::time::Duration;  | 
4 | 5 | 
 
  | 
5 | 6 | use apollo_propeller as propeller;  | 
6 | 7 | use libp2p::connection_limits::ConnectionLimits;  | 
@@ -86,6 +87,57 @@ impl MixedBehaviour {  | 
86 | 87 |         let kademlia_config = kad::Config::new(protocol_name);  | 
87 | 88 |         let connection_limits = ConnectionLimits::default(); // .with_max_established_per_peer(Some(1));  | 
88 | 89 | 
 
  | 
 | 90 | +        let gossipsub_config = gossipsub::ConfigBuilder::default()  | 
 | 91 | +            .max_transmit_size(1 << 34)  | 
 | 92 | +            .flood_publish(false)  | 
 | 93 | +            .heartbeat_interval(Duration::from_millis(700))  | 
 | 94 | +            // .validation_mode(ValidationMode::None)  | 
 | 95 | +            .message_id_fn(|message| {  | 
 | 96 | +                let mut source_string = message.source.as_ref().map(|id| id.to_bytes()).unwrap_or_default();  | 
 | 97 | +                source_string  | 
 | 98 | +                    .extend_from_slice(&message.sequence_number.unwrap_or_default().to_be_bytes());  | 
 | 99 | +                source_string.extend_from_slice(&message.data[0..16]);  | 
 | 100 | +                gossipsub::MessageId::from(source_string)  | 
 | 101 | +            })  | 
 | 102 | + | 
 | 103 | +              | 
 | 104 | +            // .max_messages_per_rpc(Some(1))  | 
 | 105 | +            .history_length(5)  | 
 | 106 | + | 
 | 107 | +            // .connection_handler_queue_len(50_000)   | 
 | 108 | + | 
 | 109 | +            .mesh_n(10)          // Target mesh peers  | 
 | 110 | +            .mesh_n_low(10)       // Minimum before adding (default: 5)  | 
 | 111 | +            .mesh_n_high(10)     // Maximum before pruning (default  | 
 | 112 | +            // .publish_queue_duration(Duration::from_millis(500))  // default: 5s  | 
 | 113 | +            // .forward_queue_duration(Duration::from_millis(100))  // default: 1s  | 
 | 114 | +      | 
 | 115 | + | 
 | 116 | +            // .heartbeat_interval(Duration::from_millis(200))  | 
 | 117 | +            // Set gossip_lazy to 0 - minimum number of peers to gossip to  | 
 | 118 | +            .gossip_lazy(0)  | 
 | 119 | + | 
 | 120 | +            // Set gossip_factor to 0.0 - factor for dynamic gossip peer selection  | 
 | 121 | +            .gossip_factor(0.0)  | 
 | 122 | + | 
 | 123 | +            // Set history_gossip to 0 - number of past heartbeats to gossip about  | 
 | 124 | +            .history_gossip(0)  | 
 | 125 | + | 
 | 126 | +            // Optional: Set max_ihave_length to 0 - maximum IHAVE message IDs per message  | 
 | 127 | +            .max_ihave_length(0)  | 
 | 128 | + | 
 | 129 | +            // Optional: Set max_ihave_messages to 0 - maximum IHAVE messages per heartbeat  | 
 | 130 | +            .max_ihave_messages(0)  | 
 | 131 | + | 
 | 132 | +            // Optional: Set gossip_retransmission to 0 - disable IWANT retries  | 
 | 133 | +            .gossip_retransimission(0)  | 
 | 134 | +              | 
 | 135 | +            // Enable IDONTWANT optimization  | 
 | 136 | +            // .idontwant_message_size_threshold(1000)  // Adjust based on your message sizes  | 
 | 137 | +            .idontwant_on_publish(true)              // Prevent echo-back on publish  | 
 | 138 | +     | 
 | 139 | +            .build()  | 
 | 140 | +            .expect("Failed to build gossipsub config");  | 
89 | 141 |         Self {  | 
90 | 142 |             limits: connection_limits::Behaviour::new(connection_limits),  | 
91 | 143 |             peer_manager: peer_manager::PeerManager::new(peer_manager_config),  | 
@@ -126,12 +178,8 @@ impl MixedBehaviour {  | 
126 | 178 |             ),  | 
127 | 179 |             sqmr: sqmr::Behaviour::new(streamed_bytes_config),  | 
128 | 180 |             gossipsub: gossipsub::Behaviour::new(  | 
129 |  | -                gossipsub::MessageAuthenticity::Signed(keypair.clone()),  | 
130 |  | -                gossipsub::ConfigBuilder::default()  | 
131 |  | -                    // TODO(shahak): try to reduce this bound.  | 
132 |  | -                    .max_transmit_size(1 << 34)  | 
133 |  | -                    .build()  | 
134 |  | -                    .expect("Failed to build gossipsub config"),  | 
 | 181 | +        gossipsub::MessageAuthenticity::Signed(keypair.clone()),  | 
 | 182 | +                gossipsub_config,  | 
135 | 183 |             )  | 
136 | 184 |             .unwrap_or_else(|err_string| {  | 
137 | 185 |                 panic!(  | 
 | 
0 commit comments