Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: more renaming of the term peer id to node id #1789

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions iroh-gossip/examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ use url::Url;
/// This broadcasts signed messages over iroh-gossip and verifies signatures
/// on received messages.
///
/// By default a new peer id is created when starting the example. To reuse your identity,
/// By default a new node id is created when starting the example. To reuse your identity,
/// set the `--secret-key` flag with the secret key printed on a previous invocation.
///
/// By default, the DERP server run by n0 is used. To use a local DERP server, run
/// cargo run --bin derper --features derper -- --dev
/// in another terminal and then set the `-d http://localhost:3340` flag on this example.
#[derive(Parser, Debug)]
struct Args {
/// secret key to derive our peer id from.
/// secret key to derive our node id from.
#[clap(long)]
secret_key: Option<String>,
/// Set a custom DERP server. By default, the DERP server hosted by n0 will be used.
Expand Down Expand Up @@ -131,7 +131,7 @@ async fn main() -> anyhow::Result<()> {
})
.bind(args.bind_port)
.await?;
println!("> our peer id: {}", endpoint.peer_id());
println!("> our node id: {}", endpoint.node_id());

// wait for a first endpoint update so that we know about our endpoint addresses
notify.notified().await;
Expand All @@ -142,7 +142,7 @@ async fn main() -> anyhow::Result<()> {
// insert the gossip handle into the gossip cell to be used in the endpoint callbacks above
gossip_cell.set(gossip.clone()).unwrap();

// print a ticket that includes our own peer id and endpoint addresses
// print a ticket that includes our own node id and endpoint addresses
let ticket = {
let me = endpoint.my_addr().await?;
let peers = peers.iter().cloned().chain([me]).collect();
Expand Down Expand Up @@ -206,12 +206,12 @@ async fn subscribe_loop(gossip: Gossip, topic: TopicId) -> anyhow::Result<()> {
match message {
Message::AboutMe { name } => {
names.insert(from, name.clone());
println!("> {} is now known as {}", fmt_peer_id(&from), name);
println!("> {} is now known as {}", fmt_node_id(&from), name);
}
Message::Message { text } => {
let name = names
.get(&from)
.map_or_else(|| fmt_peer_id(&from), String::to_string);
.map_or_else(|| fmt_node_id(&from), String::to_string);
println!("{}: {}", name, text);
}
}
Expand Down Expand Up @@ -320,7 +320,7 @@ impl FromStr for Ticket {

// helpers

fn fmt_peer_id(input: &PublicKey) -> String {
fn fmt_node_id(input: &PublicKey) -> String {
base32::fmt_short(input.as_bytes())
}
fn parse_secret_key(secret: &str) -> anyhow::Result<SecretKey> {
Expand Down
18 changes: 10 additions & 8 deletions iroh-gossip/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use anyhow::{anyhow, Context};
use bytes::{Bytes, BytesMut};
use futures::{stream::Stream, FutureExt};
use genawaiter::sync::{Co, Gen};
use iroh_net::{key::PublicKey, magic_endpoint::get_peer_id, AddrInfo, MagicEndpoint, NodeAddr};
use iroh_net::{
key::PublicKey, magic_endpoint::get_remote_node_id, AddrInfo, MagicEndpoint, NodeAddr,
};
use rand::rngs::StdRng;
use rand_core::SeedableRng;
use std::{collections::HashMap, future::Future, sync::Arc, task::Poll, time::Instant};
Expand Down Expand Up @@ -80,7 +82,7 @@ impl Gossip {
config: proto::Config,
my_addr: &AddrInfo,
) -> Self {
let peer_id = endpoint.peer_id();
let peer_id = endpoint.node_id();
let dialer = Dialer::new(endpoint.clone());
let state = proto::State::new(
peer_id,
Expand All @@ -92,7 +94,7 @@ impl Gossip {
let (in_event_tx, in_event_rx) = mpsc::channel(IN_EVENT_CAP);
let (on_endpoints_tx, on_endpoints_rx) = mpsc::channel(ON_ENDPOINTS_CAP);

let me = endpoint.peer_id().fmt_short();
let me = endpoint.node_id().fmt_short();
let actor = Actor {
endpoint,
state,
Expand Down Expand Up @@ -228,7 +230,7 @@ impl Gossip {
///
/// Make sure to check the ALPN protocol yourself before passing the connection.
pub async fn handle_connection(&self, conn: quinn::Connection) -> anyhow::Result<()> {
let peer_id = get_peer_id(&conn)?;
let peer_id = get_remote_node_id(&conn)?;
self.send(ToActor::ConnIncoming(peer_id, ConnOrigin::Accept, conn))
.await?;
Ok(())
Expand Down Expand Up @@ -714,10 +716,10 @@ mod test {
let go1 = Gossip::from_endpoint(ep1.clone(), Default::default(), &addr1);
let go2 = Gossip::from_endpoint(ep2.clone(), Default::default(), &addr2);
let go3 = Gossip::from_endpoint(ep3.clone(), Default::default(), &addr3);
debug!("peer1 {:?}", ep1.peer_id());
debug!("peer2 {:?}", ep2.peer_id());
debug!("peer3 {:?}", ep3.peer_id());
let pi1 = ep1.peer_id();
debug!("peer1 {:?}", ep1.node_id());
debug!("peer2 {:?}", ep2.node_id());
debug!("peer3 {:?}", ep3.node_id());
let pi1 = ep1.node_id();

let cancel = CancellationToken::new();
let tasks = [
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn server_endpoint(rt: &tokio::runtime::Runtime, opt: &Opt) -> (NodeAddr, Ma
.unwrap();
let addr = ep.local_addr().unwrap();
let addr = SocketAddr::new("127.0.0.1".parse().unwrap(), addr.0.port());
let addr = NodeAddr::new(ep.peer_id()).with_direct_addresses([addr]);
let addr = NodeAddr::new(ep.node_id()).with_direct_addresses([addr]);
(addr, ep)
})
}
Expand Down
4 changes: 2 additions & 2 deletions iroh-net/examples/magic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ async fn main() -> anyhow::Result<()> {
.bind(args.bind_port)
.await?;

let me = endpoint.peer_id();
let me = endpoint.node_id();
let local_addr = endpoint.local_addr()?;
println!("magic socket listening on {local_addr:?}");
println!("our peer id: {me}");
println!("our node id: {me}");

match args.command {
Command::Listen => {
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/src/derp/client_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl ClientConnManager {
/// - receive a ping and write a pong back
/// - notify the server to send a packet to another peer on behalf of the client
/// - note whether the client is `preferred`, aka this client is the preferred way
/// to speak to the peer ID associated with that client.
/// to speak to the node ID associated with that client.
///
/// If the `ClientConnIo` `can_mesh` that means that the associated [`super::client::Client`] is connected to
/// a derp [`super::server::Server`] that is apart of the same mesh network as this [`super::server::Server`]. It can:
Expand Down
4 changes: 2 additions & 2 deletions iroh-net/src/derp/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct Metrics {
pub accepts: Counter,
/// Number of connections we have removed because of an error
pub disconnects: Counter,
// TODO: enable when we can have multiple connections for one peer id
// TODO: enable when we can have multiple connections for one node id
// pub duplicate_client_keys: Counter,
// pub duplicate_client_conns: Counter,
// TODO: only important stat that we cannot track right now
Expand Down Expand Up @@ -115,7 +115,7 @@ impl Default for Metrics {

accepts: Counter::new("Number of times this server has accepted a connection."),
disconnects: Counter::new("Number of clients that have then disconnected."),
// TODO: enable when we can have multiple connections for one peer id
// TODO: enable when we can have multiple connections for one node id
// pub duplicate_client_keys: Counter::new("Number of dupliate client keys."),
// pub duplicate_client_conns: Counter::new("Number of duplicate client connections."),
// TODO: only important stat that we cannot track right now
Expand Down
24 changes: 12 additions & 12 deletions iroh-net/src/magic_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ impl MagicEndpoint {
self.endpoint.accept()
}

/// Get the peer id of this endpoint.
pub fn peer_id(&self) -> PublicKey {
/// Get the node id of this endpoint.
pub fn node_id(&self) -> PublicKey {
self.secret_key.public()
}

Expand Down Expand Up @@ -392,14 +392,14 @@ impl MagicEndpoint {
let addrs = self.local_endpoints().await?;
let derp = self.my_derp();
let addrs = addrs.into_iter().map(|x| x.addr).collect();
Ok(NodeAddr::from_parts(self.peer_id(), derp, addrs))
Ok(NodeAddr::from_parts(self.node_id(), derp, addrs))
}

/// Get the [`NodeAddr`] for this endpoint, while providing the endpoints.
pub fn my_addr_with_endpoints(&self, eps: Vec<config::Endpoint>) -> Result<NodeAddr> {
let derp = self.my_derp();
let addrs = eps.into_iter().map(|x| x.addr).collect();
Ok(NodeAddr::from_parts(self.peer_id(), derp, addrs))
Ok(NodeAddr::from_parts(self.node_id(), derp, addrs))
}

/// Get information on all the nodes we have connection information about.
Expand Down Expand Up @@ -573,7 +573,7 @@ pub async fn accept_conn(
) -> Result<(PublicKey, String, quinn::Connection)> {
let alpn = get_alpn(&mut conn).await?;
let conn = conn.await?;
let peer_id = get_peer_id(&conn)?;
let peer_id = get_remote_node_id(&conn)?;
Ok((peer_id, alpn, conn))
}

Expand All @@ -590,7 +590,7 @@ pub async fn get_alpn(connecting: &mut quinn::Connecting) -> Result<String> {
}

/// Extract the [`PublicKey`] from the peer's TLS certificate.
pub fn get_peer_id(connection: &quinn::Connection) -> Result<PublicKey> {
pub fn get_remote_node_id(connection: &quinn::Connection) -> Result<PublicKey> {
let data = connection.peer_identity();
match data {
None => anyhow::bail!("no peer certificate found"),
Expand Down Expand Up @@ -788,7 +788,7 @@ mod tests {
.await
.unwrap();
let eps = ep.local_addr().unwrap();
info!(me = %ep.peer_id().fmt_short(), ipv4=%eps.0, ipv6=?eps.1, "server bound");
info!(me = %ep.node_id().fmt_short(), ipv4=%eps.0, ipv6=?eps.1, "server bound");
for i in 0..n_iters {
let now = Instant::now();
println!("[server] round {}", i + 1);
Expand Down Expand Up @@ -829,7 +829,7 @@ mod tests {
.await
.unwrap();
let eps = ep.local_addr().unwrap();
info!(me = %ep.peer_id().fmt_short(), ipv4=%eps.0, ipv6=?eps.1, t = ?start.elapsed(), "client bound");
info!(me = %ep.node_id().fmt_short(), ipv4=%eps.0, ipv6=?eps.1, t = ?start.elapsed(), "client bound");
let node_addr = NodeAddr::new(server_node_id).with_derp_region(region_id);
info!(to = ?node_addr, "client connecting");
let t = Instant::now();
Expand Down Expand Up @@ -866,10 +866,10 @@ mod tests {
// setup_logging();
// let (ep1, ep2, cleanup) = setup_pair().await.unwrap();

// let peer_id_1 = ep1.peer_id();
// eprintln!("peer id 1 {peer_id_1}");
// let peer_id_2 = ep2.peer_id();
// eprintln!("peer id 2 {peer_id_2}");
// let peer_id_1 = ep1.node_id();
// eprintln!("node id 1 {peer_id_1}");
// let peer_id_2 = ep2.node_id();
// eprintln!("node id 2 {peer_id_2}");

// let endpoint = ep2.clone();
// let p2_connect = tokio::spawn(async move {
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/src/magicsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2860,7 +2860,7 @@ pub(crate) mod tests {

let a_addr = b.endpoint.magic_sock().get_mapping_addr(&a.public()).await.unwrap();
let b_addr = a.endpoint.magic_sock().get_mapping_addr(&b.public()).await.unwrap();
let b_node_id = b.endpoint.peer_id();
let b_node_id = b.endpoint.node_id();

println!("{}: {}, {}: {}", a_name, a_addr, b_name, b_addr);

Expand Down
4 changes: 2 additions & 2 deletions iroh-sync/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
time::{Duration, Instant},
};

use iroh_net::{key::PublicKey, magic_endpoint::get_peer_id, MagicEndpoint, NodeAddr};
use iroh_net::{key::PublicKey, magic_endpoint::get_remote_node_id, MagicEndpoint, NodeAddr};
use serde::{Deserialize, Serialize};
use tracing::{debug, error_span, trace, Instrument};

Expand Down Expand Up @@ -115,7 +115,7 @@ where
{
let t_start = Instant::now();
let connection = connecting.await.map_err(AcceptError::connect)?;
let peer = get_peer_id(&connection).map_err(AcceptError::connect)?;
let peer = get_remote_node_id(&connection).map_err(AcceptError::connect)?;
let (mut send_stream, mut recv_stream) = connection
.accept_bi()
.await
Expand Down
2 changes: 1 addition & 1 deletion iroh-sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub enum Event {
pub enum InsertOrigin {
/// The entry was inserted locally.
Local,
/// The entry was received from the remote peer identified by [`PeerIdBytes`].
/// The entry was received from the remote node identified by [`PeerIdBytes`].
Sync {
/// The peer from which we received this entry.
from: PeerIdBytes,
Expand Down
2 changes: 1 addition & 1 deletion iroh/examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This example shows the shortest path to working with documents in iroh. This example creates a
//! document and sets an entry with key: "hello", value: "world". The document is completely local.
//!
//! The iroh node that creates the document is backed by an in-memory database and a random peer ID
//! The iroh node that creates the document is backed by an in-memory database and a random node ID
//!
//! run this example from the project root:
//! $ cargo run --example client
Expand Down
2 changes: 1 addition & 1 deletion iroh/examples/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Since this is using the default iroh collection format, it can be downloaded
//! recursively using the iroh CLI.
//!
//! This is using an in memory database and a random peer id.
//! This is using an in memory database and a random node id.
//! run this example from the project root:
//! $ cargo run -p collection
use iroh::bytes::util::runtime;
Expand Down
2 changes: 1 addition & 1 deletion iroh/examples/hello-world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This can be downloaded using the iroh CLI.
//!
//! This is using an in memory database and a random peer id.
//! This is using an in memory database and a random node id.
//! run this example from the project root:
//! $ cargo run --example hello-world
use iroh::bytes::util::runtime;
Expand Down
2 changes: 1 addition & 1 deletion iroh/examples/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn run(db: impl Store) -> anyhow::Result<()> {
.spawn()
.await?;
// print some info about the node
let peer = node.peer_id();
let peer = node.node_id();
let addrs = node.local_endpoint_addresses().await?;
println!("node PeerID: {peer}");
println!("node listening addresses:");
Expand Down
7 changes: 4 additions & 3 deletions iroh/src/commands/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub enum Commands {
},
/// Connect to an iroh doctor accept node.
Connect {
/// hex peer id of the node to connect to
/// hex node id of the node to connect to
dial: PublicKey,

/// One or more remote endpoints to use when dialing
Expand Down Expand Up @@ -535,7 +535,7 @@ async fn passive_side(
endpoint: MagicEndpoint,
connection: quinn::Connection,
) -> anyhow::Result<()> {
let remote_peer_id = magic_endpoint::get_peer_id(&connection)?;
let remote_peer_id = magic_endpoint::get_remote_node_id(&connection)?;
let gui = Gui::new(endpoint, remote_peer_id);
loop {
match connection.accept_bi().await {
Expand Down Expand Up @@ -679,7 +679,8 @@ async fn accept(
match connecting.await {
Ok(connection) => {
if n == 0 {
let Ok(remote_peer_id) = magic_endpoint::get_peer_id(&connection) else {
let Ok(remote_peer_id) = magic_endpoint::get_remote_node_id(&connection)
else {
return;
};
println!("Accepted connection from {}", remote_peer_id);
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/commands/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async fn spawn_daemon_node<B: iroh_bytes::store::Store, D: iroh_sync::store::Sto
"DERP Region: {}",
region.map_or("None".to_string(), |r| r.to_string())
);
println!("PeerID: {}", provider.peer_id());
println!("PeerID: {}", provider.node_id());
println!();
Ok(provider)
}
Expand Down
2 changes: 1 addition & 1 deletion iroh/src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl Downloader {
where
S: Store,
{
let me = endpoint.peer_id().fmt_short();
let me = endpoint.node_id().fmt_short();
let (msg_tx, msg_rx) = mpsc::channel(SERVICE_CHANNEL_CAPACITY);
let dialer = iroh_gossip::net::util::Dialer::new(endpoint);

Expand Down
6 changes: 3 additions & 3 deletions iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ where
let handler = RpcHandler {
inner: inner.clone(),
};
let me = endpoint.peer_id().fmt_short();
let me = endpoint.node_id().fmt_short();
rt2.main().spawn(
async move {
Self::run(
Expand Down Expand Up @@ -448,7 +448,7 @@ where
// is only initialized once the endpoint is fully bound
if let Ok(local_endpoints) = server.local_endpoints().await {
if !local_endpoints.is_empty() {
debug!(me = ?server.peer_id(), "gossip initial update: {local_endpoints:?}");
debug!(me = ?server.node_id(), "gossip initial update: {local_endpoints:?}");
gossip.update_endpoints(&local_endpoints).ok();
}
}
Expand Down Expand Up @@ -719,7 +719,7 @@ impl<D: ReadableStore> Node<D> {
}

/// Returns the [`PublicKey`] of the node.
pub fn peer_id(&self) -> PublicKey {
pub fn node_id(&self) -> PublicKey {
self.inner.secret_key.public()
}

Expand Down
2 changes: 1 addition & 1 deletion iroh/src/rpc_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl RpcMsg<ProviderService> for NodeStatusRequest {
/// The response to a version request
#[derive(Serialize, Deserialize, Debug)]
pub struct NodeStatusResponse {
/// The peer id and socket addresses of this node.
/// The node id and socket addresses of this node.
pub addr: NodeAddr,
/// The bound listening addresses of the node
pub listen_addrs: Vec<SocketAddr>,
Expand Down
Loading