Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
fix(ManageNetwork): replace Range -> RangeIncls
Browse files Browse the repository at this point in the history
Fixes `TODO: Range should be changed to RangeInclusive once stable (rust-lang/rust#50758
  • Loading branch information
niklasad1 committed Jan 17, 2019
1 parent 2a7ed45 commit 4a675b7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
16 changes: 7 additions & 9 deletions ethcore/sync/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use std::sync::{Arc, mpsc, atomic};
use std::collections::{HashMap, BTreeMap};
use std::io;
use std::ops::Range;
use std::ops::RangeInclusive;
use std::time::Duration;
use bytes::Bytes;
use devp2p::NetworkService;
Expand Down Expand Up @@ -615,9 +615,7 @@ pub trait ManageNetwork : Send + Sync {
/// Stop network
fn stop_network(&self);
/// Returns the minimum and maximum peers.
/// Note that `range.end` is *exclusive*.
// TODO: Range should be changed to RangeInclusive once stable (https://github.com/rust-lang/rust/pull/50758)
fn num_peers_range(&self) -> Range<u32>;
fn num_peers_range(&self) -> RangeInclusive<u32>;
/// Get network context for protocol.
fn with_proto_context(&self, proto: ProtocolId, f: &mut FnMut(&NetworkContext));
}
Expand Down Expand Up @@ -656,7 +654,7 @@ impl ManageNetwork for EthSync {
self.stop();
}

fn num_peers_range(&self) -> Range<u32> {
fn num_peers_range(&self) -> RangeInclusive<u32> {
self.network.num_peers_range()
}

Expand Down Expand Up @@ -935,7 +933,7 @@ impl ManageNetwork for LightSync {
self.network.stop();
}

fn num_peers_range(&self) -> Range<u32> {
fn num_peers_range(&self) -> RangeInclusive<u32> {
self.network.num_peers_range()
}

Expand All @@ -948,12 +946,12 @@ impl LightSyncProvider for LightSync {
fn peer_numbers(&self) -> PeerNumbers {
let (connected, active) = self.proto.peer_count();
let peers_range = self.num_peers_range();
debug_assert!(peers_range.end > peers_range.start);
debug_assert!(peers_range.end() > peers_range.start());
PeerNumbers {
connected: connected,
active: active,
max: peers_range.end as usize - 1,
min: peers_range.start as usize,
max: *peers_range.end() as usize - 1,
min: *peers_range.start() as usize,
}
}

Expand Down
10 changes: 3 additions & 7 deletions util/network-devp2p/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use host::Host;
use io::*;
use parking_lot::RwLock;
use std::net::SocketAddr;
use std::ops::Range;
use std::ops::RangeInclusive;
use std::sync::Arc;
use ansi_term::Colour;
use network::ConnectionFilter;
Expand Down Expand Up @@ -95,12 +95,8 @@ impl NetworkService {
}

/// Returns the number of peers allowed.
///
/// Keep in mind that `range.end` is *exclusive*.
pub fn num_peers_range(&self) -> Range<u32> {
let start = self.config.min_peers;
let end = self.config.max_peers + 1;
start .. end
pub fn num_peers_range(&self) -> RangeInclusive<u32> {
self.config.min_peers..=self.config.max_peers
}

/// Returns external url if available.
Expand Down

0 comments on commit 4a675b7

Please sign in to comment.