Skip to content

Commit

Permalink
chore: remove unused node code
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Jul 23, 2024
1 parent d5d3be9 commit cd5f8d4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 43 deletions.
5 changes: 1 addition & 4 deletions sn_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod replication;
pub use self::{
event::{NodeEvent, NodeEventsChannel, NodeEventsReceiver},
log_markers::Marker,
node::{NodeBuilder, NodeCmd, PERIODIC_REPLICATION_INTERVAL_MAX_S},
node::{NodeBuilder, PERIODIC_REPLICATION_INTERVAL_MAX_S},
};

use crate::error::{Error, Result};
Expand All @@ -53,16 +53,13 @@ use std::{
collections::{BTreeMap, HashSet},
path::PathBuf,
};
use tokio::sync::broadcast;

/// Once a node is started and running, the user obtains
/// a `NodeRunning` object which can be used to interact with it.
#[derive(Clone)]
pub struct RunningNode {
network: Network,
node_events_channel: NodeEventsChannel,
#[allow(dead_code)]
node_cmds: broadcast::Sender<NodeCmd>,
}

impl RunningNode {
Expand Down
17 changes: 2 additions & 15 deletions sn_node/src/log_markers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
// KIND, either express or implied. Please review the Licences for the specific language governing
// permissions and limitations relating to use of the SAFE Network Software.

use libp2p::{kad::RecordKey, PeerId};
use sn_protocol::{messages::Cmd, PrettyPrintRecordKey};
use std::time::Duration;
// this gets us to_string easily enough
use crate::Error;
use libp2p::{kad::RecordKey, PeerId};
use sn_protocol::PrettyPrintRecordKey;
use strum::Display;

/// Public Markers for generating log output,
Expand All @@ -21,15 +19,6 @@ pub enum Marker<'a> {
/// The node has started
NodeConnectedToNetwork,

/// No network activity in some time
NoNetworkActivity(Duration),

/// Forced Replication by simulating a churned out node within close range.
ForcedReplication,

/// Network Cmd message received
NodeCmdReceived(&'a Cmd),

/// Peer was added to the routing table
PeerAddedToRoutingTable(PeerId),

Expand All @@ -39,8 +28,6 @@ pub enum Marker<'a> {
/// The number of peers in the routing table
PeersInRoutingTable(usize),

/// Replication trigger was fired
ReplicationTriggered,
/// Interval based replication
IntervalReplicationTriggered,

Expand Down
2 changes: 1 addition & 1 deletion sn_node/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl NodeMetrics {
let _ = self.put_record_err.inc();
}

Marker::ReplicationTriggered => {
Marker::IntervalReplicationTriggered => {
let _ = self.replication_triggered.inc();
}

Expand Down
24 changes: 1 addition & 23 deletions sn_node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use std::{
time::Duration,
};
use tokio::{
sync::{broadcast, mpsc::Receiver},
sync::mpsc::Receiver,
task::{spawn, JoinHandle},
};

Expand Down Expand Up @@ -171,12 +171,10 @@ impl NodeBuilder {

let (network, network_event_receiver, swarm_driver) = network_builder.build_node()?;
let node_events_channel = NodeEventsChannel::default();
let (node_cmds, _) = broadcast::channel(10);

let node = NodeInner {
network: network.clone(),
events_channel: node_events_channel.clone(),
node_cmds: node_cmds.clone(),
initial_peers: self.initial_peers,
reward_address,
#[cfg(feature = "open-metrics")]
Expand All @@ -189,7 +187,6 @@ impl NodeBuilder {
let running_node = RunningNode {
network,
node_events_channel,
node_cmds,
};

// Run the node
Expand All @@ -199,10 +196,6 @@ impl NodeBuilder {
}
}

/// Commands that can be sent by the user to the Node instance, e.g. to mutate some settings.
#[derive(Clone, Debug)]
pub enum NodeCmd {}

/// `Node` represents a single node in the distributed network. It handles
/// network events, processes incoming requests, interacts with the data
/// storage, and broadcasts node-related events.
Expand All @@ -218,7 +211,6 @@ struct NodeInner {
// Peers that are dialed at startup of node.
initial_peers: Vec<Multiaddr>,
network: Network,
node_cmds: broadcast::Sender<NodeCmd>,
#[cfg(feature = "open-metrics")]
node_metrics: Option<NodeMetrics>,
/// Node owner's discord username, in readable format
Expand All @@ -243,11 +235,6 @@ impl Node {
&self.inner.network
}

/// Returns the NodeCmds channel
pub(crate) fn node_cmds(&self) -> &broadcast::Sender<NodeCmd> {
&self.inner.node_cmds
}

#[cfg(feature = "open-metrics")]
/// Returns a reference to the NodeMetrics if the `open-metrics` feature flag is enabled
pub(crate) fn node_metrics(&self) -> Option<&NodeMetrics> {
Expand All @@ -269,7 +256,6 @@ impl Node {
let mut rng = StdRng::from_entropy();

let peers_connected = Arc::new(AtomicUsize::new(0));
let mut cmds_receiver = self.node_cmds().subscribe();

// read the forwarded balance from the file and set the metric.
// This is done initially because reward forwarding takes a while to kick in
Expand Down Expand Up @@ -410,14 +396,6 @@ impl Node {
let _ = node_metrics.uptime.set(node_metrics.started_instant.elapsed().as_secs() as i64);
}
}
node_cmd = cmds_receiver.recv() => {
match node_cmd {
Ok(cmd) => {
info!("{cmd:?} received... unhandled")
}
Err(err) => error!("When trying to read from the NodeCmds channel/receiver: {err:?}")
}
}
}
}
});
Expand Down

0 comments on commit cd5f8d4

Please sign in to comment.