Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
refactor!: rename Instance to Routing
Browse files Browse the repository at this point in the history
  • Loading branch information
madadam committed Oct 15, 2020
1 parent ee5f50b commit a85145e
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use hex_fmt::HexFmt;
use log::{info, LevelFilter};
use sn_routing::{
event::{Connected, Event},
Config, EventStream, Instance, TransportConfig,
Config, EventStream, Routing, TransportConfig,
};
use std::{
collections::HashSet,
Expand Down Expand Up @@ -195,7 +195,7 @@ async fn start_node(
transport_config,
..Default::default()
};
let (node, event_stream) = Instance::new(config)
let (node, event_stream) = Routing::new(config)
.await
.expect("Failed to instantiate a Node");

Expand All @@ -209,7 +209,7 @@ async fn start_node(
}

// Runs the nodes event loop. Blocks until terminated.
async fn run_node(index: usize, mut node: Instance, mut event_stream: EventStream) {
async fn run_node(index: usize, mut node: Routing, mut event_stream: EventStream) {
tokio::spawn(async move {
while let Some(event) = event_stream.next().await {
if !handle_event(index, &mut node, event).await {
Expand All @@ -220,7 +220,7 @@ async fn run_node(index: usize, mut node: Instance, mut event_stream: EventStrea
}

// Handles the event emitted by the node.
async fn handle_event(index: usize, node: &mut Instance, event: Event) -> bool {
async fn handle_event(index: usize, node: &mut Routing, event: Event) -> bool {
match event {
Event::Connected(Connected::First) => {
let contact_info = node
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ extern crate serde;
// ############################################################################
pub use self::{
error::{Error, Result},
instance::{Config, EventStream, Instance},
location::{DstLocation, SrcLocation},
network_params::NetworkParams,
routing::{Config, EventStream, Routing},
section::{SectionProofChain, MIN_AGE},
};
pub use qp2p::Config as TransportConfig;
Expand All @@ -96,7 +96,6 @@ mod cancellation;
mod consensus;
mod delivery_group;
mod error;
mod instance;
mod location;
mod message_filter;
mod messages;
Expand All @@ -105,6 +104,7 @@ mod network_params;
mod node;
mod peer;
mod relocation;
mod routing;
mod section;

// Cryptography
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/instance/mod.rs → src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use std::{net::SocketAddr, sync::Arc};
use tokio::sync::mpsc;
use xor_name::{Prefix, XorName};

/// Instance configuration.
/// Routing configuration.
pub struct Config {
/// If true, configures the node to start a new network instead of joining an existing one.
pub first: bool,
Expand Down Expand Up @@ -70,12 +70,12 @@ impl Default for Config {
/// location. Its methods can be used to send requests and responses as either an individual
/// `Node` or as a part of a section or group location. Their `src` argument indicates that
/// role, and can be any [`SrcLocation`](enum.SrcLocation.html).
pub struct Instance {
pub struct Routing {
stage: Arc<Stage>,
_executor: Executor,
}

impl Instance {
impl Routing {
////////////////////////////////////////////////////////////////////////////
// Public API
////////////////////////////////////////////////////////////////////////////
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions tests/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use futures::future::join_all;
use sn_routing::{
event::{Connected, Event},
rng::MainRng,
Instance,
Routing,
};
use utils::*;
use xor_name::XorName;
Expand All @@ -23,7 +23,7 @@ use xor_name::XorName;
async fn test_genesis_node() -> Result<()> {
let keypair = Keypair::generate(&mut MainRng::default());
let pub_key = keypair.public;
let (node, mut event_stream) = InstanceBuilder::new(None)
let (node, mut event_stream) = RoutingBuilder::new(None)
.first()
.keypair(keypair)
.create()
Expand All @@ -41,7 +41,7 @@ async fn test_genesis_node() -> Result<()> {

#[tokio::test]
async fn test_node_bootstrapping() -> Result<()> {
let (genesis_node, mut event_stream) = InstanceBuilder::new(None).first().create().await?;
let (genesis_node, mut event_stream) = RoutingBuilder::new(None).first().create().await?;

// spawn genesis node events listener
let genesis_handler = tokio::spawn(async move {
Expand All @@ -55,7 +55,7 @@ async fn test_node_bootstrapping() -> Result<()> {

// bootstrap a second node with genesis
let genesis_contact = genesis_node.our_connection_info()?;
let (node1, mut event_stream) = InstanceBuilder::new(None)
let (node1, mut event_stream) = RoutingBuilder::new(None)
.with_contact(genesis_contact)
.create()
.await?;
Expand All @@ -75,7 +75,7 @@ async fn test_node_bootstrapping() -> Result<()> {
#[tokio::test]
async fn test_section_bootstrapping() -> Result<()> {
let num_of_nodes = 7;
let (genesis_node, mut event_stream) = InstanceBuilder::new(None)
let (genesis_node, mut event_stream) = RoutingBuilder::new(None)
.elder_size(num_of_nodes)
.first()
.create()
Expand Down Expand Up @@ -107,14 +107,14 @@ async fn test_section_bootstrapping() -> Result<()> {
let mut nodes_joining_tasks = Vec::with_capacity(num_of_nodes);
for _ in 0..num_of_nodes {
nodes_joining_tasks.push(async {
let (node, mut event_stream) = InstanceBuilder::new(None)
let (node, mut event_stream) = RoutingBuilder::new(None)
.with_contact(genesis_contact)
.create()
.await?;

assert_next_event!(event_stream, Event::Connected(Connected::First));

Ok::<Instance, Error>(node)
Ok::<Routing, Error>(node)
});
}

Expand Down
6 changes: 3 additions & 3 deletions tests/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async fn test_messages_client_node() -> Result<()> {
let msg = b"hello!";
let response = b"good bye!";

let (node, mut event_stream) = InstanceBuilder::new(None).first().create().await?;
let (node, mut event_stream) = RoutingBuilder::new(None).first().create().await?;

// spawn node events listener
let node_handler = tokio::spawn(async move {
Expand Down Expand Up @@ -65,7 +65,7 @@ async fn test_messages_between_nodes() -> Result<()> {
let msg = b"hello!";
let response = b"good bye!";

let (node1, mut event_stream) = InstanceBuilder::new(None).first().create().await?;
let (node1, mut event_stream) = RoutingBuilder::new(None).first().create().await?;
let node1_contact = node1.our_connection_info()?;
let node1_name = node1.name().await;

Expand All @@ -84,7 +84,7 @@ async fn test_messages_between_nodes() -> Result<()> {
});

// start a second node which sends a message to the first node
let (node2, mut event_stream) = InstanceBuilder::new(None)
let (node2, mut event_stream) = RoutingBuilder::new(None)
.with_contact(node1_contact)
.create()
.await?;
Expand Down
18 changes: 9 additions & 9 deletions tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use futures::future;
use itertools::Itertools;
use sn_routing::{
event::{Connected, Event},
log_ident, Config, EventStream, Instance, NetworkParams, TransportConfig, MIN_AGE,
log_ident, Config, EventStream, NetworkParams, Routing, TransportConfig, MIN_AGE,
};
use std::{
collections::{BTreeSet, HashSet},
Expand All @@ -29,11 +29,11 @@ use std::{

static LOG_INIT: Once = Once::new();

pub struct InstanceBuilder {
pub struct RoutingBuilder {
config: Config,
}

impl<'a> InstanceBuilder {
impl<'a> RoutingBuilder {
pub fn new(config: Option<Config>) -> Self {
// We initialise the logger but only once for all tests
LOG_INIT.call_once(|| {
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'a> InstanceBuilder {
self
}

pub async fn create(self) -> Result<(Instance, EventStream)> {
pub async fn create(self) -> Result<(Routing, EventStream)> {
// make sure we set 127.0.0.1 as the IP if was not set
let config = if self.config.transport_config.ip.is_none() {
let mut config = self.config;
Expand All @@ -97,7 +97,7 @@ impl<'a> InstanceBuilder {
self.config
};

Ok(Instance::new(config).await?)
Ok(Routing::new(config).await?)
}
}

Expand All @@ -122,11 +122,11 @@ macro_rules! assert_next_event {
pub async fn create_connected_nodes(
count: usize,
network_params: NetworkParams,
) -> Result<Vec<(Instance, EventStream)>> {
) -> Result<Vec<(Routing, EventStream)>> {
let mut nodes = vec![];

// Create the first node
let (node, mut event_stream) = InstanceBuilder::new(None)
let (node, mut event_stream) = RoutingBuilder::new(None)
.first()
.network_params(network_params)
.create()
Expand All @@ -140,7 +140,7 @@ pub async fn create_connected_nodes(

// Create the other nodes bootstrapping off the first node.
let other_nodes = (1..count).map(|_| async {
let (node, mut event_stream) = InstanceBuilder::new(None)
let (node, mut event_stream) = RoutingBuilder::new(None)
.network_params(network_params)
.with_contact(bootstrap_contact)
.create()
Expand Down Expand Up @@ -181,7 +181,7 @@ pub async fn create_connected_nodes(
Ok(nodes)
}

pub async fn verify_invariants_for_node(node: &Instance, elder_size: usize) -> Result<()> {
pub async fn verify_invariants_for_node(node: &Routing, elder_size: usize) -> Result<()> {
let our_name = node.name().await;
assert!(node.matches_our_prefix(&our_name).await?);

Expand Down

0 comments on commit a85145e

Please sign in to comment.