Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
fix: expand ConnInfoReq handling conditions.
Browse files Browse the repository at this point in the history
- Also accept incoming ConnInfoRequests to us as a Client authority.
- We carry over Online votes into the new prefix.
- Remove previous commit patch to clear_candidate from peer_mgr on pfx change
- Update poll_and_resend to not always wait for unconsensused transparent observations.
  • Loading branch information
Viv-Rajkumar committed Apr 19, 2019
1 parent 57cd490 commit d081800
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
6 changes: 4 additions & 2 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,10 @@ impl Node {
}

/// Indicates if there are any pending observations in the parsec object
pub fn has_unconsensused_observations(&self) -> bool {
self.machine.current().has_unconsensused_observations()
pub fn has_unconsensused_observations(&self, filter_opaque: bool) -> bool {
self.machine
.current()
.has_unconsensused_observations(filter_opaque)
}

/// Indicates if a given `PublicId` is in the peer manager as a routing peer
Expand Down
5 changes: 0 additions & 5 deletions src/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,6 @@ impl PeerManager {
);
}

/// Removes any existing candidate
pub fn clear_candidate(&mut self) {
self.candidate = Candidate::None;
}

/// Adds a potential candidate to the candidate list setting its state to `VotedFor`. If
/// another ongoing (i.e. unapproved) candidate exists, or if the candidate is unsuitable for
/// adding to our section, returns an error.
Expand Down
4 changes: 2 additions & 2 deletions src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ impl State {
}
}

pub fn has_unconsensused_observations(&self) -> bool {
pub fn has_unconsensused_observations(&self, filter_opaque: bool) -> bool {
match *self {
State::Node(ref state) => state.has_unconsensused_observations(),
State::Node(ref state) => state.has_unconsensused_observations(filter_opaque),
_ => false,
}
}
Expand Down
39 changes: 28 additions & 11 deletions src/states/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -991,10 +991,6 @@ impl Node {
self.gen_pfx_info = Some(gen_pfx_info);
let _ = self.init_parsec()?; // We don't reset the chain on prefix change.

// Clear any pending candidate
// TODO: maybe also disconnect if currently connected.
self.peer_mgr.clear_candidate();

let neighbour_infos: Vec<_> = self.chain.neighbour_infos().cloned().collect();
for ni in neighbour_infos {
if sibling_pfx != *ni.prefix() {
Expand Down Expand Up @@ -1025,8 +1021,7 @@ impl Node {
cached_events
.iter()
.filter(|event| match **event {
NetworkEvent::Online(_pub_id, _) => false,
NetworkEvent::Offline(pub_id) => {
NetworkEvent::Online(pub_id, _) | NetworkEvent::Offline(pub_id) => {
our_pfx.matches(pub_id.name()) && !completed_events.contains(event)
}
NetworkEvent::SectionInfo(ref sec_info) => our_pfx.is_neighbour(sec_info.prefix()),
Expand Down Expand Up @@ -1384,6 +1379,15 @@ impl Node {
},
src @ ManagedNode(_),
dst @ ManagedNode(_),
)
| (
ConnectionInfoRequest {
encrypted_conn_info,
pub_id,
msg_id,
},
src @ ManagedNode(_),
dst @ Client { .. },
) => self.handle_connection_info_request(
encrypted_conn_info,
pub_id,
Expand Down Expand Up @@ -3298,11 +3302,24 @@ impl Node {
self.clients_rate_limiter.usage_map().clone()
}

pub fn has_unconsensused_observations(&self) -> bool {
self.parsec_map
.values()
.last()
.map_or(false, Parsec::has_unconsensused_observations)
pub fn has_unconsensused_observations(&self, filter_opaque: bool) -> bool {
if filter_opaque {
match self.parsec_map.values().last() {
None => false,
Some(par) => par.our_unpolled_observations().any(|obs| {
if let parsec::Observation::OpaquePayload(_) = obs {
true
} else {
false
}
}),
}
} else {
self.parsec_map
.values()
.last()
.map_or(false, Parsec::has_unconsensused_observations)
}
}

pub fn is_routing_peer(&self, pub_id: &PublicId) -> bool {
Expand Down
9 changes: 7 additions & 2 deletions tests/mock_crust/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,14 @@ pub fn poll_all(nodes: &mut [TestNode], clients: &mut [TestClient]) -> bool {
/// Polls and processes all events, until there are no unacknowledged messages left.
pub fn poll_and_resend(nodes: &mut [TestNode], clients: &mut [TestClient]) {
let mut fired_connecting_peer_timeout = false;
for _ in 0..MAX_POLL_CALLS {
for i in 0..MAX_POLL_CALLS {
let node_busy = |node: &TestNode| {
node.inner.has_unconsensused_observations() || node.inner.has_unacked_msg()
// after MAX_POLL_CALLS / 2 only filter for opaque events
// to avoid stalling the test due to lack of parsec voters.
node.inner.has_unacked_msg()
|| node
.inner
.has_unconsensused_observations(i > MAX_POLL_CALLS / 2)
};
let client_busy = |client: &TestClient| client.inner.has_unacked_msg();
if poll_all(nodes, clients)
Expand Down

0 comments on commit d081800

Please sign in to comment.