Skip to content

Commit

Permalink
implement get_raw_graph again
Browse files Browse the repository at this point in the history
  • Loading branch information
pmnoxx committed Feb 2, 2021
1 parent 8402c6a commit 7a63251
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions chain/network/src/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ impl PeerManagerActor {
duration,
|act, _ctx| {
act.routing_table.update();
//#[cfg(feature = "metric_recorder")]
// act.metric_recorder.set_graph(act.routing_table.get_raw_graph())
#[cfg(feature = "metric_recorder")]
act.metric_recorder.set_graph(act.routing_table.get_raw_graph())
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion chain/network/src/recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl MetricRecorder {
self
}

pub fn set_graph(&mut self, graph: &HashMap<PeerId, HashSet<PeerId>>) {
pub fn set_graph(&mut self, graph: HashMap<PeerId, HashSet<PeerId>>) {
self.graph.clear();
for (u, u_adj) in graph.iter() {
for v in u_adj {
Expand Down
16 changes: 13 additions & 3 deletions chain/network/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,9 +740,19 @@ impl RoutingTable {
}
}

// pub fn get_raw_graph(&self) -> &HashMap<PeerId, HashSet<PeerId>> {
// &self.raw_graph.adjacency
// }
// This method is slow
pub fn get_raw_graph(&self) -> HashMap<PeerId, HashSet<PeerId>> {
let mut result = HashMap::new();
for (key, neighbors) in self.raw_graph.adjacency.iter() {
let mut tmp: HashSet<PeerId> = HashSet::new();
for node in neighbors.iter() {
tmp.insert(self.raw_graph.id2p.get(node).cloned().unwrap());
}
let key = self.raw_graph.id2p.get(&key).cloned().unwrap();
result.insert(key, tmp);
}
result
}
}

pub struct ProcessEdgeResult {
Expand Down

0 comments on commit 7a63251

Please sign in to comment.