Skip to content

Commit

Permalink
Merge pull request #1196 from driftluo/fix-reserved-only-outbound-ser…
Browse files Browse the repository at this point in the history
…vice

fix: reserved only do nothing except for connect all reserved peers
  • Loading branch information
doitian authored Jul 6, 2019
2 parents 03f2838 + 36c46a2 commit 3298eaf
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions network/src/services/outbound_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ impl OutboundPeerService {
}
paddrs
});
let p2p_control = self.p2p_control.clone();
trace!(
"count={}, attempt_peers: {:?} is_feeler: {}",
count,
Expand All @@ -62,10 +61,26 @@ impl OutboundPeerService {
for paddr in attempt_peers {
let PeerAddr { peer_id, addr, .. } = paddr;
if is_feeler {
self.network_state.dial_feeler(&p2p_control, &peer_id, addr);
self.network_state
.dial_feeler(&self.p2p_control, &peer_id, addr);
} else {
self.network_state
.dial_identify(&p2p_control, &peer_id, addr);
.dial_identify(&self.p2p_control, &peer_id, addr);
}
}
}

fn try_dial_reserved(&self) {
// This will never panic because network start has already been checked
for (peer_id, addr) in self
.network_state
.config
.reserved_peers()
.expect("address must be correct")
{
if self.network_state.query_session_id(&peer_id).is_none() {
self.network_state
.dial_identify(&self.p2p_control, &peer_id, addr);
}
}
}
Expand All @@ -86,7 +101,9 @@ impl Future for OutboundPeerService {
if last_connect > self.try_connect_interval {
let status = self.network_state.connection_status();
let new_outbound = status.max_outbound - status.unreserved_outbound;
if new_outbound > 0 {
if self.network_state.config.reserved_only {
self.try_dial_reserved()
} else if new_outbound > 0 {
// dial peers
self.dial_peers(false, new_outbound as u32);
} else {
Expand Down

0 comments on commit 3298eaf

Please sign in to comment.