Skip to content

Commit

Permalink
fix: better logging for iroh-dns-server (n0-computer#2195)
Browse files Browse the repository at this point in the history
## Description

Logs the database file path on start, and adds context to some errors if
things fail.

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [ ] Self-review.
- [ ] Documentation updates if relevant.
- [ ] Tests if relevant.
  • Loading branch information
Frando authored and ppodolsky committed Apr 20, 2024
1 parent d0ff3c3 commit 90dbe61
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
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

0 comments on commit 90dbe61

Please sign in to comment.