@@ -14,6 +14,36 @@ use poldercast::{
14
14
use slog:: Logger ;
15
15
use std:: sync:: { Arc , RwLock } ;
16
16
17
+ // object holding a count of available, unreachable and quarantined nodes.
18
+ #[ derive( Clone ) ]
19
+ pub struct NodeCount {
20
+ all_available_nodes : usize ,
21
+ all_unreachable_nodes : usize ,
22
+ all_quarantined_nodes : usize ,
23
+ }
24
+
25
+ impl NodeCount {
26
+ pub fn new ( nodes : & poldercast:: Nodes ) -> Self {
27
+ NodeCount {
28
+ all_available_nodes : nodes. all_available_nodes ( ) . len ( ) ,
29
+ all_unreachable_nodes : nodes. all_unreachable_nodes ( ) . len ( ) ,
30
+ all_quarantined_nodes : nodes. all_quarantined_nodes ( ) . len ( ) ,
31
+ }
32
+ }
33
+
34
+ pub fn all_available_nodes_count ( & self ) -> usize {
35
+ self . all_available_nodes
36
+ }
37
+
38
+ pub fn all_unreachable_nodes_count ( & self ) -> usize {
39
+ self . all_unreachable_nodes
40
+ }
41
+
42
+ pub fn all_quarantined_nodes_count ( & self ) -> usize {
43
+ self . all_quarantined_nodes
44
+ }
45
+ }
46
+
17
47
/// object holding the P2pTopology of the Node
18
48
#[ derive( Clone ) ]
19
49
pub struct P2pTopology {
@@ -138,6 +168,10 @@ impl P2pTopology {
138
168
. collect ( )
139
169
}
140
170
171
+ pub fn nodes_count ( & self ) -> NodeCount {
172
+ NodeCount :: new ( self . lock . read ( ) . unwrap ( ) . nodes ( ) )
173
+ }
174
+
141
175
/// register a strike against the given node id
142
176
///
143
177
/// the function returns `None` if the node was not even in the
0 commit comments