Skip to content

Commit

Permalink
Address even more review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Dec 20, 2021
1 parent aba62d6 commit 5775e15
Show file tree
Hide file tree
Showing 29 changed files with 854 additions and 711 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bee-network/bee-autopeering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = [ "iota", "bee", "framework", "network", "autopeering" ]
homepage = "https://www.iota.org"

[dependencies]
bee-common = { path = "../../bee-common/bee-common", default-features = false }
bee-runtime = { version = "0.1.1-alpha", path = "../../bee-runtime", default-features = false, optional = true }

async-trait = { version = "0.1.51", default-features = false }
base64 = { version = "0.13.0", default-features = false, features = [ "alloc" ] }
Expand Down
20 changes: 10 additions & 10 deletions bee-network/bee-autopeering/examples/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ fn read_config() -> AutopeeringConfigJsonBuilder {
"/dns/entry-hornet-0.h.chrysalis-mainnet.iotaledger.net/udp/14626/autopeering/iotaPHdAn7eueBnXtikZMwhfPXaeGJGXDt4RBuLuGgb",
"/dns/entry-hornet-1.h.chrysalis-mainnet.iotaledger.net/udp/14626/autopeering/iotaJJqMd5CQvv1A61coSQCYW9PNT1QKPs7xh2Qg5K2",
"/dns/entry-mainnet.tanglebay.com/udp/14626/autopeering/iot4By1FD4pFLrGJ6AAe7YEeSu9RbW9xnPUmxMdQenC"
],
"entryNodesPreferIPv6": false,
"runAsEntryNode": false
]
}"#;

// "entryNodesPreferIPv6": false,
// "runAsEntryNode": false
serde_json::from_str(config_json).expect("error deserializing json config")
}

#[tokio::main]
async fn main() {
// Set up logger.
setup_logger(LevelFilter::Debug);
setup_logger(LevelFilter::Info);

// Read the config from a JSON file/string.
let config = read_config().finish();
Expand All @@ -74,25 +74,25 @@ async fn main() {

// Storage config.
// No config is necessary for the `InMemoryPeerStore`.
// let peerstore_config = ();
// let peer_store_config = ();

// Sled peerstore:
let peerstore_config = SledPeerStoreConfig::new().path("./peerstore");
// Sled peer store:
let peer_store_config = SledPeerStoreConfig::new().path("./peerstore");

// Neighbor validator.
let neighbor_validator = GossipNeighborValidator {};

// Shutdown signal.
let quit_signal = ctrl_c();
let term_signal = ctrl_c();

// Initialize the Autopeering service.
let mut event_rx = bee_autopeering::init::<SledPeerStore, _, _, GossipNeighborValidator>(
config.clone(),
version,
network_name,
local,
peerstore_config,
quit_signal,
peer_store_config,
term_signal,
neighbor_validator,
)
.await
Expand Down
31 changes: 15 additions & 16 deletions bee-network/bee-autopeering/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
//! Autopeering configuration.
//!
//! ## JSON Example
//!
//! ```json
//! "autopeering": {
//! "enabled": true,
//! "bindAddress": "0.0.0.0:14626",
//! "entryNodes": [
//! "/dns/lucamoser.ch/udp/14826/autopeering/4H6WV54tB29u8xCcEaMGQMn37LFvM1ynNpp27TTXaqNM",
//! "/dns/entry-hornet-0.h.chrysalis-mainnet.iotaledger.net/udp/14626/autopeering/iotaPHdAn7eueBnXtikZMwhfPXaeGJGXDt4RBuLuGgb",
//! "/dns/entry-hornet-1.h.chrysalis-mainnet.iotaledger.net/udp/14626/autopeering/iotaJJqMd5CQvv1A61coSQCYW9PNT1QKPs7xh2Qg5K2",
//! "/dns/entry-mainnet.tanglebay.com/udp/14626/autopeering/iot4By1FD4pFLrGJ6AAe7YEeSu9RbW9xnPUmxMdQenC"
Expand All @@ -25,7 +25,6 @@
//! enabled = true
//! bind_address = "0.0.0.0:14626"
//! entry_nodes = [
//! "/dns/lucamoser.ch/udp/14826/autopeering/4H6WV54tB29u8xCcEaMGQMn37LFvM1ynNpp27TTXaqNM",
//! "/dns/entry-hornet-0.h.chrysalis-mainnet.iotaledger.net/udp/14626/autopeering/iotaPHdAn7eueBnXtikZMwhfPXaeGJGXDt4RBuLuGgb",
//! "/dns/entry-hornet-1.h.chrysalis-mainnet.iotaledger.net/udp/14626/autopeering/iotaJJqMd5CQvv1A61coSQCYW9PNT1QKPs7xh2Qg5K2",
//! "/dns/entry-mainnet.tanglebay.com/udp/14626/autopeering/iot4By1FD4pFLrGJ6AAe7YEeSu9RbW9xnPUmxMdQenC"
Expand All @@ -42,9 +41,10 @@ use std::{
net::{IpAddr, Ipv4Addr, SocketAddr},
};

const AUTOPEERING_ENABLED_DEFAULT: bool = false;
// TODO: watch out for possible constification regarding `SocketAddr::new()`.
const AUTOPEERING_BIND_ADDR_DEFAULT: IpAddr = IpAddr::V4(Ipv4Addr::UNSPECIFIED);
const AUTOPEERING_BIND_PORT_DEFAULT: u16 = 0;
const AUTOPEERING_BIND_PORT_DEFAULT: u16 = 14626;
const ENTRYNODES_PREFER_IPV6_DEFAULT: bool = false;
const RUN_AS_ENTRYNODE_DEFAULT: bool = false;
const DROP_NEIGHBORS_ON_SALT_UPDATE_DEFAULT: bool = false;
Expand All @@ -61,7 +61,7 @@ pub struct AutopeeringConfig {
}

impl AutopeeringConfig {
/// Wether autopeering should be enabled.
/// Whether autopeering should be enabled.
pub fn enabled(&self) -> bool {
self.enabled
}
Expand Down Expand Up @@ -132,7 +132,7 @@ impl AutopeeringConfig {
#[cfg_attr(test, derive(Eq, PartialEq))]
#[serde(rename = "autopeering")]
pub struct AutopeeringConfigJsonBuilder {
/// Wether autopeering should be enabled.
/// Whether autopeering should be enabled.
pub enabled: bool,
/// The bind address for the server.
#[serde(rename = "bindAddress")]
Expand Down Expand Up @@ -170,12 +170,12 @@ impl AutopeeringConfigJsonBuilder {
impl Default for AutopeeringConfigJsonBuilder {
fn default() -> Self {
Self {
enabled: false,
enabled: AUTOPEERING_ENABLED_DEFAULT,
bind_addr: SocketAddr::new(AUTOPEERING_BIND_ADDR_DEFAULT, AUTOPEERING_BIND_PORT_DEFAULT),
entry_nodes: Vec::default(),
entry_nodes_prefer_ipv6: Some(false),
run_as_entry_node: Some(false),
drop_neighbors_on_salt_update: Some(false),
entry_nodes_prefer_ipv6: Some(ENTRYNODES_PREFER_IPV6_DEFAULT),
run_as_entry_node: Some(RUN_AS_ENTRYNODE_DEFAULT),
drop_neighbors_on_salt_update: Some(DROP_NEIGHBORS_ON_SALT_UPDATE_DEFAULT),
}
}
}
Expand Down Expand Up @@ -220,14 +220,13 @@ impl AutopeeringConfigTomlBuilder {

impl Default for AutopeeringConfigTomlBuilder {
fn default() -> Self {
let json_builder = AutopeeringConfigJsonBuilder::default();
Self {
enabled: json_builder.enabled,
bind_addr: json_builder.bind_addr,
entry_nodes: json_builder.entry_nodes,
entry_nodes_prefer_ipv6: json_builder.entry_nodes_prefer_ipv6,
run_as_entry_node: json_builder.run_as_entry_node,
drop_neighbors_on_salt_update: json_builder.drop_neighbors_on_salt_update,
enabled: AUTOPEERING_ENABLED_DEFAULT,
bind_addr: SocketAddr::new(AUTOPEERING_BIND_ADDR_DEFAULT, AUTOPEERING_BIND_PORT_DEFAULT),
entry_nodes: Vec::default(),
entry_nodes_prefer_ipv6: Some(ENTRYNODES_PREFER_IPV6_DEFAULT),
run_as_entry_node: Some(RUN_AS_ENTRYNODE_DEFAULT),
drop_neighbors_on_salt_update: Some(DROP_NEIGHBORS_ON_SALT_UPDATE_DEFAULT),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion bee-network/bee-autopeering/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) struct ManualDelayFactory(AtomicU64);

impl ManualDelayFactory {
/// Creates a new `ManualDelayFactory` from an initial delay.
pub(crate) const fn new(initial_delay: Duration) -> Self {
pub(crate) const fn new(initial_delay: Delay) -> Self {
Self(AtomicU64::new(delay_to_millis(initial_delay)))
}

Expand Down
Loading

0 comments on commit 5775e15

Please sign in to comment.