1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
crate::ix!();
impl AddrManInner {
pub unsafe fn good(&mut self,
addr: &Service,
test_before_evict: bool,
n_time: i64,
n_key: &u256,
asmap: &Vec<bool>,
tried_collisions: *mut HashSet<i32>) {
unsafe {
let mut n_id = i32::default();
self.n_last_good = n_time;
let info: *mut AddrInfo = self.find(addr,Some(&mut n_id as *mut _));
// if not found, bail out
if info == std::ptr::null_mut() {
return;
}
// update info
(*info).n_last_success = n_time;
(*info).n_last_try = n_time;
(*info).n_attempts = 0;
// n_time is not updated here, to avoid
// leaking information about
// currently-connected peers.
// if it is already in the tried set,
// don't do anything else
if (*info).in_tried {
return;
}
// if it is not in new, something bad
// happened
if !assume!((*info).n_ref_count > 0) {
return;
}
// which tried bucket to move the entry to
let tried_bucket: usize = (*info).get_tried_bucket(n_key, asmap).try_into().unwrap();
let tried_bucket_pos: usize = (*info).get_bucket_position(n_key, false, tried_bucket).try_into().unwrap();
// Will moving this address into tried evict another entry?
if test_before_evict && (self.vv_tried[tried_bucket][tried_bucket_pos] != -1) {
if (*tried_collisions).len() < ADDRMAN_SET_TRIED_COLLISION_SIZE {
(*tried_collisions).insert(n_id);
}
// Output the entry we'd be colliding with, for debugging purposes
let colliding_entry = self.map_info.get(&self.vv_tried[tried_bucket][tried_bucket_pos]);
log_print!(
bc_log::addrman,
"Collision with %s while attempting to move %s to tried table. Collisions=%d\n",
match colliding_entry.is_some() {
true => (*colliding_entry).to_string(),
false => ""
},
addr.to_string(),
(*tried_collisions).len()
);
} else {
// move nId to the tried tables
self.make_tried(&mut *info,n_id,n_key,asmap);
log_print!(
bc_log::addrman,
"Moved %s mapped to AS%i to tried[%i][%i]\n",
addr.to_string(),
addr.get_mappedas(asmap),
tried_bucket,
tried_bucket_pos
);
}
}
}
}