|
|
@ -1,25 +1,23 @@
|
|
|
|
/// An async function that can recursively call itself.
|
|
|
|
/// An async function that can recursively call itself.
|
|
|
|
type AsyncRecursiveType<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
|
|
|
|
type AsyncRecursiveType<'a, T> = Pin<Box<dyn Future<Output = T> + 'a + Send>>;
|
|
|
|
|
|
|
|
|
|
|
|
use ruma::{
|
|
|
|
|
|
|
|
api::federation::discovery::{get_remote_server_keys, get_server_keys},
|
|
|
|
|
|
|
|
CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, OwnedServerSigningKeyId,
|
|
|
|
|
|
|
|
RoomVersionId,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
use std::{
|
|
|
|
use std::{
|
|
|
|
collections::{hash_map, BTreeMap, HashMap, HashSet},
|
|
|
|
collections::{hash_map, BTreeMap, HashMap, HashSet},
|
|
|
|
pin::Pin,
|
|
|
|
pin::Pin,
|
|
|
|
sync::{Arc, RwLock, RwLockWriteGuard},
|
|
|
|
sync::Arc,
|
|
|
|
time::{Duration, Instant, SystemTime},
|
|
|
|
time::{Duration, Instant, SystemTime},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use tokio::sync::Semaphore;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use futures_util::{stream::FuturesUnordered, Future, StreamExt};
|
|
|
|
use futures_util::{stream::FuturesUnordered, Future, StreamExt};
|
|
|
|
use ruma::{
|
|
|
|
use ruma::{
|
|
|
|
api::{
|
|
|
|
api::{
|
|
|
|
client::error::ErrorKind,
|
|
|
|
client::error::ErrorKind,
|
|
|
|
federation::{
|
|
|
|
federation::{
|
|
|
|
discovery::get_remote_server_keys_batch::{self, v2::QueryCriteria},
|
|
|
|
discovery::{
|
|
|
|
|
|
|
|
get_remote_server_keys,
|
|
|
|
|
|
|
|
get_remote_server_keys_batch::{self, v2::QueryCriteria},
|
|
|
|
|
|
|
|
get_server_keys,
|
|
|
|
|
|
|
|
},
|
|
|
|
event::{get_event, get_room_state_ids},
|
|
|
|
event::{get_event, get_room_state_ids},
|
|
|
|
membership::create_join_event,
|
|
|
|
membership::create_join_event,
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -31,9 +29,11 @@ use ruma::{
|
|
|
|
int,
|
|
|
|
int,
|
|
|
|
serde::Base64,
|
|
|
|
serde::Base64,
|
|
|
|
state_res::{self, RoomVersion, StateMap},
|
|
|
|
state_res::{self, RoomVersion, StateMap},
|
|
|
|
uint, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName,
|
|
|
|
uint, CanonicalJsonObject, CanonicalJsonValue, EventId, MilliSecondsSinceUnixEpoch,
|
|
|
|
|
|
|
|
OwnedServerName, OwnedServerSigningKeyId, RoomId, RoomVersionId, ServerName,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use serde_json::value::RawValue as RawJsonValue;
|
|
|
|
use serde_json::value::RawValue as RawJsonValue;
|
|
|
|
|
|
|
|
use tokio::sync::{RwLock, RwLockWriteGuard, Semaphore};
|
|
|
|
use tracing::{debug, error, info, trace, warn};
|
|
|
|
use tracing::{debug, error, info, trace, warn};
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{service::*, services, Error, PduEvent, Result};
|
|
|
|
use crate::{service::*, services, Error, PduEvent, Result};
|
|
|
@ -168,7 +168,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.read()
|
|
|
|
.read()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.get(&*prev_id)
|
|
|
|
.get(&*prev_id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Exponential backoff
|
|
|
|
// Exponential backoff
|
|
|
@ -189,7 +189,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.write()
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.entry((*prev_id).to_owned())
|
|
|
|
.entry((*prev_id).to_owned())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
hash_map::Entry::Vacant(e) => {
|
|
|
|
hash_map::Entry::Vacant(e) => {
|
|
|
@ -213,7 +213,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.roomid_federationhandletime
|
|
|
|
.roomid_federationhandletime
|
|
|
|
.write()
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.insert(room_id.to_owned(), ((*prev_id).to_owned(), start_time));
|
|
|
|
.insert(room_id.to_owned(), ((*prev_id).to_owned(), start_time));
|
|
|
|
|
|
|
|
|
|
|
|
if let Err(e) = self
|
|
|
|
if let Err(e) = self
|
|
|
@ -233,7 +233,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.write()
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.entry((*prev_id).to_owned())
|
|
|
|
.entry((*prev_id).to_owned())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
hash_map::Entry::Vacant(e) => {
|
|
|
|
hash_map::Entry::Vacant(e) => {
|
|
|
@ -249,7 +249,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.roomid_federationhandletime
|
|
|
|
.roomid_federationhandletime
|
|
|
|
.write()
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.remove(&room_id.to_owned());
|
|
|
|
.remove(&room_id.to_owned());
|
|
|
|
debug!(
|
|
|
|
debug!(
|
|
|
|
"Handling prev event {} took {}m{}s",
|
|
|
|
"Handling prev event {} took {}m{}s",
|
|
|
@ -267,7 +267,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.roomid_federationhandletime
|
|
|
|
.roomid_federationhandletime
|
|
|
|
.write()
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.insert(room_id.to_owned(), (event_id.to_owned(), start_time));
|
|
|
|
.insert(room_id.to_owned(), (event_id.to_owned(), start_time));
|
|
|
|
let r = services()
|
|
|
|
let r = services()
|
|
|
|
.rooms
|
|
|
|
.rooms
|
|
|
@ -285,7 +285,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.roomid_federationhandletime
|
|
|
|
.roomid_federationhandletime
|
|
|
|
.write()
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.remove(&room_id.to_owned());
|
|
|
|
.remove(&room_id.to_owned());
|
|
|
|
|
|
|
|
|
|
|
|
r
|
|
|
|
r
|
|
|
@ -326,11 +326,8 @@ impl Service {
|
|
|
|
let room_version =
|
|
|
|
let room_version =
|
|
|
|
RoomVersion::new(room_version_id).expect("room version is supported");
|
|
|
|
RoomVersion::new(room_version_id).expect("room version is supported");
|
|
|
|
|
|
|
|
|
|
|
|
let mut val = match ruma::signatures::verify_event(
|
|
|
|
let guard = pub_key_map.read().await;
|
|
|
|
&pub_key_map.read().expect("RwLock is poisoned."),
|
|
|
|
let mut val = match ruma::signatures::verify_event(&guard, &value, room_version_id) {
|
|
|
|
&value,
|
|
|
|
|
|
|
|
room_version_id,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Err(e) => {
|
|
|
|
Err(e) => {
|
|
|
|
// Drop
|
|
|
|
// Drop
|
|
|
|
warn!("Dropping bad event {}: {}", event_id, e,);
|
|
|
|
warn!("Dropping bad event {}: {}", event_id, e,);
|
|
|
@ -365,6 +362,8 @@ impl Service {
|
|
|
|
Ok(ruma::signatures::Verified::All) => value,
|
|
|
|
Ok(ruma::signatures::Verified::All) => value,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drop(guard);
|
|
|
|
|
|
|
|
|
|
|
|
// Now that we have checked the signature and hashes we can add the eventID and convert
|
|
|
|
// Now that we have checked the signature and hashes we can add the eventID and convert
|
|
|
|
// to our PduEvent type
|
|
|
|
// to our PduEvent type
|
|
|
|
val.insert(
|
|
|
|
val.insert(
|
|
|
@ -692,13 +691,15 @@ impl Service {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Ok(res) => {
|
|
|
|
Ok(res) => {
|
|
|
|
debug!("Fetching state events at event.");
|
|
|
|
debug!("Fetching state events at event.");
|
|
|
|
|
|
|
|
let collect = res
|
|
|
|
|
|
|
|
.pdu_ids
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.map(|x| Arc::from(&**x))
|
|
|
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let state_vec = self
|
|
|
|
let state_vec = self
|
|
|
|
.fetch_and_handle_outliers(
|
|
|
|
.fetch_and_handle_outliers(
|
|
|
|
origin,
|
|
|
|
origin,
|
|
|
|
&res.pdu_ids
|
|
|
|
&collect,
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.map(|x| Arc::from(&**x))
|
|
|
|
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
|
|
|
|
create_event,
|
|
|
|
create_event,
|
|
|
|
room_id,
|
|
|
|
room_id,
|
|
|
|
room_version_id,
|
|
|
|
room_version_id,
|
|
|
@ -805,7 +806,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.roomid_mutex_state
|
|
|
|
.roomid_mutex_state
|
|
|
|
.write()
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.entry(room_id.to_owned())
|
|
|
|
.entry(room_id.to_owned())
|
|
|
|
.or_default(),
|
|
|
|
.or_default(),
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -884,14 +885,18 @@ impl Service {
|
|
|
|
debug!("Starting soft fail auth check");
|
|
|
|
debug!("Starting soft fail auth check");
|
|
|
|
|
|
|
|
|
|
|
|
if soft_fail {
|
|
|
|
if soft_fail {
|
|
|
|
services().rooms.timeline.append_incoming_pdu(
|
|
|
|
services()
|
|
|
|
|
|
|
|
.rooms
|
|
|
|
|
|
|
|
.timeline
|
|
|
|
|
|
|
|
.append_incoming_pdu(
|
|
|
|
&incoming_pdu,
|
|
|
|
&incoming_pdu,
|
|
|
|
val,
|
|
|
|
val,
|
|
|
|
extremities.iter().map(|e| (**e).to_owned()).collect(),
|
|
|
|
extremities.iter().map(|e| (**e).to_owned()).collect(),
|
|
|
|
state_ids_compressed,
|
|
|
|
state_ids_compressed,
|
|
|
|
soft_fail,
|
|
|
|
soft_fail,
|
|
|
|
&state_lock,
|
|
|
|
&state_lock,
|
|
|
|
)?;
|
|
|
|
)
|
|
|
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
// Soft fail, we keep the event as an outlier but don't add it to the timeline
|
|
|
|
// Soft fail, we keep the event as an outlier but don't add it to the timeline
|
|
|
|
warn!("Event was soft failed: {:?}", incoming_pdu);
|
|
|
|
warn!("Event was soft failed: {:?}", incoming_pdu);
|
|
|
@ -912,14 +917,18 @@ impl Service {
|
|
|
|
// We use the `state_at_event` instead of `state_after` so we accurately
|
|
|
|
// We use the `state_at_event` instead of `state_after` so we accurately
|
|
|
|
// represent the state for this event.
|
|
|
|
// represent the state for this event.
|
|
|
|
|
|
|
|
|
|
|
|
let pdu_id = services().rooms.timeline.append_incoming_pdu(
|
|
|
|
let pdu_id = services()
|
|
|
|
|
|
|
|
.rooms
|
|
|
|
|
|
|
|
.timeline
|
|
|
|
|
|
|
|
.append_incoming_pdu(
|
|
|
|
&incoming_pdu,
|
|
|
|
&incoming_pdu,
|
|
|
|
val,
|
|
|
|
val,
|
|
|
|
extremities.iter().map(|e| (**e).to_owned()).collect(),
|
|
|
|
extremities.iter().map(|e| (**e).to_owned()).collect(),
|
|
|
|
state_ids_compressed,
|
|
|
|
state_ids_compressed,
|
|
|
|
soft_fail,
|
|
|
|
soft_fail,
|
|
|
|
&state_lock,
|
|
|
|
&state_lock,
|
|
|
|
)?;
|
|
|
|
)
|
|
|
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
debug!("Appended incoming pdu");
|
|
|
|
debug!("Appended incoming pdu");
|
|
|
|
|
|
|
|
|
|
|
@ -1045,17 +1054,21 @@ impl Service {
|
|
|
|
) -> AsyncRecursiveType<'a, Vec<(Arc<PduEvent>, Option<BTreeMap<String, CanonicalJsonValue>>)>>
|
|
|
|
) -> AsyncRecursiveType<'a, Vec<(Arc<PduEvent>, Option<BTreeMap<String, CanonicalJsonValue>>)>>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Box::pin(async move {
|
|
|
|
Box::pin(async move {
|
|
|
|
let back_off = |id| match services()
|
|
|
|
let back_off = |id| async move {
|
|
|
|
|
|
|
|
match services()
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.write()
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.entry(id)
|
|
|
|
.entry(id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
hash_map::Entry::Vacant(e) => {
|
|
|
|
hash_map::Entry::Vacant(e) => {
|
|
|
|
e.insert((Instant::now(), 1));
|
|
|
|
e.insert((Instant::now(), 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hash_map::Entry::Occupied(mut e) => *e.get_mut() = (Instant::now(), e.get().1 + 1),
|
|
|
|
hash_map::Entry::Occupied(mut e) => {
|
|
|
|
|
|
|
|
*e.get_mut() = (Instant::now(), e.get().1 + 1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let mut pdus = vec![];
|
|
|
|
let mut pdus = vec![];
|
|
|
@ -1081,7 +1094,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.read()
|
|
|
|
.read()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.get(&*next_id)
|
|
|
|
.get(&*next_id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Exponential backoff
|
|
|
|
// Exponential backoff
|
|
|
@ -1128,7 +1141,7 @@ impl Service {
|
|
|
|
match pdu::gen_event_id_canonical_json(&res.pdu, room_version_id) {
|
|
|
|
match pdu::gen_event_id_canonical_json(&res.pdu, room_version_id) {
|
|
|
|
Ok(t) => t,
|
|
|
|
Ok(t) => t,
|
|
|
|
Err(_) => {
|
|
|
|
Err(_) => {
|
|
|
|
back_off((*next_id).to_owned());
|
|
|
|
back_off((*next_id).to_owned()).await;
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -1160,7 +1173,7 @@ impl Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(_) => {
|
|
|
|
Err(_) => {
|
|
|
|
warn!("Failed to fetch event: {}", next_id);
|
|
|
|
warn!("Failed to fetch event: {}", next_id);
|
|
|
|
back_off((*next_id).to_owned());
|
|
|
|
back_off((*next_id).to_owned()).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1170,7 +1183,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.read()
|
|
|
|
.read()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.get(&**next_id)
|
|
|
|
.get(&**next_id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Exponential backoff
|
|
|
|
// Exponential backoff
|
|
|
@ -1205,7 +1218,7 @@ impl Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
Err(e) => {
|
|
|
|
warn!("Authentication of event {} failed: {:?}", next_id, e);
|
|
|
|
warn!("Authentication of event {} failed: {:?}", next_id, e);
|
|
|
|
back_off((**next_id).to_owned());
|
|
|
|
back_off((**next_id).to_owned()).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1360,7 +1373,7 @@ impl Service {
|
|
|
|
|
|
|
|
|
|
|
|
pub_key_map
|
|
|
|
pub_key_map
|
|
|
|
.write()
|
|
|
|
.write()
|
|
|
|
.map_err(|_| Error::bad_database("RwLock is poisoned."))?
|
|
|
|
.await
|
|
|
|
.insert(signature_server.clone(), keys);
|
|
|
|
.insert(signature_server.clone(), keys);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1369,7 +1382,7 @@ impl Service {
|
|
|
|
|
|
|
|
|
|
|
|
// Gets a list of servers for which we don't have the signing key yet. We go over
|
|
|
|
// Gets a list of servers for which we don't have the signing key yet. We go over
|
|
|
|
// the PDUs and either cache the key or add it to the list that needs to be retrieved.
|
|
|
|
// the PDUs and either cache the key or add it to the list that needs to be retrieved.
|
|
|
|
fn get_server_keys_from_cache(
|
|
|
|
async fn get_server_keys_from_cache(
|
|
|
|
&self,
|
|
|
|
&self,
|
|
|
|
pdu: &RawJsonValue,
|
|
|
|
pdu: &RawJsonValue,
|
|
|
|
servers: &mut BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>>,
|
|
|
|
servers: &mut BTreeMap<OwnedServerName, BTreeMap<OwnedServerSigningKeyId, QueryCriteria>>,
|
|
|
@ -1393,7 +1406,7 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.bad_event_ratelimiter
|
|
|
|
.read()
|
|
|
|
.read()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.get(event_id)
|
|
|
|
.get(event_id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Exponential backoff
|
|
|
|
// Exponential backoff
|
|
|
@ -1469,17 +1482,19 @@ impl Service {
|
|
|
|
> = BTreeMap::new();
|
|
|
|
> = BTreeMap::new();
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let mut pkm = pub_key_map
|
|
|
|
let mut pkm = pub_key_map.write().await;
|
|
|
|
.write()
|
|
|
|
|
|
|
|
.map_err(|_| Error::bad_database("RwLock is poisoned."))?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Try to fetch keys, failure is okay
|
|
|
|
// Try to fetch keys, failure is okay
|
|
|
|
// Servers we couldn't find in the cache will be added to `servers`
|
|
|
|
// Servers we couldn't find in the cache will be added to `servers`
|
|
|
|
for pdu in &event.room_state.state {
|
|
|
|
for pdu in &event.room_state.state {
|
|
|
|
let _ = self.get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm);
|
|
|
|
let _ = self
|
|
|
|
|
|
|
|
.get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm)
|
|
|
|
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for pdu in &event.room_state.auth_chain {
|
|
|
|
for pdu in &event.room_state.auth_chain {
|
|
|
|
let _ = self.get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm);
|
|
|
|
let _ = self
|
|
|
|
|
|
|
|
.get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm)
|
|
|
|
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drop(pkm);
|
|
|
|
drop(pkm);
|
|
|
@ -1503,9 +1518,7 @@ impl Service {
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
{
|
|
|
|
{
|
|
|
|
trace!("Got signing keys: {:?}", keys);
|
|
|
|
trace!("Got signing keys: {:?}", keys);
|
|
|
|
let mut pkm = pub_key_map
|
|
|
|
let mut pkm = pub_key_map.write().await;
|
|
|
|
.write()
|
|
|
|
|
|
|
|
.map_err(|_| Error::bad_database("RwLock is poisoned."))?;
|
|
|
|
|
|
|
|
for k in keys.server_keys {
|
|
|
|
for k in keys.server_keys {
|
|
|
|
let k = match k.deserialize() {
|
|
|
|
let k = match k.deserialize() {
|
|
|
|
Ok(key) => key,
|
|
|
|
Ok(key) => key,
|
|
|
@ -1564,10 +1577,7 @@ impl Service {
|
|
|
|
.into_iter()
|
|
|
|
.into_iter()
|
|
|
|
.map(|(k, v)| (k.to_string(), v.key))
|
|
|
|
.map(|(k, v)| (k.to_string(), v.key))
|
|
|
|
.collect();
|
|
|
|
.collect();
|
|
|
|
pub_key_map
|
|
|
|
pub_key_map.write().await.insert(origin.to_string(), result);
|
|
|
|
.write()
|
|
|
|
|
|
|
|
.map_err(|_| Error::bad_database("RwLock is poisoned."))?
|
|
|
|
|
|
|
|
.insert(origin.to_string(), result);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
info!("Done handling result");
|
|
|
|
info!("Done handling result");
|
|
|
@ -1632,14 +1642,14 @@ impl Service {
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.servername_ratelimiter
|
|
|
|
.servername_ratelimiter
|
|
|
|
.read()
|
|
|
|
.read()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.get(origin)
|
|
|
|
.get(origin)
|
|
|
|
.map(|s| Arc::clone(s).acquire_owned());
|
|
|
|
.map(|s| Arc::clone(s).acquire_owned());
|
|
|
|
|
|
|
|
|
|
|
|
let permit = match permit {
|
|
|
|
let permit = match permit {
|
|
|
|
Some(p) => p,
|
|
|
|
Some(p) => p,
|
|
|
|
None => {
|
|
|
|
None => {
|
|
|
|
let mut write = services().globals.servername_ratelimiter.write().unwrap();
|
|
|
|
let mut write = services().globals.servername_ratelimiter.write().await;
|
|
|
|
let s = Arc::clone(
|
|
|
|
let s = Arc::clone(
|
|
|
|
write
|
|
|
|
write
|
|
|
|
.entry(origin.to_owned())
|
|
|
|
.entry(origin.to_owned())
|
|
|
@ -1651,24 +1661,26 @@ impl Service {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.await;
|
|
|
|
.await;
|
|
|
|
|
|
|
|
|
|
|
|
let back_off = |id| match services()
|
|
|
|
let back_off = |id| async {
|
|
|
|
|
|
|
|
match services()
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.bad_signature_ratelimiter
|
|
|
|
.bad_signature_ratelimiter
|
|
|
|
.write()
|
|
|
|
.write()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.entry(id)
|
|
|
|
.entry(id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
hash_map::Entry::Vacant(e) => {
|
|
|
|
hash_map::Entry::Vacant(e) => {
|
|
|
|
e.insert((Instant::now(), 1));
|
|
|
|
e.insert((Instant::now(), 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hash_map::Entry::Occupied(mut e) => *e.get_mut() = (Instant::now(), e.get().1 + 1),
|
|
|
|
hash_map::Entry::Occupied(mut e) => *e.get_mut() = (Instant::now(), e.get().1 + 1),
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if let Some((time, tries)) = services()
|
|
|
|
if let Some((time, tries)) = services()
|
|
|
|
.globals
|
|
|
|
.globals
|
|
|
|
.bad_signature_ratelimiter
|
|
|
|
.bad_signature_ratelimiter
|
|
|
|
.read()
|
|
|
|
.read()
|
|
|
|
.unwrap()
|
|
|
|
.await
|
|
|
|
.get(&signature_ids)
|
|
|
|
.get(&signature_ids)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Exponential backoff
|
|
|
|
// Exponential backoff
|
|
|
@ -1775,7 +1787,7 @@ impl Service {
|
|
|
|
|
|
|
|
|
|
|
|
drop(permit);
|
|
|
|
drop(permit);
|
|
|
|
|
|
|
|
|
|
|
|
back_off(signature_ids);
|
|
|
|
back_off(signature_ids).await;
|
|
|
|
|
|
|
|
|
|
|
|
warn!("Failed to find public key for server: {}", origin);
|
|
|
|
warn!("Failed to find public key for server: {}", origin);
|
|
|
|
Err(Error::BadServerResponse(
|
|
|
|
Err(Error::BadServerResponse(
|
|
|
|