Skip to content

Commit

Permalink
Fix warnings, clippy, format
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Nov 5, 2021
1 parent 58b2f4d commit a818140
Show file tree
Hide file tree
Showing 28 changed files with 370 additions and 436 deletions.
15 changes: 7 additions & 8 deletions bee-autopeering/examples/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

use bee_autopeering::{
init,
peerstore::InMemoryPeerStore,
peerstore::{SledPeerStore, SledPeerStoreConfig},
peerstore::{InMemoryPeerStore, SledPeerStore, SledPeerStoreConfig},
AutopeeringConfig, Event, Local, NeighborValidator, Peer, ServiceProtocol, AUTOPEERING_SERVICE_NAME,
};

Expand Down Expand Up @@ -36,10 +35,10 @@ fn read_config() -> AutopeeringConfig {
// "bindAddress": "0.0.0.0:14627",
// "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"
// ],
// "/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
// }"#;
Expand All @@ -48,8 +47,8 @@ fn read_config() -> AutopeeringConfig {
// {
// "bindAddress": "0.0.0.0:14627",
// "entryNodes": [
// "/dns/entry-hornet-0.h.chrysalis-mainnet.iotaledger.net/udp/14626/autopeering/iotaPHdAn7eueBnXtikZMwhfPXaeGJGXDt4RBuLuGgb"
// ],
// "/dns/entry-hornet-0.h.chrysalis-mainnet.iotaledger.net/udp/14626/autopeering/
// iotaPHdAn7eueBnXtikZMwhfPXaeGJGXDt4RBuLuGgb" ],
// "entryNodesPreferIPv6": false,
// "runAsEntryNode": false
// }"#;
Expand Down
14 changes: 10 additions & 4 deletions bee-autopeering/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ use crate::peer::peer_id::PeerId;

use tokio::sync::mpsc;

// TODO: revisit dead code
#[allow(dead_code)]
#[derive(Debug)]
pub(crate) enum Command {
SendVerificationRequest { peer_id: PeerId },
SendDiscoveryRequest { peer_id: PeerId },
SendVerificationRequests,
SendDiscoveryRequests,
// Send a verfication request to that peer.
Verify { peer_id: PeerId },
// Send a discovery request to that peer.
Query { peer_id: PeerId },
// Send a peering request to that peer.
Peer { peer_id: PeerId },
// Send a drop-peering request to that peer.
Drop { peer_id: PeerId },
}

pub(crate) type CommandRx = mpsc::UnboundedReceiver<Command>;
Expand Down
3 changes: 1 addition & 2 deletions bee-autopeering/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ use serde::{Deserialize, Serialize};
use std::net::SocketAddr;

#[rustfmt::skip]
// # Example
// ```json
// "autopeering": {
// "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"
// ],
// "entryNodesPreferIPv6": false,
// "runAsEntryNode": false,
Expand Down
22 changes: 12 additions & 10 deletions bee-autopeering/src/delay.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crate::{task::ShutdownRx, time};

use rand::{thread_rng, Rng as _};

use std::{
future::Future,
sync::atomic::{AtomicU64, Ordering},
time::{Duration, Instant},
};

pub(crate) type Delay = Duration;

// TODO: revisit dead code
#[allow(dead_code)]
#[derive(Default)]
pub(crate) struct DelayFactoryBuilder {
max_count: Option<usize>,
Expand All @@ -21,6 +20,8 @@ pub(crate) struct DelayFactoryBuilder {
mode: DelayFactoryMode,
}

// TODO: revisit dead code
#[allow(dead_code)]
impl DelayFactoryBuilder {
pub fn new(mode: DelayFactoryMode) -> Self {
Self {
Expand Down Expand Up @@ -77,12 +78,11 @@ impl Iterator for DelayFactory {
type Item = Delay;

fn next(&mut self) -> Option<Self::Item> {
if self.curr_count >= self.max_count {
None
} else if Instant::now()
.checked_duration_since(self.timestamp)
.expect("error duration since")
> self.timeout
if self.curr_count >= self.max_count
|| Instant::now()
.checked_duration_since(self.timestamp)
.expect("error duration since")
> self.timeout
{
None
} else {
Expand All @@ -97,7 +97,7 @@ impl Iterator for DelayFactory {
};
self.curr_count += 1;

if self.jitter != 1.0 {
if (self.jitter - 1.0).abs() > f32::EPSILON {
next_interval_millis =
thread_rng().gen_range(((next_interval_millis as f32 * self.jitter) as u64)..next_interval_millis)
}
Expand All @@ -107,6 +107,8 @@ impl Iterator for DelayFactory {
}
}

// TODO: revisit dead code
#[allow(dead_code)]
/// The different "Modi operandi" for the [`DelayFactory`].
pub(crate) enum DelayFactoryMode {
/// The factory produces a series of 0-delays.
Expand Down
Loading

0 comments on commit a818140

Please sign in to comment.