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

fix: better logging for iroh-dns-server #2195

Merged
merged 1 commit into from
Apr 16, 2024
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
10 changes: 8 additions & 2 deletions iroh-dns-server/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Configuration for the server

use anyhow::{anyhow, Context, Result};
use serde::{Deserialize, Serialize};
use std::{
env,
net::{IpAddr, Ipv4Addr, SocketAddr},
path::{Path, PathBuf},
};

use anyhow::{anyhow, Context, Result};
use serde::{Deserialize, Serialize};
use tracing::info;

use crate::{
dns::DnsConfig,
http::{CertMode, HttpConfig, HttpsConfig},
Expand Down Expand Up @@ -62,6 +64,10 @@ impl MetricsConfig {
impl Config {
/// Load the config from a file.
pub async fn load(path: impl AsRef<Path>) -> Result<Config> {
info!(
"loading config file from {}",
path.as_ref().to_string_lossy()
);
let s = tokio::fs::read_to_string(path.as_ref())
.await
.with_context(|| format!("failed to read {}", path.as_ref().to_string_lossy()))?;
Expand Down
19 changes: 15 additions & 4 deletions iroh-dns-server/src/store/signed_packets.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::path::Path;

use anyhow::Result;
use anyhow::{Context, Result};
use iroh_metrics::inc;
use pkarr::SignedPacket;
use redb::{backends::InMemoryBackend, Database, ReadableTable, TableDefinition};
use tracing::info;

use crate::{metrics::Metrics, util::PublicKeyBytes};

Expand All @@ -18,14 +19,24 @@ pub struct SignedPacketStore {

impl SignedPacketStore {
pub fn persistent(path: impl AsRef<Path>) -> Result<Self> {
if let Some(parent) = path.as_ref().parent() {
std::fs::create_dir_all(parent)?;
let path = path.as_ref();
info!("loading packet database from {}", path.to_string_lossy());
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent).with_context(|| {
format!(
"failed to create database directory at {}",
path.to_string_lossy()
)
})?;
}
let db = Database::builder().create(path)?;
let db = Database::builder()
.create(path)
.context("failed to open packet database")?;
Self::open(db)
}

pub fn in_memory() -> Result<Self> {
info!("using in-memory packet database");
let db = Database::builder().create_with_backend(InMemoryBackend::new())?;
Self::open(db)
}
Expand Down
Loading