Skip to content

Commit

Permalink
More module docs & move relay metrics to server::metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Jul 31, 2024
1 parent 98098cf commit f19fcc7
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 17 deletions.
3 changes: 2 additions & 1 deletion iroh-net/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
pub use crate::magicsock::Metrics as MagicsockMetrics;
pub use crate::netcheck::Metrics as NetcheckMetrics;
pub use crate::portmapper::Metrics as PortmapMetrics;
pub use crate::relay::Metrics as RelayMetrics;
#[cfg(feature = "iroh-relay")]
pub use crate::relay::server::Metrics as RelayMetrics;
6 changes: 0 additions & 6 deletions iroh-net/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub(crate) mod client;
pub(crate) mod codec;
pub mod http;
mod map;
mod metrics;
#[cfg(feature = "iroh-relay")]
pub mod server;

Expand All @@ -25,9 +24,4 @@ pub use self::client::{
};
pub use self::codec::MAX_PACKET_SIZE;
pub use self::map::{RelayMap, RelayMode, RelayNode};
pub use self::metrics::Metrics;
#[cfg(feature = "iroh-relay")]
pub use self::server::actor::{ClientConnHandler, ServerActorTask};
#[cfg(feature = "iroh-relay")]
pub use self::server::streams::MaybeTlsStream as MaybeTlsStreamServer;
pub use iroh_base::node_addr::RelayUrl;
3 changes: 3 additions & 0 deletions iroh-net/src/relay/client/conn.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//! Manages client-side connections to the relay server.
//!
//! based on tailscale/derp/derp_client.go
use std::net::SocketAddr;
use std::num::NonZeroU32;
use std::pin::Pin;
Expand Down
5 changes: 2 additions & 3 deletions iroh-net/src/relay/http.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! An http specific relay Client and relay Server. Allows for using tls or non tls connection
//! upgrades.
//!
//! HTTP-specific constants for the relay server and client.
pub(crate) const HTTP_UPGRADE_PROTOCOL: &str = "iroh derp http";
pub(crate) const WEBSOCKET_UPGRADE_PROTOCOL: &str = "websocket";
#[cfg(feature = "iroh-relay")] // only used in the server for now
Expand Down
11 changes: 8 additions & 3 deletions iroh-net/src/relay/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! A full-fledged iroh-relay server.
//! A fully-fledged iroh-relay server over HTTP or HTTPS.
//!
//! This module provides an API to run a full fledged iroh-relay server. It is primarily
//! used by the `iroh-relay` binary in this crate. It can be used to run a relay server in
Expand Down Expand Up @@ -31,15 +31,20 @@ use crate::stun;
use crate::util::AbortingJoinHandle;

// Module defined in this file.
use metrics::StunMetrics;
use stun_metrics::StunMetrics;

pub(crate) mod actor;
pub(crate) mod client_conn;
mod clients;
mod http_server;
mod metrics;
pub(crate) mod streams;
pub(crate) mod types;

pub use self::actor::{ClientConnHandler, ServerActorTask};
pub use self::metrics::Metrics;
pub use self::streams::MaybeTlsStream as MaybeTlsStreamServer;

const NO_CONTENT_CHALLENGE_HEADER: &str = "X-Tailscale-Challenge";
const NO_CONTENT_RESPONSE_HEADER: &str = "X-Tailscale-Response";
const NOTFOUND: &[u8] = b"Not Found";
Expand Down Expand Up @@ -646,7 +651,7 @@ impl hyper::service::Service<Request<Incoming>> for CaptivePortalService {
}
}

mod metrics {
mod stun_metrics {
use iroh_metrics::{
core::{Counter, Metric},
struct_iterable::Iterable,
Expand Down
5 changes: 4 additions & 1 deletion iroh-net/src/relay/server/actor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//! The main event loop for the relay server.
//!
//! based on tailscale/derp/derp_server.go
use std::collections::HashMap;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
Expand All @@ -25,9 +28,9 @@ use crate::relay::{
recv_client_key, DerpCodec, PER_CLIENT_SEND_QUEUE_DEPTH, PROTOCOL_VERSION,
SERVER_CHANNEL_SIZE,
},
metrics::Metrics,
server::client_conn::ClientConnBuilder,
server::clients::Clients,
server::metrics::Metrics,
};
use crate::util::AbortingJoinHandle;

Expand Down
4 changes: 3 additions & 1 deletion iroh-net/src/relay/server/client_conn.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! The server-side representation of an ongoing client relaying connection.
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
Expand All @@ -20,7 +22,7 @@ use crate::relay::server::streams::RelayIo;
use crate::relay::server::types::{Packet, ServerMessage};
use crate::relay::{
codec::{write_frame, KEEP_ALIVE},
metrics::Metrics,
server::metrics::Metrics,
};

/// The [`Server`] side representation of a [`Client`]'s connection.
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/src/relay/server/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use tracing::{Instrument, Span};
use crate::key::PublicKey;

use super::client_conn::{ClientConnBuilder, ClientConnManager};
use super::metrics::Metrics;
use super::types::Packet;
use crate::relay::metrics::Metrics;

/// Number of times we try to send to a client connection before dropping the data;
const RETRIES: usize = 3;
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion iroh-net/src/relay/server/streams.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Streams used in the server-side implementation of iroh relays.
use std::pin::Pin;
use std::task::{Context, Poll};

Expand Down Expand Up @@ -80,7 +82,9 @@ impl Stream for RelayIo {
}
}

/// Whether or not the underlying [`tokio::net::TcpStream`] is served over Tls
/// The main underlying IO stream type used for the relay server.
///
/// Allows choosing whether or not the underlying [`tokio::net::TcpStream`] is served over Tls
#[derive(Debug)]
pub enum MaybeTlsStream {
/// A plain non-Tls [`tokio::net::TcpStream`]
Expand Down
2 changes: 2 additions & 0 deletions iroh-net/src/relay/server/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Types that are shared between [`super::actor`] and [`super::client_conn`].
use bytes::Bytes;

use crate::key::PublicKey;
Expand Down

0 comments on commit f19fcc7

Please sign in to comment.