Clean up debug impls

This commit is contained in:
Aode (Lion) 2021-09-21 14:32:25 -05:00
parent 4b4aaaa0b4
commit 3384ca9064
17 changed files with 182 additions and 31 deletions

2
Cargo.lock generated
View file

@ -1941,7 +1941,7 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]] [[package]]
name = "relay" name = "relay"
version = "0.3.3" version = "0.3.4"
dependencies = [ dependencies = [
"activitystreams", "activitystreams",
"activitystreams-ext", "activitystreams-ext",

View file

@ -1,7 +1,7 @@
[package] [package]
name = "relay" name = "relay"
description = "A simple activitypub relay" description = "A simple activitypub relay"
version = "0.3.3" version = "0.3.4"
authors = ["asonix <asonix@asonix.dog>"] authors = ["asonix <asonix@asonix.dog>"]
license-file = "LICENSE" license-file = "LICENSE"
readme = "README.md" readme = "README.md"

View file

@ -1,12 +1,12 @@
use activitystreams_ext::{Ext1, UnparsedExtension};
use activitystreams::{ use activitystreams::{
activity::ActorAndObject, activity::ActorAndObject,
actor::{Actor, ApActor}, actor::{Actor, ApActor},
unparsed::UnparsedMutExt, unparsed::UnparsedMutExt,
url::Url, url::Url,
}; };
use activitystreams_ext::{Ext1, UnparsedExtension};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct PublicKeyInner { pub struct PublicKeyInner {
pub id: Url, pub id: Url,
@ -14,6 +14,16 @@ pub struct PublicKeyInner {
pub public_key_pem: String, pub public_key_pem: String,
} }
impl std::fmt::Debug for PublicKeyInner {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PublicKeyInner")
.field("id", &self.id.to_string())
.field("owner", &self.owner.to_string())
.field("public_key_pem", &self.public_key_pem)
.finish()
}
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct PublicKey { pub struct PublicKey {

View file

@ -26,7 +26,7 @@ pub(crate) struct ParsedConfig {
opentelemetry_url: Option<Url>, opentelemetry_url: Option<Url>,
} }
#[derive(Clone, Debug)] #[derive(Clone)]
pub struct Config { pub struct Config {
hostname: String, hostname: String,
addr: IpAddr, addr: IpAddr,
@ -54,6 +54,27 @@ pub enum UrlKind {
Outbox, Outbox,
} }
impl std::fmt::Debug for Config {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Config")
.field("hostname", &self.hostname)
.field("addr", &self.addr)
.field("port", &self.port)
.field("debug", &self.debug)
.field("restricted_mode", &self.restricted_mode)
.field("validate_signatures", &self.validate_signatures)
.field("publish_blocks", &self.publish_blocks)
.field("base_uri", &self.base_uri.to_string())
.field("sled_path", &self.sled_path)
.field("source_repo", &self.source_repo.to_string())
.field(
"opentelemetry_url",
&self.opentelemetry_url.as_ref().map(|url| url.to_string()),
)
.finish()
}
}
impl Config { impl Config {
pub(crate) fn build() -> Result<Self, Error> { pub(crate) fn build() -> Result<Self, Error> {
let mut config = config::Config::new(); let mut config = config::Config::new();

View file

@ -40,7 +40,7 @@ impl ActorCache {
ActorCache { db } ActorCache { db }
} }
#[tracing::instrument(name = "Get Actor")] #[tracing::instrument(name = "Get Actor", fields(id = id.to_string().as_str(), requests))]
pub(crate) async fn get( pub(crate) async fn get(
&self, &self,
id: &Url, id: &Url,
@ -68,7 +68,7 @@ impl ActorCache {
self.db.remove_connection(actor.id.clone()).await self.db.remove_connection(actor.id.clone()).await
} }
#[tracing::instrument(name = "Fetch remote actor")] #[tracing::instrument(name = "Fetch remote actor", fields(id = id.to_string().as_str(), requests))]
pub(crate) async fn get_no_cache(&self, id: &Url, requests: &Requests) -> Result<Actor, Error> { pub(crate) async fn get_no_cache(&self, id: &Url, requests: &Requests) -> Result<Actor, Error> {
let accepted_actor = requests.fetch::<AcceptedActors>(id.as_str()).await?; let accepted_actor = requests.fetch::<AcceptedActors>(id.as_str()).await?;

View file

@ -19,7 +19,7 @@ impl MediaCache {
MediaCache { db } MediaCache { db }
} }
#[tracing::instrument(name = "Get media uuid")] #[tracing::instrument(name = "Get media uuid", fields(url = url.to_string().as_str()))]
pub(crate) async fn get_uuid(&self, url: Url) -> Result<Option<Uuid>, Error> { pub(crate) async fn get_uuid(&self, url: Url) -> Result<Option<Uuid>, Error> {
self.db.media_id(url).await self.db.media_id(url).await
} }
@ -55,7 +55,7 @@ impl MediaCache {
Ok(None) Ok(None)
} }
#[tracing::instrument(name = "Store media url")] #[tracing::instrument(name = "Store media url", fields(url = url.to_string().as_str()))]
pub(crate) async fn store_url(&self, url: Url) -> Result<Uuid, Error> { pub(crate) async fn store_url(&self, url: Url) -> Result<Uuid, Error> {
let uuid = Uuid::new_v4(); let uuid = Uuid::new_v4();

View file

@ -10,7 +10,7 @@ pub struct NodeCache {
db: Db, db: Db,
} }
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, serde::Deserialize, serde::Serialize)]
pub struct Node { pub struct Node {
pub(crate) base: Url, pub(crate) base: Url,
pub(crate) info: Option<Info>, pub(crate) info: Option<Info>,
@ -18,6 +18,17 @@ pub struct Node {
pub(crate) contact: Option<Contact>, pub(crate) contact: Option<Contact>,
} }
impl std::fmt::Debug for Node {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Node")
.field("base", &self.base.to_string())
.field("info", &self.info)
.field("instance", &self.instance)
.field("contact", &self.contact)
.finish()
}
}
impl NodeCache { impl NodeCache {
pub(crate) fn new(db: Db) -> Self { pub(crate) fn new(db: Db) -> Self {
NodeCache { db } NodeCache { db }
@ -49,7 +60,7 @@ impl NodeCache {
Ok(vec) Ok(vec)
} }
#[tracing::instrument(name = "Is NodeInfo Outdated")] #[tracing::instrument(name = "Is NodeInfo Outdated", fields(actor_id = actor_id.to_string().as_str()))]
pub(crate) async fn is_nodeinfo_outdated(&self, actor_id: Url) -> bool { pub(crate) async fn is_nodeinfo_outdated(&self, actor_id: Url) -> bool {
self.db self.db
.info(actor_id) .info(actor_id)
@ -58,7 +69,7 @@ impl NodeCache {
.unwrap_or(true) .unwrap_or(true)
} }
#[tracing::instrument(name = "Is Contact Outdated")] #[tracing::instrument(name = "Is Contact Outdated", fields(actor_id = actor_id.to_string().as_str()))]
pub(crate) async fn is_contact_outdated(&self, actor_id: Url) -> bool { pub(crate) async fn is_contact_outdated(&self, actor_id: Url) -> bool {
self.db self.db
.contact(actor_id) .contact(actor_id)
@ -67,7 +78,7 @@ impl NodeCache {
.unwrap_or(true) .unwrap_or(true)
} }
#[tracing::instrument(name = "Is Instance Outdated")] #[tracing::instrument(name = "Is Instance Outdated", fields(actor_id = actor_id.to_string().as_str()))]
pub(crate) async fn is_instance_outdated(&self, actor_id: Url) -> bool { pub(crate) async fn is_instance_outdated(&self, actor_id: Url) -> bool {
self.db self.db
.instance(actor_id) .instance(actor_id)
@ -76,7 +87,7 @@ impl NodeCache {
.unwrap_or(true) .unwrap_or(true)
} }
#[tracing::instrument(name = "Save node info")] #[tracing::instrument(name = "Save node info", fields(actor_id = actor_id.to_string().as_str(), software, version, reg))]
pub(crate) async fn set_info( pub(crate) async fn set_info(
&self, &self,
actor_id: Url, actor_id: Url,
@ -97,7 +108,17 @@ impl NodeCache {
.await .await
} }
#[tracing::instrument(name = "Save instance info")] #[tracing::instrument(
name = "Save instance info",
fields(
actor_id = actor_id.to_string().as_str(),
title,
description,
version,
reg,
requires_approval
)
)]
pub(crate) async fn set_instance( pub(crate) async fn set_instance(
&self, &self,
actor_id: Url, actor_id: Url,
@ -122,7 +143,16 @@ impl NodeCache {
.await .await
} }
#[tracing::instrument(name = "Save contact info")] #[tracing::instrument(
name = "Save contact info",
fields(
actor_id = actor_id.to_string().as_str(),
username,
display_name,
url = url.to_string().as_str(),
avatar = avatar.to_string().as_str()
)
)]
pub(crate) async fn set_contact( pub(crate) async fn set_contact(
&self, &self,
actor_id: Url, actor_id: Url,

View file

@ -27,9 +27,6 @@ pub struct State {
impl std::fmt::Debug for State { impl std::fmt::Debug for State {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("State") f.debug_struct("State")
.field("public_key", &"PublicKey")
.field("private_key", &"[redacted]")
.field("object_cache", &"Object Cache")
.field("node_cache", &self.node_cache) .field("node_cache", &self.node_cache)
.field("breakers", &self.breakers) .field("breakers", &self.breakers)
.field("db", &self.db) .field("db", &self.db)
@ -51,7 +48,13 @@ impl State {
) )
} }
#[tracing::instrument(name = "Get inboxes for other domains")] #[tracing::instrument(
name = "Get inboxes for other domains",
fields(
existing_inbox = existing_inbox.to_string().as_str(),
domain
)
)]
pub(crate) async fn inboxes_without( pub(crate) async fn inboxes_without(
&self, &self,
existing_inbox: &Url, existing_inbox: &Url,

View file

@ -39,7 +39,7 @@ impl std::fmt::Debug for Inner {
} }
} }
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, serde::Deserialize, serde::Serialize)]
pub struct Actor { pub struct Actor {
pub(crate) id: Url, pub(crate) id: Url,
pub(crate) public_key: String, pub(crate) public_key: String,
@ -48,6 +48,18 @@ pub struct Actor {
pub(crate) saved_at: SystemTime, pub(crate) saved_at: SystemTime,
} }
impl std::fmt::Debug for Actor {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Actor")
.field("id", &self.id.to_string())
.field("public_key", &self.public_key)
.field("public_key_id", &self.public_key_id.to_string())
.field("inbox", &self.inbox.to_string())
.field("saved_at", &self.saved_at)
.finish()
}
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub(crate) struct MediaMeta { pub(crate) struct MediaMeta {
pub(crate) media_type: String, pub(crate) media_type: String,
@ -72,7 +84,7 @@ pub struct Instance {
pub(crate) updated: SystemTime, pub(crate) updated: SystemTime,
} }
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, serde::Deserialize, serde::Serialize)]
pub struct Contact { pub struct Contact {
pub(crate) username: String, pub(crate) username: String,
pub(crate) display_name: String, pub(crate) display_name: String,
@ -81,6 +93,18 @@ pub struct Contact {
pub(crate) updated: SystemTime, pub(crate) updated: SystemTime,
} }
impl std::fmt::Debug for Contact {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Info")
.field("username", &self.username)
.field("display_name", &self.display_name)
.field("url", &self.url.to_string())
.field("avatar", &self.avatar.to_string())
.field("updated", &self.updated)
.finish()
}
}
impl Inner { impl Inner {
fn connected_by_domain(&self, domains: &[String]) -> impl DoubleEndedIterator<Item = Url> { fn connected_by_domain(&self, domains: &[String]) -> impl DoubleEndedIterator<Item = Url> {
let reversed: Vec<_> = domains let reversed: Vec<_> = domains

View file

@ -145,7 +145,7 @@ pub(crate) enum ErrorKind {
Breaker, Breaker,
#[error("Failed to extract fields from {0}")] #[error("Failed to extract fields from {0}")]
Extract(&'static str) Extract(&'static str),
} }
impl ResponseError for Error { impl ResponseError for Error {

View file

@ -11,12 +11,21 @@ use activitystreams::{activity::Announce as AsAnnounce, url::Url};
use background_jobs::ActixJob; use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct Announce { pub(crate) struct Announce {
object_id: Url, object_id: Url,
actor: Actor, actor: Actor,
} }
impl std::fmt::Debug for Announce {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Announce")
.field("object_id", &self.object_id.to_string())
.field("actor", &self.actor)
.finish()
}
}
impl Announce { impl Announce {
pub fn new(object_id: Url, actor: Actor) -> Self { pub fn new(object_id: Url, actor: Actor) -> Self {
Announce { object_id, actor } Announce { object_id, actor }

View file

@ -7,12 +7,21 @@ use activitystreams::{object::Image, prelude::*, url::Url};
use background_jobs::ActixJob; use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct QueryContact { pub(crate) struct QueryContact {
actor_id: Url, actor_id: Url,
contact_id: Url, contact_id: Url,
} }
impl std::fmt::Debug for QueryContact {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryContact")
.field("actor_id", &self.actor_id.to_string())
.field("contact_id", &self.contact_id.to_string())
.finish()
}
}
impl QueryContact { impl QueryContact {
pub(crate) fn new(actor_id: Url, contact_id: Url) -> Self { pub(crate) fn new(actor_id: Url, contact_id: Url) -> Self {
QueryContact { QueryContact {

View file

@ -3,12 +3,21 @@ use activitystreams::url::Url;
use background_jobs::{ActixJob, Backoff}; use background_jobs::{ActixJob, Backoff};
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct Deliver { pub(crate) struct Deliver {
to: Url, to: Url,
data: serde_json::Value, data: serde_json::Value,
} }
impl std::fmt::Debug for Deliver {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Deliver")
.field("to", &self.to.to_string())
.field("data", &self.data)
.finish()
}
}
impl Deliver { impl Deliver {
pub(crate) fn new<T>(to: Url, data: T) -> Result<Self, Error> pub(crate) fn new<T>(to: Url, data: T) -> Result<Self, Error>
where where

View file

@ -6,12 +6,29 @@ use activitystreams::url::Url;
use background_jobs::ActixJob; use background_jobs::ActixJob;
use std::future::{ready, Ready}; use std::future::{ready, Ready};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct DeliverMany { pub(crate) struct DeliverMany {
to: Vec<Url>, to: Vec<Url>,
data: serde_json::Value, data: serde_json::Value,
} }
impl std::fmt::Debug for DeliverMany {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let to = format!(
"[{}]",
self.to
.iter()
.map(|u| u.to_string())
.collect::<Vec<_>>()
.join(", ")
);
f.debug_struct("DeliverMany")
.field("to", &to)
.field("data", &self.data)
.finish()
}
}
impl DeliverMany { impl DeliverMany {
pub(crate) fn new<T>(to: Vec<Url>, data: T) -> Result<Self, Error> pub(crate) fn new<T>(to: Vec<Url>, data: T) -> Result<Self, Error>
where where

View file

@ -7,11 +7,19 @@ use activitystreams::url::Url;
use background_jobs::ActixJob; use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct QueryInstance { pub(crate) struct QueryInstance {
actor_id: Url, actor_id: Url,
} }
impl std::fmt::Debug for QueryInstance {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryInstance")
.field("actor_id", &self.actor_id.to_string())
.finish()
}
}
impl QueryInstance { impl QueryInstance {
pub(crate) fn new(actor_id: Url) -> Self { pub(crate) fn new(actor_id: Url) -> Self {
QueryInstance { actor_id } QueryInstance { actor_id }

View file

@ -4,13 +4,21 @@ use crate::{
}; };
use activitystreams::url::Url; use activitystreams::url::Url;
use background_jobs::ActixJob; use background_jobs::ActixJob;
use std::{future::Future, pin::Pin}; use std::{fmt::Debug, future::Future, pin::Pin};
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct QueryNodeinfo { pub(crate) struct QueryNodeinfo {
actor_id: Url, actor_id: Url,
} }
impl Debug for QueryNodeinfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryNodeinfo")
.field("actor_id", &self.actor_id.to_string())
.finish()
}
}
impl QueryNodeinfo { impl QueryNodeinfo {
pub(crate) fn new(actor_id: Url) -> Self { pub(crate) fn new(actor_id: Url) -> Self {
QueryNodeinfo { actor_id } QueryNodeinfo { actor_id }

View file

@ -361,7 +361,10 @@ impl Requests {
Ok((content_type, bytes)) Ok((content_type, bytes))
} }
#[tracing::instrument("Deliver to Inbox")] #[tracing::instrument(
"Deliver to Inbox",
fields(self, inbox = inbox.to_string().as_str(), item)
)]
pub(crate) async fn deliver<T>(&self, inbox: Url, item: &T) -> Result<(), Error> pub(crate) async fn deliver<T>(&self, inbox: Url, item: &T) -> Result<(), Error>
where where
T: serde::ser::Serialize + std::fmt::Debug, T: serde::ser::Serialize + std::fmt::Debug,