This commit is contained in:
asonix 2020-04-25 20:49:29 -05:00
parent a417a3d054
commit 0b2763ab8b
13 changed files with 27 additions and 28 deletions

View file

@ -93,7 +93,7 @@ pub struct Endpoints {
} }
impl PublicKey { impl PublicKey {
pub fn to_ext(self) -> PublicKeyExtension { pub fn into_ext(self) -> PublicKeyExtension {
self.into() self.into()
} }
} }

View file

@ -65,15 +65,15 @@ impl ActorCache {
let inbox_host = accepted_actor.inbox().as_url().host(); let inbox_host = accepted_actor.inbox().as_url().host();
if input_host != actor_host { if input_host != actor_host {
let input_host = input_host.map(|h| h.to_string()).unwrap_or(String::new()); let input_host = input_host.map(|h| h.to_string()).unwrap_or_default();
let actor_host = actor_host.map(|h| h.to_string()).unwrap_or(String::new()); let actor_host = actor_host.map(|h| h.to_string()).unwrap_or_default();
return Err(MyError::HostMismatch(input_host, actor_host)); return Err(MyError::HostMismatch(input_host, actor_host));
} }
if actor_host != inbox_host { if actor_host != inbox_host {
let actor_host = actor_host.map(|h| h.to_string()).unwrap_or(String::new()); let actor_host = actor_host.map(|h| h.to_string()).unwrap_or_default();
let inbox_host = inbox_host.map(|h| h.to_string()).unwrap_or(String::new()); let inbox_host = inbox_host.map(|h| h.to_string()).unwrap_or_default();
return Err(MyError::HostMismatch(actor_host, inbox_host)); return Err(MyError::HostMismatch(actor_host, inbox_host));
} }

View file

@ -90,9 +90,8 @@ impl Media {
} }
pub async fn get_url(&self, uuid: Uuid) -> Result<Option<XsdAnyUri>, MyError> { pub async fn get_url(&self, uuid: Uuid) -> Result<Option<XsdAnyUri>, MyError> {
match self.url_cache.lock().await.get(&uuid).cloned() { if let Some(url) = self.url_cache.lock().await.get(&uuid).cloned() {
Some(url) => return Ok(Some(url)), return Ok(Some(url));
_ => (),
} }
let row_opt = self let row_opt = self

View file

@ -179,7 +179,7 @@ impl NodeCache {
let mut write_guard = self.nodes.write().await; let mut write_guard = self.nodes.write().await;
let node = write_guard let node = write_guard
.entry(listener.clone()) .entry(listener.clone())
.or_insert(Node::new(listener)); .or_insert_with(|| Node::new(listener));
if let Some(info) = info { if let Some(info) = info {
node.info = Some(info.0); node.info = Some(info.0);
@ -212,7 +212,7 @@ impl NodeCache {
let mut write_guard = self.nodes.write().await; let mut write_guard = self.nodes.write().await;
let node = write_guard let node = write_guard
.entry(listener.clone()) .entry(listener.clone())
.or_insert(Node::new(listener.clone())); .or_insert_with(|| Node::new(listener.clone()));
node.set_info(software, version, reg); node.set_info(software, version, reg);
node.clone() node.clone()
}; };
@ -239,7 +239,7 @@ impl NodeCache {
let mut write_guard = self.nodes.write().await; let mut write_guard = self.nodes.write().await;
let node = write_guard let node = write_guard
.entry(listener.clone()) .entry(listener.clone())
.or_insert(Node::new(listener.clone())); .or_insert_with(|| Node::new(listener.clone()));
node.set_instance(title, description, version, reg, requires_approval); node.set_instance(title, description, version, reg, requires_approval);
node.clone() node.clone()
}; };
@ -265,7 +265,7 @@ impl NodeCache {
let mut write_guard = self.nodes.write().await; let mut write_guard = self.nodes.write().await;
let node = write_guard let node = write_guard
.entry(listener.clone()) .entry(listener.clone())
.or_insert(Node::new(listener.clone())); .or_insert_with(|| Node::new(listener.clone()));
node.set_contact(username, display_name, url, avatar); node.set_contact(username, display_name, url, avatar);
node.clone() node.clone()
}; };

View file

@ -206,9 +206,8 @@ impl State {
loop { loop {
interval.tick().await; interval.tick().await;
match state.rehydrate(&db).await { if let Err(e) = state.rehydrate(&db).await {
Err(e) => error!("Error rehydrating, {}", e), error!("Error rehydrating, {}", e);
_ => (),
} }
} }
}); });

View file

@ -68,7 +68,7 @@ impl Db {
for domain in domains { for domain in domains {
match add_block(&conn, domain.as_str()).await { match add_block(&conn, domain.as_str()).await {
Err(e) if e.code() != Some(&SqlState::UNIQUE_VIOLATION) => { Err(e) if e.code() != Some(&SqlState::UNIQUE_VIOLATION) => {
Err(e)?; return Err(e.into());
} }
_ => (), _ => (),
}; };
@ -89,7 +89,7 @@ impl Db {
for domain in domains { for domain in domains {
match add_whitelist(&conn, domain.as_str()).await { match add_whitelist(&conn, domain.as_str()).await {
Err(e) if e.code() != Some(&SqlState::UNIQUE_VIOLATION) => { Err(e) if e.code() != Some(&SqlState::UNIQUE_VIOLATION) => {
Err(e)?; return Err(e.into());
} }
_ => (), _ => (),
}; };

View file

@ -12,7 +12,7 @@ pub struct Reject(pub Actor);
impl Reject { impl Reject {
async fn perform(self, state: JobState) -> Result<(), anyhow::Error> { async fn perform(self, state: JobState) -> Result<(), anyhow::Error> {
if let Some(_) = state.actors.unfollower(&self.0).await? { if state.actors.unfollower(&self.0).await?.is_some() {
state.db.remove_listener(self.0.inbox.clone()).await?; state.db.remove_listener(self.0.inbox.clone()).await?;
} }

View file

@ -22,7 +22,7 @@ impl Undo {
async fn perform(self, state: JobState) -> Result<(), anyhow::Error> { async fn perform(self, state: JobState) -> Result<(), anyhow::Error> {
let was_following = state.actors.is_following(&self.actor.id).await; let was_following = state.actors.is_following(&self.actor.id).await;
if let Some(_) = state.actors.unfollower(&self.actor).await? { if state.actors.unfollower(&self.actor).await?.is_some() {
state.db.remove_listener(self.actor.inbox.clone()).await?; state.db.remove_listener(self.actor.inbox.clone()).await?;
} }

View file

@ -110,8 +110,8 @@ impl<T> MaybeSupported<T> {
struct SupportedVersion(String); struct SupportedVersion(String);
struct SupportedNodeinfo(String); struct SupportedNodeinfo(String);
static SUPPORTED_VERSIONS: &'static str = "2."; static SUPPORTED_VERSIONS: &str = "2.";
static SUPPORTED_NODEINFO: &'static str = "http://nodeinfo.diaspora.software/ns/schema/2."; static SUPPORTED_NODEINFO: &str = "http://nodeinfo.diaspora.software/ns/schema/2.";
struct SupportedVersionVisitor; struct SupportedVersionVisitor;
struct SupportedNodeinfoVisitor; struct SupportedNodeinfoVisitor;

View file

@ -13,6 +13,8 @@ pub struct RelayResolver;
#[error("Error resolving webfinger data")] #[error("Error resolving webfinger data")]
pub struct RelayError; pub struct RelayError;
type FutResult<T, E> = dyn Future<Output = Result<T, E>>;
impl Resolver for RelayResolver { impl Resolver for RelayResolver {
type State = (Data<State>, Data<Config>); type State = (Data<State>, Data<Config>);
type Error = RelayError; type Error = RelayError;
@ -21,7 +23,7 @@ impl Resolver for RelayResolver {
account: &str, account: &str,
domain: &str, domain: &str,
(state, config): Self::State, (state, config): Self::State,
) -> Pin<Box<dyn Future<Output = Result<Option<Webfinger>, Self::Error>>>> { ) -> Pin<Box<FutResult<Option<Webfinger>, Self::Error>>> {
let domain = domain.to_owned(); let domain = domain.to_owned();
let account = account.to_owned(); let account = account.to_owned();

View file

@ -37,7 +37,7 @@ impl Notifier {
let v = self let v = self
.listeners .listeners
.entry(l.key().to_owned()) .entry(l.key().to_owned())
.or_insert(Vec::new()); .or_insert_with(Vec::new);
v.push(Box::new(l)); v.push(Box::new(l));
self self
} }

View file

@ -44,5 +44,5 @@ pub async fn route(
public_key_pem: state.public_key.to_pem_pkcs8()?, public_key_pem: state.public_key.to_pem_pkcs8()?,
}; };
Ok(ok(application.extend(public_key.to_ext()))) Ok(ok(application.extend(public_key.into_ext())))
} }

View file

@ -21,8 +21,7 @@ pub async fn route(
client: web::Data<Requests>, client: web::Data<Requests>,
jobs: web::Data<JobServer>, jobs: web::Data<JobServer>,
input: web::Json<AcceptedObjects>, input: web::Json<AcceptedObjects>,
verified: Option<SignatureVerified>, verified: Option<(SignatureVerified, DigestVerified)>,
digest_verified: Option<DigestVerified>,
) -> Result<HttpResponse, MyError> { ) -> Result<HttpResponse, MyError> {
let input = input.into_inner(); let input = input.into_inner();
@ -46,10 +45,10 @@ pub async fn route(
return Err(MyError::NotSubscribed(actor.inbox.to_string())); return Err(MyError::NotSubscribed(actor.inbox.to_string()));
} }
if config.validate_signatures() && (digest_verified.is_none() || verified.is_none()) { if config.validate_signatures() && verified.is_none() {
return Err(MyError::NoSignature(actor.public_key_id.to_string())); return Err(MyError::NoSignature(actor.public_key_id.to_string()));
} else if config.validate_signatures() { } else if config.validate_signatures() {
if let Some(verified) = verified { if let Some((verified, _)) = verified {
if actor.public_key_id.as_str() != verified.key_id() { if actor.public_key_id.as_str() != verified.key_id() {
error!("Bad actor, more info: {:?}", input); error!("Bad actor, more info: {:?}", input);
return Err(MyError::BadActor( return Err(MyError::BadActor(