@@ -99,6 +99,7 @@ pub struct Config {
99
99
connection_handler_publish_duration : Duration ,
100
100
connection_handler_forward_duration : Duration ,
101
101
idontwant_message_size_threshold : usize ,
102
+ idontwant_on_publish : bool ,
102
103
}
103
104
104
105
impl Config {
@@ -373,15 +374,22 @@ impl Config {
373
374
self . connection_handler_forward_duration
374
375
}
375
376
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
382
383
pub fn idontwant_message_size_threshold ( & self ) -> usize {
383
384
self . idontwant_message_size_threshold
384
385
}
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
+ }
385
393
}
386
394
387
395
impl Default for Config {
@@ -455,6 +463,7 @@ impl Default for ConfigBuilder {
455
463
connection_handler_publish_duration : Duration :: from_secs ( 5 ) ,
456
464
connection_handler_forward_duration : Duration :: from_secs ( 1 ) ,
457
465
idontwant_message_size_threshold : 1000 ,
466
+ idontwant_on_publish : false ,
458
467
} ,
459
468
invalid_protocol : false ,
460
469
}
@@ -841,17 +850,25 @@ impl ConfigBuilder {
841
850
self
842
851
}
843
852
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
850
859
pub fn idontwant_message_size_threshold ( & mut self , size : usize ) -> & mut Self {
851
860
self . config . idontwant_message_size_threshold = size;
852
861
self
853
862
}
854
863
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
+
855
872
/// Constructs a [`Config`] from the given configuration and validates the settings.
856
873
pub fn build ( & self ) -> Result < Config , ConfigBuilderError > {
857
874
// check all constraints on config
@@ -926,6 +943,7 @@ impl std::fmt::Debug for Config {
926
943
"idontwant_message_size_threhold" ,
927
944
& self . idontwant_message_size_threshold ,
928
945
) ;
946
+ let _ = builder. field ( "idontwant_on_publish" , & self . idontwant_on_publish ) ;
929
947
builder. finish ( )
930
948
}
931
949
}
0 commit comments