node: use method to access session's Node ID

Make accessing an important session value, the Node ID, as a method to
Session.

Signed-off-by: Slack Coder <slackcoder@server.ky>
This commit is contained in:
Slack Coder 2022-10-29 19:33:42 -05:00 committed by Alexis Sellier
parent 6f3a598cc1
commit 25c982cd8c
No known key found for this signature in database
2 changed files with 8 additions and 7 deletions

View File

@ -1126,13 +1126,7 @@ impl Sessions {
}
pub fn by_id(&self, id: &NodeId) -> Option<&Session> {
self.0.values().find(|p| {
if let session::State::Negotiated { id: _id, .. } = &p.state {
_id == id
} else {
false
}
})
self.0.values().find(|p| p.node_id() == Some(*id))
}
/// Iterator over fully negotiated peers.

View File

@ -122,4 +122,11 @@ impl Session {
}
Ok(())
}
pub fn node_id(&self) -> Option<NodeId> {
if let State::Negotiated { id, .. } = &self.state {
return Some(*id);
}
None
}
}