Skip to content

Commit

Permalink
chore: fix transport order for wss possibility (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeeshan Lakhani authored Feb 8, 2024
1 parent 1838452 commit 803f983
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
1 change: 0 additions & 1 deletion .github/workflows/tests_and_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ jobs:

- name: Run Linter
run: cargo clippy --all -- -D warnings
continue-on-error: ${{ matrix.rust-toolchain == 'nightly' && matrix.os == 'macos-14' }}

- name: Install cargo-hakari
if: ${{ matrix.rust-toolchain == 'stable' }}
Expand Down
1 change: 1 addition & 0 deletions homestar-runtime/src/cli/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub trait ConsoleTable {
}

/// Style trait for console table output responses.
#[allow(dead_code)]
pub(crate) trait ApplyStyle {
fn default(&mut self) -> Output;
fn default_with_title(&mut self, ext_title: &str) -> Output;
Expand Down
1 change: 1 addition & 0 deletions homestar-runtime/src/db/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use chrono::NaiveDateTime;

/// Trait for converting nanoseconds to a timestamp.
#[allow(dead_code)]
pub(crate) trait Timestamp {
fn timestamp_from_nanos(&self) -> Option<NaiveDateTime>;
}
Expand Down
53 changes: 29 additions & 24 deletions homestar-runtime/src/network/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,14 +408,38 @@ fn build_transport(
keypair: Keypair,
) -> Result<transport::Boxed<(PeerId, StreamMuxerBox)>> {
let build_tcp = || libp2p::tcp::tokio::Transport::new(libp2p::tcp::Config::new().nodelay(true));
let build_ws_or_tcp = libp2p::websocket::WsConfig::new(build_tcp()).or_transport(build_tcp());
let build_quic = if settings.libp2p.quic.enable {
OptionalTransport::some(quic::tokio::Transport::new(quic::Config::new(&keypair)))
} else {
OptionalTransport::none()
};

let transport = build_ws_or_tcp
let dns_transport = || {
if let Ok((conf, opts)) = hickory_resolver::system_conf::read_system_conf() {
info!(
subject = "swarm.init",
category = "libp2p.swarm",
"using system DNS configuration from /etc/resolv.conf"
);
dns::tokio::Transport::custom(build_tcp(), conf, opts)
} else {
info!(
subject = "swarm.init",
category = "libp2p.swarm",
"using cloudflare DNS configuration as a fallback"
);
dns::tokio::Transport::custom(
build_tcp(),
dns::ResolverConfig::cloudflare(),
dns::ResolverOpts::default(),
)
}
};

// ws + wss transport or dns + tcp transport or ws + tcp
let transport = libp2p::websocket::WsConfig::new(dns_transport())
.or_transport(dns_transport())
.or_transport(libp2p::websocket::WsConfig::new(build_tcp()))
.upgrade(upgrade::Version::V1Lazy)
.authenticate(noise::Config::new(&keypair)?)
.multiplex(yamux::Config::default())
Expand All @@ -424,27 +448,8 @@ fn build_transport(
.map(|either_output, _| match either_output {
Either::Left((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)),
Either::Right((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)),
});

let transport = if let Ok((conf, opts)) = hickory_resolver::system_conf::read_system_conf() {
info!(
subject = "swarm.init",
category = "libp2p.swarm",
"using system DNS configuration from /etc/resolv.conf"
);
dns::tokio::Transport::custom(transport, conf, opts)
} else {
info!(
subject = "swarm.init",
category = "libp2p.swarm",
"using cloudflare DNS configuration as a fallback"
);
dns::tokio::Transport::custom(
transport,
dns::ResolverConfig::cloudflare(),
dns::ResolverOpts::default(),
)
};
})
.boxed();

Ok(transport.boxed())
Ok(transport)
}
2 changes: 2 additions & 0 deletions homestar-runtime/src/network/webserver/prom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use regex::Regex;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[allow(dead_code)]
const HISTOGRAM_TYPE: &str = "HISTOGRAM";
#[allow(dead_code)]
const SUMMARY_TYPE: &str = "SUMMARY";

static METRIC_REGEX_NO_LABEL: Lazy<&Regex> = Lazy::new(|| {
Expand Down
1 change: 1 addition & 0 deletions homestar-runtime/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub(crate) enum RegisteredTasks {
}

/// Trait for loading files for different task-types directly.
#[allow(dead_code)]
#[async_trait]
pub(crate) trait FileLoad {
/// Load file asynchronously.
Expand Down

0 comments on commit 803f983

Please sign in to comment.