@@ -99,6 +99,7 @@ pub struct Config {
9999 connection_handler_publish_duration : Duration ,
100100 connection_handler_forward_duration : Duration ,
101101 idontwant_message_size_threshold : usize ,
102+ idontwant_on_publish : bool ,
102103}
103104
104105impl Config {
@@ -373,15 +374,22 @@ impl Config {
373374 self . connection_handler_forward_duration
374375 }
375376
376- // The message size threshold for which IDONTWANT messages are sent.
377- // Sending IDONTWANT messages for small messages can have a negative effect to the overall
378- // traffic and CPU load. This acts as a lower bound cutoff for the message size to which
379- // IDONTWANT won't be sent to peers. Only works if the peers support Gossipsub1.2
380- // (see https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.2.md#idontwant-message)
381- // default is 1kB
377+ /// The message size threshold for which IDONTWANT messages are sent.
378+ /// Sending IDONTWANT messages for small messages can have a negative effect to the overall
379+ /// traffic and CPU load. This acts as a lower bound cutoff for the message size to which
380+ /// IDONTWANT won't be sent to peers. Only works if the peers support Gossipsub1.2
381+ /// (see < https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.2.md#idontwant-message> )
382+ /// default is 1kB
382383 pub fn idontwant_message_size_threshold ( & self ) -> usize {
383384 self . idontwant_message_size_threshold
384385 }
386+
387+ /// Send IDONTWANT messages after publishing message on gossip. This is an optimisation
388+ /// to avoid bandwidth consumption by downloading the published message over gossip.
389+ /// By default it is false.
390+ pub fn idontwant_on_publish ( & self ) -> bool {
391+ self . idontwant_on_publish
392+ }
385393}
386394
387395impl Default for Config {
@@ -455,6 +463,7 @@ impl Default for ConfigBuilder {
455463 connection_handler_publish_duration : Duration :: from_secs ( 5 ) ,
456464 connection_handler_forward_duration : Duration :: from_secs ( 1 ) ,
457465 idontwant_message_size_threshold : 1000 ,
466+ idontwant_on_publish : false ,
458467 } ,
459468 invalid_protocol : false ,
460469 }
@@ -841,17 +850,25 @@ impl ConfigBuilder {
841850 self
842851 }
843852
844- // The message size threshold for which IDONTWANT messages are sent.
845- // Sending IDONTWANT messages for small messages can have a negative effect to the overall
846- // traffic and CPU load. This acts as a lower bound cutoff for the message size to which
847- // IDONTWANT won't be sent to peers. Only works if the peers support Gossipsub1.2
848- // (see https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.2.md#idontwant-message)
849- // default is 1kB
853+ /// The message size threshold for which IDONTWANT messages are sent.
854+ /// Sending IDONTWANT messages for small messages can have a negative effect to the overall
855+ /// traffic and CPU load. This acts as a lower bound cutoff for the message size to which
856+ /// IDONTWANT won't be sent to peers. Only works if the peers support Gossipsub1.2
857+ /// (see < https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.2.md#idontwant-message> )
858+ /// default is 1kB
850859 pub fn idontwant_message_size_threshold ( & mut self , size : usize ) -> & mut Self {
851860 self . config . idontwant_message_size_threshold = size;
852861 self
853862 }
854863
864+ /// Send IDONTWANT messages after publishing message on gossip. This is an optimisation
865+ /// to avoid bandwidth consumption by downloading the published message over gossip.
866+ /// By default it is false.
867+ pub fn idontwant_on_publish ( & mut self , idontwant_on_publish : bool ) -> & mut Self {
868+ self . config . idontwant_on_publish = idontwant_on_publish;
869+ self
870+ }
871+
855872 /// Constructs a [`Config`] from the given configuration and validates the settings.
856873 pub fn build ( & self ) -> Result < Config , ConfigBuilderError > {
857874 // check all constraints on config
@@ -926,6 +943,7 @@ impl std::fmt::Debug for Config {
926943 "idontwant_message_size_threhold" ,
927944 & self . idontwant_message_size_threshold ,
928945 ) ;
946+ let _ = builder. field ( "idontwant_on_publish" , & self . idontwant_on_publish ) ;
929947 builder. finish ( )
930948 }
931949}
0 commit comments