fix: multiple federation/pusher fixes

This commit is contained in:
Timo Kösters 2021-03-16 18:00:26 +01:00
parent 21f785d530
commit 44425a903a
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
7 changed files with 85 additions and 167 deletions

View file

@ -35,8 +35,6 @@ impl PushData {
}
pub fn set_pusher(&self, sender: &UserId, pusher: Pusher) -> Result<()> {
println!("CCCCCCCCCCCCCCCCCCCCCc");
dbg!(&pusher);
let mut key = sender.as_bytes().to_vec();
key.push(0xff);
key.extend_from_slice(pusher.pushkey.as_bytes());
@ -51,7 +49,7 @@ impl PushData {
}
self.senderkey_pusher.insert(
dbg!(key),
key,
&*serde_json::to_string(&pusher).expect("Pusher is valid JSON string"),
)?;
@ -63,12 +61,10 @@ impl PushData {
prefix.push(0xff);
self.senderkey_pusher
.scan_prefix(dbg!(prefix))
.scan_prefix(prefix)
.values()
.map(|push| {
println!("DDDDDDDDDDDDDDDDDDDDDDDDDD");
let push =
dbg!(push).map_err(|_| Error::bad_database("Invalid push bytes in db."))?;
let push = push.map_err(|_| Error::bad_database("Invalid push bytes in db."))?;
Ok(serde_json::from_slice(&*push)
.map_err(|_| Error::bad_database("Invalid Pusher in db."))?)
})
@ -100,10 +96,7 @@ where
//*reqwest_request.timeout_mut() = Some(Duration::from_secs(5));
let url = reqwest_request.url().clone();
let reqwest_response = globals
.reqwest_client()
.execute(dbg!(reqwest_request))
.await;
let reqwest_response = globals.reqwest_client().execute(reqwest_request).await;
// Because reqwest::Response -> http::Response is complicated:
match reqwest_response {
@ -182,7 +175,7 @@ pub async fn send_push_notice(
continue;
}
match dbg!(rule.rule_id.as_str()) {
match rule.rule_id.as_str() {
".m.rule.master" => {}
".m.rule.suppress_notices" => {
if pdu.kind == EventType::RoomMessage
@ -454,8 +447,7 @@ async fn send_notice(
db: &Database,
name: &str,
) -> Result<()> {
println!("BBBBBBBBBBBBBBBr");
let (http, _emails): (Vec<&Pusher>, _) = dbg!(pushers)
let (http, _emails): (Vec<&Pusher>, _) = pushers
.iter()
.partition(|pusher| pusher.kind == Some(PusherKind::Http));
@ -463,7 +455,7 @@ async fn send_notice(
// Two problems with this
// 1. if "event_id_only" is the only format kind it seems we should never add more info
// 2. can pusher/devices have conflicting formats
for pusher in dbg!(http) {
for pusher in http {
let event_id_only = pusher.data.format == Some(PushFormat::EventIdOnly);
let url = if let Some(url) = pusher.data.url.as_ref() {
url

View file

@ -3,7 +3,7 @@ mod edus;
pub use edus::RoomEdus;
use crate::{pdu::PduBuilder, utils, Database, Error, PduEvent, Result};
use log::{error, info, warn};
use log::{debug, error, info, warn};
use regex::Regex;
use ring::digest;
use ruma::{
@ -67,7 +67,7 @@ pub struct Rooms {
/// StateKey = EventType + StateKey, Short = Count
pub(super) statekey_short: sled::Tree,
/// StateId = StateHash + Short, PduId = Count (without roomid)
pub(super) stateid_pduid: sled::Tree,
pub(super) stateid_eventid: sled::Tree,
/// RoomId + EventId -> outlier PDU.
/// Any pdu that has passed the steps 1-8 in the incoming event /federation/send/txn.
@ -138,7 +138,7 @@ impl Rooms {
key.push(0xff);
key.extend_from_slice(&state_key.as_bytes());
info!("Looking for {} {:?}", event_type, state_key);
debug!("Looking for {} {:?}", event_type, state_key);
let short = self.statekey_short.get(&key)?;
@ -147,11 +147,11 @@ impl Rooms {
stateid.push(0xff);
stateid.extend_from_slice(&short);
info!("trying to find pduid/eventid. short: {:?}", stateid);
debug!("trying to find pduid/eventid. short: {:?}", stateid);
self.stateid_pduid
.get(&stateid)?
.map_or(Ok(None), |short_id| {
info!("found in stateid_pduid");
debug!("found in stateid_pduid");
let mut long_id = room_id.as_bytes().to_vec();
long_id.push(0xff);
long_id.extend_from_slice(&short_id);
@ -163,7 +163,7 @@ impl Rooms {
.map_err(|_| Error::bad_database("Invalid PDU in db."))?,
),
None => {
info!("looking in outliers");
debug!("looking in outliers");
(
short_id.clone().into(),
self.eventid_outlierpdu
@ -180,7 +180,7 @@ impl Rooms {
}))
})
} else {
info!("short id not found");
warn!("short id not found");
Ok(None)
}
}
@ -288,7 +288,7 @@ impl Rooms {
let mut state_id = prefix.clone();
state_id.extend_from_slice(&short.to_be_bytes());
info!("inserting {:?} into {:?}", short_id, state_id);
debug!("inserting {:?} into {:?}", short_id, state_id);
self.stateid_pduid.insert(state_id, short_id)?;
}
@ -574,7 +574,7 @@ impl Rooms {
self.pduid_pdu.insert(
&pdu_id,
&*serde_json::to_string(&pdu_json)
&*serde_json::to_string(dbg!(&pdu_json))
.expect("CanonicalJsonObject is always a valid String"),
)?;
@ -889,12 +889,12 @@ impl Rooms {
content.clone(),
prev_event,
None, // TODO: third party invite
dbg!(&auth_events
&auth_events
.iter()
.map(|((ty, key), pdu)| {
Ok(((ty.clone(), key.clone()), Arc::new(pdu.clone())))
})
.collect::<Result<StateMap<_>>>()?),
.collect::<Result<StateMap<_>>>()?,
)
.map_err(|e| {
log::error!("{}", e);

View file

@ -10,7 +10,7 @@ use crate::{
appservice_server, database::pusher, server_server, utils, Database, Error, PduEvent, Result,
};
use federation::transactions::send_transaction_message;
use log::{info, warn};
use log::{debug, error, info, warn};
use ring::digest;
use rocket::futures::stream::{FuturesUnordered, StreamExt};
use ruma::{
@ -308,8 +308,6 @@ impl Sending {
key.extend_from_slice(pdu_id);
self.servernamepduids.insert(key, b"")?;
println!("AAAA");
Ok(())
}
@ -348,7 +346,7 @@ impl Sending {
pdu_ids: Vec<IVec>,
db: &Database,
) -> std::result::Result<OutgoingKind, (OutgoingKind, Error)> {
match dbg!(&kind) {
match &kind {
OutgoingKind::Appservice(server) => {
let pdu_jsons = pdu_ids
.iter()
@ -414,21 +412,23 @@ impl Sending {
.filter_map(|r| r.ok())
.collect::<Vec<_>>();
for pdu in dbg!(&pdus) {
for pdu in pdus {
// Redacted events are not notification targets (we don't send push for them)
if pdu.unsigned.get("redacted_because").is_some() {
continue;
}
for user in db.rooms.room_members(&pdu.room_id) {
let user = user.map_err(|e| (OutgoingKind::Push(id.clone()), e))?;
for user in db.users.iter().filter_map(|r| r.ok()).filter(|user_id| {
db.rooms.is_joined(&user_id, &pdu.room_id).unwrap_or(false)
}) {
// Don't notify the user of their own events
if user == pdu.sender {
continue;
}
let pushers = dbg!(db.pusher.get_pusher(&user))
let pushers = db
.pusher
.get_pusher(&user)
.map_err(|e| (OutgoingKind::Push(id.clone()), e))?;
let rules_for_user = db
@ -467,7 +467,7 @@ impl Sending {
unread,
&pushers,
rules_for_user,
pdu,
&pdu,
db,
)
.await
@ -510,7 +510,7 @@ impl Sending {
let permit = db.sending.maximum_requests.acquire().await;
info!("sending pdus to {}: {:#?}", server, pdu_jsons);
error!("sending pdus to {}: {:#?}", server, pdu_jsons);
let response = server_server::send_request(
&db.globals,
&*server,
@ -527,7 +527,7 @@ impl Sending {
)
.await
.map(|response| {
info!("server response: {:?}", response);
error!("server response: {:?}", response);
kind.clone()
})
.map_err(|e| (kind, e));