forked from mirrors/relay
Clippy
This commit is contained in:
parent
a417a3d054
commit
0b2763ab8b
13 changed files with 27 additions and 28 deletions
|
@ -93,7 +93,7 @@ pub struct Endpoints {
|
|||
}
|
||||
|
||||
impl PublicKey {
|
||||
pub fn to_ext(self) -> PublicKeyExtension {
|
||||
pub fn into_ext(self) -> PublicKeyExtension {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,15 +65,15 @@ impl ActorCache {
|
|||
let inbox_host = accepted_actor.inbox().as_url().host();
|
||||
|
||||
if input_host != actor_host {
|
||||
let input_host = input_host.map(|h| h.to_string()).unwrap_or(String::new());
|
||||
let actor_host = actor_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_default();
|
||||
|
||||
return Err(MyError::HostMismatch(input_host, actor_host));
|
||||
}
|
||||
|
||||
if actor_host != inbox_host {
|
||||
let actor_host = actor_host.map(|h| h.to_string()).unwrap_or(String::new());
|
||||
let inbox_host = inbox_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_default();
|
||||
|
||||
return Err(MyError::HostMismatch(actor_host, inbox_host));
|
||||
}
|
||||
|
|
|
@ -90,9 +90,8 @@ impl Media {
|
|||
}
|
||||
|
||||
pub async fn get_url(&self, uuid: Uuid) -> Result<Option<XsdAnyUri>, MyError> {
|
||||
match self.url_cache.lock().await.get(&uuid).cloned() {
|
||||
Some(url) => return Ok(Some(url)),
|
||||
_ => (),
|
||||
if let Some(url) = self.url_cache.lock().await.get(&uuid).cloned() {
|
||||
return Ok(Some(url));
|
||||
}
|
||||
|
||||
let row_opt = self
|
||||
|
|
|
@ -179,7 +179,7 @@ impl NodeCache {
|
|||
let mut write_guard = self.nodes.write().await;
|
||||
let node = write_guard
|
||||
.entry(listener.clone())
|
||||
.or_insert(Node::new(listener));
|
||||
.or_insert_with(|| Node::new(listener));
|
||||
|
||||
if let Some(info) = info {
|
||||
node.info = Some(info.0);
|
||||
|
@ -212,7 +212,7 @@ impl NodeCache {
|
|||
let mut write_guard = self.nodes.write().await;
|
||||
let node = write_guard
|
||||
.entry(listener.clone())
|
||||
.or_insert(Node::new(listener.clone()));
|
||||
.or_insert_with(|| Node::new(listener.clone()));
|
||||
node.set_info(software, version, reg);
|
||||
node.clone()
|
||||
};
|
||||
|
@ -239,7 +239,7 @@ impl NodeCache {
|
|||
let mut write_guard = self.nodes.write().await;
|
||||
let node = write_guard
|
||||
.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.clone()
|
||||
};
|
||||
|
@ -265,7 +265,7 @@ impl NodeCache {
|
|||
let mut write_guard = self.nodes.write().await;
|
||||
let node = write_guard
|
||||
.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.clone()
|
||||
};
|
||||
|
|
|
@ -206,9 +206,8 @@ impl State {
|
|||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
match state.rehydrate(&db).await {
|
||||
Err(e) => error!("Error rehydrating, {}", e),
|
||||
_ => (),
|
||||
if let Err(e) = state.rehydrate(&db).await {
|
||||
error!("Error rehydrating, {}", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -68,7 +68,7 @@ impl Db {
|
|||
for domain in domains {
|
||||
match add_block(&conn, domain.as_str()).await {
|
||||
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 {
|
||||
match add_whitelist(&conn, domain.as_str()).await {
|
||||
Err(e) if e.code() != Some(&SqlState::UNIQUE_VIOLATION) => {
|
||||
Err(e)?;
|
||||
return Err(e.into());
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@ pub struct Reject(pub Actor);
|
|||
|
||||
impl Reject {
|
||||
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?;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ impl Undo {
|
|||
async fn perform(self, state: JobState) -> Result<(), anyhow::Error> {
|
||||
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?;
|
||||
}
|
||||
|
||||
|
|
|
@ -110,8 +110,8 @@ impl<T> MaybeSupported<T> {
|
|||
struct SupportedVersion(String);
|
||||
struct SupportedNodeinfo(String);
|
||||
|
||||
static SUPPORTED_VERSIONS: &'static str = "2.";
|
||||
static SUPPORTED_NODEINFO: &'static str = "http://nodeinfo.diaspora.software/ns/schema/2.";
|
||||
static SUPPORTED_VERSIONS: &str = "2.";
|
||||
static SUPPORTED_NODEINFO: &str = "http://nodeinfo.diaspora.software/ns/schema/2.";
|
||||
|
||||
struct SupportedVersionVisitor;
|
||||
struct SupportedNodeinfoVisitor;
|
||||
|
|
|
@ -13,6 +13,8 @@ pub struct RelayResolver;
|
|||
#[error("Error resolving webfinger data")]
|
||||
pub struct RelayError;
|
||||
|
||||
type FutResult<T, E> = dyn Future<Output = Result<T, E>>;
|
||||
|
||||
impl Resolver for RelayResolver {
|
||||
type State = (Data<State>, Data<Config>);
|
||||
type Error = RelayError;
|
||||
|
@ -21,7 +23,7 @@ impl Resolver for RelayResolver {
|
|||
account: &str,
|
||||
domain: &str,
|
||||
(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 account = account.to_owned();
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ impl Notifier {
|
|||
let v = self
|
||||
.listeners
|
||||
.entry(l.key().to_owned())
|
||||
.or_insert(Vec::new());
|
||||
.or_insert_with(Vec::new);
|
||||
v.push(Box::new(l));
|
||||
self
|
||||
}
|
||||
|
|
|
@ -44,5 +44,5 @@ pub async fn route(
|
|||
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())))
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@ pub async fn route(
|
|||
client: web::Data<Requests>,
|
||||
jobs: web::Data<JobServer>,
|
||||
input: web::Json<AcceptedObjects>,
|
||||
verified: Option<SignatureVerified>,
|
||||
digest_verified: Option<DigestVerified>,
|
||||
verified: Option<(SignatureVerified, DigestVerified)>,
|
||||
) -> Result<HttpResponse, MyError> {
|
||||
let input = input.into_inner();
|
||||
|
||||
|
@ -46,10 +45,10 @@ pub async fn route(
|
|||
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()));
|
||||
} 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() {
|
||||
error!("Bad actor, more info: {:?}", input);
|
||||
return Err(MyError::BadActor(
|
||||
|
|
Loading…
Reference in a new issue