All outgoing pdus in Sending must be PduStubs
This commit is contained in:
parent
c9a6ce54cb
commit
dcd1163806
2 changed files with 31 additions and 30 deletions
|
@ -73,7 +73,7 @@ impl Sending {
|
||||||
loop {
|
loop {
|
||||||
select! {
|
select! {
|
||||||
Some(server) = futures.next() => {
|
Some(server) = futures.next() => {
|
||||||
debug!("response: {:?}", &server);
|
debug!("sending response: {:?}", &server);
|
||||||
match server {
|
match server {
|
||||||
Ok((server, _response)) => {
|
Ok((server, _response)) => {
|
||||||
let mut prefix = server.as_bytes().to_vec();
|
let mut prefix = server.as_bytes().to_vec();
|
||||||
|
@ -184,17 +184,29 @@ impl Sending {
|
||||||
let pdu_jsons = pdu_ids
|
let pdu_jsons = pdu_ids
|
||||||
.iter()
|
.iter()
|
||||||
.map(|pdu_id| {
|
.map(|pdu_id| {
|
||||||
Ok::<_, (Box<ServerName>, Error)>(PduEvent::convert_to_outgoing_federation_event(
|
Ok::<_, (Box<ServerName>, Error)>(
|
||||||
rooms
|
// TODO: this was a PduStub
|
||||||
.get_pdu_json_from_id(pdu_id)
|
// In order for sending to work these actually do have to be
|
||||||
.map_err(|e| (server.clone(), e))?
|
// PduStub but, since they are Raw<..> we can fake it.
|
||||||
.ok_or_else(|| {
|
serde_json::from_str(
|
||||||
(
|
PduEvent::convert_to_outgoing_federation_event(
|
||||||
server.clone(),
|
rooms
|
||||||
Error::bad_database("Event in servernamepduids not found in db."),
|
.get_pdu_json_from_id(pdu_id)
|
||||||
)
|
.map_err(|e| (server.clone(), e))?
|
||||||
})?,
|
.ok_or_else(|| {
|
||||||
))
|
(
|
||||||
|
server.clone(),
|
||||||
|
Error::bad_database(
|
||||||
|
"Event in servernamepduids not found in db.",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})?,
|
||||||
|
)
|
||||||
|
.json()
|
||||||
|
.get(),
|
||||||
|
)
|
||||||
|
.expect("Raw<..> is always valid"),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
|
@ -20,7 +20,7 @@ use ruma::{
|
||||||
OutgoingRequest,
|
OutgoingRequest,
|
||||||
},
|
},
|
||||||
directory::{IncomingFilter, IncomingRoomNetwork},
|
directory::{IncomingFilter, IncomingRoomNetwork},
|
||||||
EventId, RoomVersionId, ServerName,
|
EventId, RoomId, RoomVersionId, ServerName, UserId,
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
|
@ -412,19 +412,10 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
"m.receipt" => {}
|
"m.receipt" => {}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
Err(_err) => {
|
Err(_err) => continue,
|
||||||
log::error!("{}", _err);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: For RoomVersion6 we must check that Raw<..> is canonical do we?
|
|
||||||
// SPEC:
|
|
||||||
// Servers MUST strictly enforce the JSON format specified in the appendices.
|
|
||||||
// This translates to a 400 M_BAD_JSON error on most endpoints, or discarding of
|
|
||||||
// events over federation. For example, the Federation API's /send endpoint would
|
|
||||||
// discard the event whereas the Client Server API's /send/{eventType} endpoint
|
|
||||||
// would return a M_BAD_JSON error.
|
|
||||||
let mut resolved_map = BTreeMap::new();
|
let mut resolved_map = BTreeMap::new();
|
||||||
for pdu in &body.pdus {
|
for pdu in &body.pdus {
|
||||||
println!("LOOP");
|
println!("LOOP");
|
||||||
|
@ -437,16 +428,14 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
if !db.rooms.is_joined(&pdu.sender, &pdu.room_id)? {
|
if !db.rooms.is_joined(&pdu.sender, &pdu.room_id)? {
|
||||||
// TODO: auth rules apply to all events, not only those with a state key
|
// TODO: auth rules apply to all events, not only those with a state key
|
||||||
log::error!("Unauthorized {}", pdu.kind);
|
log::error!("Unauthorized {}", pdu.kind);
|
||||||
return Err(Error::BadRequest(
|
|
||||||
ruma::api::client::error::ErrorKind::Forbidden,
|
resolved_map.insert(event_id, Err("User is not in this room".into()));
|
||||||
"Event is not authorized",
|
continue;
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: We should be doing the same get_closest_parent thing here too?
|
// TODO: We should be doing the same get_closest_parent thing here too?
|
||||||
// same as for state events ~100 lines down
|
// same as for state events ~100 lines down
|
||||||
let count = db.globals.next_count()?;
|
let count = db.globals.next_count()?;
|
||||||
|
|
||||||
let mut pdu_id = pdu.room_id.as_bytes().to_vec();
|
let mut pdu_id = pdu.room_id.as_bytes().to_vec();
|
||||||
pdu_id.push(0xff);
|
pdu_id.push(0xff);
|
||||||
pdu_id.extend_from_slice(&count.to_be_bytes());
|
pdu_id.extend_from_slice(&count.to_be_bytes());
|
||||||
|
@ -677,7 +666,7 @@ pub async fn send_transaction_message_route<'a>(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(send_transaction_message::v1::Response { pdus: resolved_map }.into())
|
Ok(dbg!(send_transaction_message::v1::Response { pdus: resolved_map }).into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
|
|
Loading…
Add table
Reference in a new issue