@@ -29,8 +29,6 @@ pub enum Event {
29
29
30
30
/// A in-memory store that uses LRU cache for bounded storage of addresses
31
31
/// and a frequency-based ordering of addresses.
32
- ///
33
- ///
34
32
#[ derive( Default ) ]
35
33
pub struct MemoryStore < T = ( ) > {
36
34
/// The internal store.
@@ -67,7 +65,8 @@ impl<T> MemoryStore<T> {
67
65
is_updated
68
66
}
69
67
70
- /// Update an address record without notifying swarm.
68
+ /// Update an address record without notifying swarm.
69
+ ///
71
70
/// Returns `true` when the address is new.
72
71
fn update_address_silent (
73
72
& mut self ,
@@ -86,7 +85,7 @@ impl<T> MemoryStore<T> {
86
85
87
86
/// Remove an address record.
88
87
///
89
- /// Returns `true` when the address is removed .
88
+ /// Returns `true` when the address existed .
90
89
pub fn remove_address ( & mut self , peer : & PeerId , address : & Multiaddr ) -> bool {
91
90
let is_updated = self . remove_address_silent ( peer, address, true ) ;
92
91
if is_updated {
@@ -96,7 +95,9 @@ impl<T> MemoryStore<T> {
96
95
}
97
96
98
97
/// Remove an address record without notifying swarm.
99
- /// Returns `true` when the address is removed.
98
+ ///
99
+ /// Returns `true` when the address is removed, `false` if the address didn't exist
100
+ /// or the address is permanent and `force` false.
100
101
fn remove_address_silent ( & mut self , peer : & PeerId , address : & Multiaddr , force : bool ) -> bool {
101
102
if let Some ( record) = self . records . get_mut ( peer) {
102
103
if record. remove_address ( address, force) {
@@ -293,7 +294,7 @@ impl Config {
293
294
pub struct PeerRecord < T > {
294
295
/// A LRU(Least Recently Used) cache for addresses.
295
296
/// Will delete the least-recently-used record when full.
296
- /// If the associated `bool` is true, the address can only be force-removed
297
+ /// If the associated `bool` is true, the address can only be force-removed.
297
298
addresses : LruCache < Multiaddr , bool > ,
298
299
/// Custom data attached to the peer.
299
300
custom_data : Option < T > ,
@@ -314,6 +315,7 @@ impl<T> PeerRecord<T> {
314
315
315
316
/// Update the address in the LRU cache, promote it to the front if it exists,
316
317
/// insert it to the front if not.
318
+ ///
317
319
/// Returns true when the address is new.
318
320
pub fn update_address ( & mut self , address : & Multiaddr , permanent : bool ) -> bool {
319
321
if let Some ( was_permanent) = self . addresses . get ( address) {
@@ -327,7 +329,9 @@ impl<T> PeerRecord<T> {
327
329
}
328
330
329
331
/// Remove the address in the LRU cache regardless of its position.
330
- /// Returns true when the address is removed, false when not exist.
332
+ ///
333
+ /// Returns true when the address is removed, false when it didn't exist
334
+ /// or it is permanent and `force` is false.
331
335
pub fn remove_address ( & mut self , address : & Multiaddr , force : bool ) -> bool {
332
336
if !force && self . addresses . peek ( address) == Some ( & true ) {
333
337
return false ;
0 commit comments