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
89
90
91
92
93
94
95
96
97
98
crate::ix!();
pub struct AddrManInner {
/**
| Source of random numbers for randomization
| in inner loops
|
*/
pub insecure_rand: RefCell<FastRandomContext>,
/**
| last used nId
|
*/
pub n_id_count: i32,
/**
| table with information about all n_ids
|
*/
pub map_info: HashMap<i32,AddrInfo>,
/**
| find an nId based on its network address
| and port.
|
*/
pub map_addr: HashMap<Service,i32,ServiceHash>,
/**
| randomly-ordered vector of all n_ids
|
| This is mutable because it is unobservable
| outside the class, so any changes to it
| (even in const methods) are also
| unobservable.
*/
pub random: RefCell<Vec<i32>>,
/**
| number of "tried" entries
|
*/
pub n_tried: i32,
/**
| list of "tried" buckets
|
*/
pub vv_tried: AddrManTriedBucketList,
/**
| number of (unique) "new" entries
|
*/
pub n_new: i32,
/**
| list of "new" buckets
|
*/
pub vv_new: AddrManNewBucketList,
/**
| last time Good was called (memory
| only). Initially set to 1 so that "never" is
| strictly worse.
*/
pub n_last_good: i64,
}
impl AddrManInner {
pub fn default_new_bucket_list() -> AddrManNewBucketList {
[[-1; ADDRMAN_NEW_BUCKET_COUNT]; ADDRMAN_BUCKET_SIZE]
}
pub fn default_tried_bucket_list() -> AddrManTriedBucketList {
[[-1; ADDRMAN_TRIED_BUCKET_COUNT]; ADDRMAN_BUCKET_SIZE]
}
pub fn new(deterministic: bool, insecure_rand: FastRandomContext) -> Self {
Self {
insecure_rand: RefCell::new(insecure_rand),
n_id_count: 0,
map_info: HashMap::<i32,AddrInfo>::default(),
map_addr: HashMap::<Service,i32,ServiceHash>::default(),
random: RefCell::new(vec![]),
n_tried: 0,
vv_tried: Self::default_tried_bucket_list(),
n_new: 0,
vv_new: Self::default_new_bucket_list(),
n_last_good: 1,
}
}
}