This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Remove NetworkService::config() #8653
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
use std::sync::Arc; | ||
use std::collections::{HashMap, BTreeMap}; | ||
use std::io; | ||
use std::ops::Range; | ||
use std::time::Duration; | ||
use bytes::Bytes; | ||
use devp2p::NetworkService; | ||
|
@@ -452,11 +453,18 @@ impl ChainNotify for EthSync { | |
} | ||
|
||
fn start(&self) { | ||
match self.network.start().map_err(Into::into) { | ||
Err(ErrorKind::Io(ref e)) if e.kind() == io::ErrorKind::AddrInUse => warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", self.network.config().listen_address.expect("Listen address is not set.")), | ||
Err(err) => warn!("Error starting network: {}", err), | ||
match self.network.start() { | ||
Err((err, listen_address)) => { | ||
match err.into() { | ||
ErrorKind::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => { | ||
warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", listen_address.expect("Listen address is not set.")) | ||
}, | ||
err => warn!("Error starting network: {}", err), | ||
} | ||
}, | ||
_ => {}, | ||
} | ||
|
||
self.network.register_protocol(self.eth_handler.clone(), self.subprotocol_name, &[ETH_PROTOCOL_VERSION_62, ETH_PROTOCOL_VERSION_63]) | ||
.unwrap_or_else(|e| warn!("Error registering ethereum protocol: {:?}", e)); | ||
// register the warp sync subprotocol | ||
|
@@ -520,8 +528,10 @@ pub trait ManageNetwork : Send + Sync { | |
fn start_network(&self); | ||
/// Stop network | ||
fn stop_network(&self); | ||
/// Query the current configuration of the network | ||
fn network_config(&self) -> NetworkConfiguration; | ||
/// 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
fn num_peers_range(&self) -> Range<u32>; | ||
/// Get network context for protocol. | ||
fn with_proto_context(&self, proto: ProtocolId, f: &mut FnMut(&NetworkContext)); | ||
} | ||
|
@@ -561,8 +571,8 @@ impl ManageNetwork for EthSync { | |
self.stop(); | ||
} | ||
|
||
fn network_config(&self) -> NetworkConfiguration { | ||
NetworkConfiguration::from(self.network.config().clone()) | ||
fn num_peers_range(&self) -> Range<u32> { | ||
self.network.num_peers_range() | ||
} | ||
|
||
fn with_proto_context(&self, proto: ProtocolId, f: &mut FnMut(&NetworkContext)) { | ||
|
@@ -815,11 +825,15 @@ impl ManageNetwork for LightSync { | |
} | ||
|
||
fn start_network(&self) { | ||
match self.network.start().map_err(Into::into) { | ||
Err(ErrorKind::Io(ref e)) if e.kind() == io::ErrorKind::AddrInUse => { | ||
warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", self.network.config().listen_address.expect("Listen address is not set.")) | ||
} | ||
Err(err) => warn!("Error starting network: {}", err), | ||
match self.network.start() { | ||
Err((err, listen_address)) => { | ||
match err.into() { | ||
ErrorKind::Io(ref e) if e.kind() == io::ErrorKind::AddrInUse => { | ||
warn!("Network port {:?} is already in use, make sure that another instance of an Ethereum client is not running or change the port using the --port option.", listen_address.expect("Listen address is not set.")) | ||
}, | ||
err => warn!("Error starting network: {}", err), | ||
} | ||
}, | ||
_ => {}, | ||
} | ||
|
||
|
@@ -836,8 +850,8 @@ impl ManageNetwork for LightSync { | |
self.network.stop(); | ||
} | ||
|
||
fn network_config(&self) -> NetworkConfiguration { | ||
NetworkConfiguration::from(self.network.config().clone()) | ||
fn num_peers_range(&self) -> Range<u32> { | ||
self.network.num_peers_range() | ||
} | ||
|
||
fn with_proto_context(&self, proto: ProtocolId, f: &mut FnMut(&NetworkContext)) { | ||
|
@@ -848,12 +862,13 @@ impl ManageNetwork for LightSync { | |
impl LightSyncProvider for LightSync { | ||
fn peer_numbers(&self) -> PeerNumbers { | ||
let (connected, active) = self.proto.peer_count(); | ||
let config = self.network_config(); | ||
let peers_range = self.num_peers_range(); | ||
debug_assert!(peers_range.end > peers_range.start); | ||
PeerNumbers { | ||
connected: connected, | ||
active: active, | ||
max: config.max_peers as usize, | ||
min: config.min_peers as usize, | ||
max: peers_range.end as usize - 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is the range exclusive and not inclusive? This is a breaking change. If someone have |
||
min: peers_range.start as usize, | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just remove
struct NetworkConfiguration
entirely?