@@ -74,6 +74,23 @@ pub use protocol::{ConnectionType, KadPeer};
74
74
pub use query:: QueryId ;
75
75
pub use record:: { store, Key as RecordKey , ProviderRecord , Record } ;
76
76
77
+ #[ cfg( all( feature = "k-4" , not( any( feature = "k-8" , feature = "k-12" , feature = "k-16" ) ) ) ) ]
78
+ const K : usize = 4 ;
79
+ #[ cfg( all( feature = "k-8" , not( any( feature = "k-4" , feature = "k-12" , feature = "k-16" ) ) ) ) ]
80
+ const K : usize = 8 ;
81
+ #[ cfg( all( feature = "k-12" , not( any( feature = "k-4" , feature = "k-8" , feature = "k-16" ) ) ) ) ]
82
+ const K : usize = 12 ;
83
+ #[ cfg( all( feature = "k-16" , not( any( feature = "k-4" , feature = "k-8" , feature = "k-12" ) ) ) ) ]
84
+ const K : usize = 16 ;
85
+ // Enable if none of the k-n features are enabled or if all the k-n features are enabled.
86
+ #[ cfg( any( not( any( feature = "k-4" , feature = "k-8" , feature = "k-12" , feature = "k-16" ) ) , all(
87
+ feature = "k-4" ,
88
+ feature = "k-8" ,
89
+ feature = "k-12" ,
90
+ feature = "k-16"
91
+ ) ) ) ]
92
+ const K : usize = 20 ;
93
+
77
94
/// The `k` parameter of the Kademlia specification.
78
95
///
79
96
/// This parameter determines:
@@ -86,9 +103,7 @@ pub use record::{store, Key as RecordKey, ProviderRecord, Record};
86
103
/// The choice of (1) is fixed to this constant. The replication factor is configurable
87
104
/// but should generally be no greater than `K_VALUE`. All nodes in a Kademlia
88
105
/// DHT should agree on the choices made for (1) and (2).
89
- ///
90
- /// The current value is `20`.
91
- pub const K_VALUE : NonZeroUsize = NonZeroUsize :: new ( 20 ) . unwrap ( ) ;
106
+ pub const K_VALUE : NonZeroUsize = NonZeroUsize :: new ( K ) . unwrap ( ) ;
92
107
93
108
/// The `α` parameter of the Kademlia specification.
94
109
///
0 commit comments