Skip to content

Commit

Permalink
Fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Nov 18, 2022
1 parent 6687c44 commit ea67c04
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
16 changes: 8 additions & 8 deletions node/tcp/src/helpers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ use std::{
#[cfg(doc)]
use crate::protocols::{self, Handshake, Reading, Writing};

/// The node's configuration. See the source of [`Config::default`] for the defaults.
/// The Tcp's configuration. See the source of [`Config::default`] for the defaults.
#[derive(Debug, Clone)]
pub struct Config {
/// A user-friendly identifier of the node. It is visible in the logs, where it allows nodes to be
/// A user-friendly identifier of the Tcp. It is visible in the logs, where it allows Tcp instances to be
/// distinguished more easily if multiple are run at the same time.
///
/// note: If set to `None`, the node will automatically be assigned a sequential, zero-based numeric identifier.
/// note: If set to `None`, Tcp will automatically be assigned a sequential, zero-based numeric identifier.
pub name: Option<String>,
/// The IP address the node's connection listener should bind to.
/// The IP address the Tcp's connection listener should bind to.
///
/// note: If set to `None`, the node will not listen for inbound connections at all.
/// note: If set to `None`, the Tcp will not listen for inbound connections at all.
pub listener_ip: Option<IpAddr>,
/// The desired listening port of the node. If [`Config::allow_random_port`] is set to `true`, the node
/// The desired listening port of the Tcp. If [`Config::allow_random_port`] is set to `true`, the Tcp
/// will attempt to bind its listener to a different port if the desired one is not available.
///
/// note: [`Config::listener_ip`] must not be `None` in order for it to have any effect.
Expand All @@ -45,9 +45,9 @@ pub struct Config {
pub allow_random_port: bool,
/// The list of IO errors considered fatal and causing the connection to be dropped.
///
/// note: The node needs to implement the [`Reading`] and/or [`Writing`] protocol in order for it to have any effect.
/// note: Tcp needs to implement the [`Reading`] and/or [`Writing`] protocol in order for it to have any effect.
pub fatal_io_errors: Vec<io::ErrorKind>,
/// The maximum number of active connections the node can maintain at any given time.
/// The maximum number of active connections Tcp can maintain at any given time.
///
/// note: This number can very briefly be breached by 1 in case of inbound connection attempts. It can never be
/// breached by outbound connection attempts, though.
Expand Down
4 changes: 2 additions & 2 deletions node/tcp/src/helpers/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<T: AsyncWrite + Unpin + Send + Sync> AW for T {}
pub struct Connection {
/// The address of the connection.
addr: SocketAddr,
/// The connection's side in relation to the node.
/// The connection's side in relation to Tcp.
side: ConnectionSide,
/// Available and used only in the [`Handshake`] protocol.
pub(crate) stream: Option<TcpStream>,
Expand Down Expand Up @@ -107,7 +107,7 @@ impl Connection {
}

/// Returns `ConnectionSide::Initiator` if the associated peer initiated the connection
/// and `ConnectionSide::Responder` if the connection request was initiated by the node.
/// and `ConnectionSide::Responder` if the connection request was initiated by Tcp.
pub fn side(&self) -> ConnectionSide {
self.side
}
Expand Down
2 changes: 1 addition & 1 deletion node/tcp/src/helpers/known_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use parking_lot::RwLock;

use crate::Stats;

/// Contains statistics related to node's peers, currently connected or not.
/// Contains statistics related to Tcp's peers, currently connected or not.
#[derive(Default)]
pub struct KnownPeers(RwLock<HashMap<SocketAddr, Arc<Stats>>>);

Expand Down
2 changes: 1 addition & 1 deletion node/tcp/src/helpers/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use std::sync::atomic::{AtomicU64, Ordering::Relaxed};

/// Contains statistics related to a node.
/// Contains statistics related to Tcp.
#[derive(Default)]
pub struct Stats {
/// The number of all messages sent.
Expand Down
34 changes: 17 additions & 17 deletions node/tcp/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,32 +204,32 @@ impl Tcp {
Ok(node)
}

/// Returns the name assigned to the node.
/// Returns the name assigned to Tcp.
#[inline]
pub fn name(&self) -> &str {
// safe; can be set as None in Config, but receives a default value on Tcp creation
self.config.name.as_deref().unwrap()
}

/// Returns a reference to the node's config.
/// Returns a reference to the Tcp's config.
#[inline]
pub fn config(&self) -> &Config {
&self.config
}

/// Returns a reference to the node's stats.
/// Returns a reference to the Tcp's stats.
#[inline]
pub fn stats(&self) -> &Stats {
&self.stats
}

/// Returns the tracing [`Span`] associated with the node.
/// Returns the tracing [`Span`] associated with Tcp.
#[inline]
pub fn span(&self) -> &Span {
&self.span
}

/// Returns the node's listening address; returns an error if the node was configured
/// Returns the Tcp's listening address; returns an error if Tcp was configured
/// to not listen for inbound connections.
pub fn listening_addr(&self) -> io::Result<SocketAddr> {
self.listening_addr.ok_or_else(|| io::ErrorKind::AddrNotAvailable.into())
Expand Down Expand Up @@ -290,7 +290,7 @@ impl Tcp {
pub async fn connect(&self, addr: SocketAddr) -> io::Result<()> {
if let Ok(listening_addr) = self.listening_addr() {
if addr == listening_addr || addr.ip().is_loopback() && addr.port() == listening_addr.port() {
error!(parent: self.span(), "can't connect to node's own listening address ({})", addr);
error!(parent: self.span(), "can't connect to Tcp's own listening address ({})", addr);
return Err(io::ErrorKind::AddrInUse.into());
}
}
Expand Down Expand Up @@ -347,7 +347,7 @@ impl Tcp {
task.abort();
}

// if the (owning) node was not the initiator of the connection, it doesn't know the listening address
// if the (owning) Tcp was not the initiator of the connection, it doesn't know the listening address
// of the associated peer, so the related stats are unreliable; the next connection initiated by the
// peer could be bound to an entirely different port number
if conn.side() == ConnectionSide::Initiator {
Expand All @@ -367,7 +367,7 @@ impl Tcp {
self.connections.addrs()
}

/// Returns a reference to the collection of statistics of node's known peers.
/// Returns a reference to the collection of statistics of Tcp's known peers.
#[inline]
pub fn known_peers(&self) -> &KnownPeers {
&self.known_peers
Expand All @@ -378,7 +378,7 @@ impl Tcp {
self.connections.is_connected(addr)
}

/// Checks if the node is currently setting up a connection with the provided address.
/// Checks if Tcp is currently setting up a connection with the provided address.
pub fn is_connecting(&self, addr: SocketAddr) -> bool {
self.connecting.lock().contains(&addr)
}
Expand All @@ -405,7 +405,7 @@ impl Tcp {
}
}

/// Gracefully shuts the node down.
/// Gracefully shuts Tcp down.
pub async fn shut_down(&self) {
debug!(parent: self.span(), "shutting down");

Expand All @@ -425,23 +425,23 @@ impl Tcp {
}

// FIXME: this can probably be done more elegantly
/// Creates the node's tracing span based on its name.
fn create_span(node_name: &str) -> Span {
let mut span = trace_span!("node", name = node_name);
/// Creates the Tcp's tracing span based on its name.
fn create_span(tcp_name: &str) -> Span {
let mut span = trace_span!("tcp", name = tcp_name);
if !span.is_disabled() {
return span;
} else {
span = debug_span!("node", name = node_name);
span = debug_span!("tcp", name = tcp_name);
}
if !span.is_disabled() {
return span;
} else {
span = info_span!("node", name = node_name);
span = info_span!("tcp", name = tcp_name);
}
if !span.is_disabled() {
return span;
} else {
span = warn_span!("node", name = node_name);
span = warn_span!("tcp", name = tcp_name);
}
if !span.is_disabled() { span } else { error_span!("node", name = node_name) }
if !span.is_disabled() { span } else { error_span!("tcp", name = tcp_name) }
}

0 comments on commit ea67c04

Please sign in to comment.