Skip to content

Commit

Permalink
feat(network): log capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
nerodono committed Jan 21, 2025
1 parent 06eaddf commit 82d248a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
14 changes: 8 additions & 6 deletions elfo-network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ pub struct CompressionAlgorithms {
pub lz4: Algorithm,
}

impl CompressionAlgorithms {
const fn lz4_default() -> Algorithm {
Algorithm {
preference: Preference::Supported,
}
}
}

impl Default for CompressionAlgorithms {
fn default() -> Self {
Self {
Expand All @@ -96,12 +104,6 @@ impl Default for CompressionAlgorithms {
}
}

impl CompressionAlgorithms {
const fn lz4_default() -> Algorithm {
Algorithm { preference: Preference::Supported }
}
}

/// Compression settings.
#[derive(Debug, Default, Deserialize, Clone)]
pub struct CompressionConfig {
Expand Down
8 changes: 7 additions & 1 deletion elfo-network/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl Discovery {
info!(
message = "listening for connections",
addr = %transport,
capabilities = %capabilities,
);

self.ctx.attach(Stream::from_futures03(stream));
Expand Down Expand Up @@ -252,7 +253,12 @@ impl Discovery {

self.ctx.attach(Stream::once(async move {
loop {
debug!(message = "connecting to peer", addr = %transport, role = ?role);
debug!(
message = "connecting to peer",
addr = %transport,
role = ?role,
capabilities = %capabilities,
);

match socket::connect(&transport, node_no, launch_id, capabilities).await {
Ok(socket) => {
Expand Down
32 changes: 32 additions & 0 deletions elfo-network/src/socket/capabilities/compression.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Layouts are specified from highest to lowest bits.

use std::fmt;

use crate::config::Preference;

/// Layout:
Expand All @@ -26,6 +28,36 @@ use crate::config::Preference;
#[derive(Debug, Clone, Copy)]
pub(crate) struct Compression(u32);

fn write_array(algos: Algorithms, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[")?;
let mut need_comma = false;
for (name, _) in algos.iter_names() {
if need_comma {
need_comma = false;
write!(f, ", ")?;
} else {
need_comma = true;
}

f.write_str(name)?;
}

write!(f, "]")
}

impl fmt::Display for Compression {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let preferred = self.preferred();
let supported = self.supported();

write!(f, "(preferred: ")?;
write_array(preferred, f)?;
write!(f, ", supported: ")?;
write_array(supported, f)?;
write!(f, ")")
}
}

impl Compression {
pub(crate) const fn empty() -> Self {
Self::new(Algorithms::empty(), Algorithms::empty())
Expand Down
8 changes: 8 additions & 0 deletions elfo-network/src/socket/capabilities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
use std::fmt;

use self::compression::Compression;

pub(crate) mod compression;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct Capabilities(u32);

impl fmt::Display for Capabilities {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "(compression: {})", self.compression())
}
}

impl Capabilities {
pub(crate) const fn new(compression: Compression) -> Self {
let compression = compression.bits() as u32;
Expand Down

0 comments on commit 82d248a

Please sign in to comment.