mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-24 09:27:38 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dee936813c | ||
|
|
2cf0923386 | ||
|
|
26483e17ad |
No files matched your search
@@ -586,10 +586,13 @@
|
|||||||
#allow_unstable_room_versions = true
|
#allow_unstable_room_versions = true
|
||||||
|
|
||||||
# Default room version continuwuity will create rooms with.
|
# Default room version continuwuity will create rooms with.
|
||||||
|
# Note that this has to be a string since the room version is a string
|
||||||
|
# rather than an integer. Forgetting the quotes will make the server fail
|
||||||
|
# to start!
|
||||||
#
|
#
|
||||||
# Per spec, room version 11 is the default.
|
# Per spec, room version "11" is the default.
|
||||||
#
|
#
|
||||||
#default_room_version = 11
|
#default_room_version = "11"
|
||||||
|
|
||||||
# Enable OpenTelemetry OTLP tracing export. This replaces the deprecated
|
# Enable OpenTelemetry OTLP tracing export. This replaces the deprecated
|
||||||
# Jaeger exporter. Traces will be sent via OTLP to a collector (such as
|
# Jaeger exporter. Traces will be sent via OTLP to a collector (such as
|
||||||
|
|||||||
+118
-92
@@ -6,6 +6,69 @@
|
|||||||
pkgs,
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
baseTestScript =
|
||||||
|
pkgs.writers.writePython3Bin "do_test" { libraries = [ pkgs.python3Packages.matrix-nio ]; }
|
||||||
|
''
|
||||||
|
import asyncio
|
||||||
|
import nio
|
||||||
|
|
||||||
|
|
||||||
|
async def main() -> None:
|
||||||
|
# Connect to continuwuity
|
||||||
|
client = nio.AsyncClient("http://continuwuity:6167", "alice")
|
||||||
|
|
||||||
|
# Register as user alice
|
||||||
|
response = await client.register("alice", "my-secret-password")
|
||||||
|
|
||||||
|
# Log in as user alice
|
||||||
|
response = await client.login("my-secret-password")
|
||||||
|
|
||||||
|
# Create a new room
|
||||||
|
response = await client.room_create(federate=False)
|
||||||
|
print("Matrix room create response:", response)
|
||||||
|
assert isinstance(response, nio.RoomCreateResponse)
|
||||||
|
room_id = response.room_id
|
||||||
|
|
||||||
|
# Join the room
|
||||||
|
response = await client.join(room_id)
|
||||||
|
print("Matrix join response:", response)
|
||||||
|
assert isinstance(response, nio.JoinResponse)
|
||||||
|
|
||||||
|
# Send a message to the room
|
||||||
|
response = await client.room_send(
|
||||||
|
room_id=room_id,
|
||||||
|
message_type="m.room.message",
|
||||||
|
content={
|
||||||
|
"msgtype": "m.text",
|
||||||
|
"body": "Hello continuwuity!"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
print("Matrix room send response:", response)
|
||||||
|
assert isinstance(response, nio.RoomSendResponse)
|
||||||
|
|
||||||
|
# Sync responses
|
||||||
|
response = await client.sync(timeout=30000)
|
||||||
|
print("Matrix sync response:", response)
|
||||||
|
assert isinstance(response, nio.SyncResponse)
|
||||||
|
|
||||||
|
# Check the message was received by continuwuity
|
||||||
|
last_message = response.rooms.join[room_id].timeline.events[-1].body
|
||||||
|
assert last_message == "Hello continuwuity!"
|
||||||
|
|
||||||
|
# Leave the room
|
||||||
|
response = await client.room_leave(room_id)
|
||||||
|
print("Matrix room leave response:", response)
|
||||||
|
assert isinstance(response, nio.RoomLeaveResponse)
|
||||||
|
|
||||||
|
# Close the client
|
||||||
|
await client.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(main())
|
||||||
|
'';
|
||||||
|
in
|
||||||
{
|
{
|
||||||
# run some nixos tests as checks
|
# run some nixos tests as checks
|
||||||
checks = lib.pipe self'.packages [
|
checks = lib.pipe self'.packages [
|
||||||
@@ -18,106 +81,69 @@
|
|||||||
# this test was initially yoinked from
|
# this test was initially yoinked from
|
||||||
#
|
#
|
||||||
# https://github.com/NixOS/nixpkgs/blob/960ce26339661b1b69c6f12b9063ca51b688615f/nixos/tests/matrix/continuwuity.nix
|
# https://github.com/NixOS/nixpkgs/blob/960ce26339661b1b69c6f12b9063ca51b688615f/nixos/tests/matrix/continuwuity.nix
|
||||||
(builtins.map (name: {
|
(builtins.concatMap (
|
||||||
name = "test-${name}";
|
name:
|
||||||
value = pkgs.testers.runNixOSTest {
|
builtins.map
|
||||||
inherit name;
|
(
|
||||||
|
{ config, suffix }:
|
||||||
|
{
|
||||||
|
name = "test-${name}-${suffix}";
|
||||||
|
value = pkgs.testers.runNixOSTest {
|
||||||
|
inherit name;
|
||||||
|
|
||||||
nodes = {
|
nodes = {
|
||||||
continuwuity = {
|
continuwuity = {
|
||||||
services.matrix-continuwuity = {
|
services.matrix-continuwuity = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = self'.packages.${name};
|
package = self'.packages.${name};
|
||||||
settings.global = {
|
settings = config;
|
||||||
|
extraEnvironment.RUST_BACKTRACE = "yes";
|
||||||
|
};
|
||||||
|
networking.firewall.allowedTCPPorts = [ 6167 ];
|
||||||
|
};
|
||||||
|
client.environment.systemPackages = [ baseTestScript ];
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = ''
|
||||||
|
start_all()
|
||||||
|
|
||||||
|
with subtest("start continuwuity"):
|
||||||
|
continuwuity.wait_for_unit("continuwuity.service")
|
||||||
|
continuwuity.wait_for_open_port(6167)
|
||||||
|
|
||||||
|
with subtest("ensure messages can be exchanged"):
|
||||||
|
client.succeed("${lib.getExe baseTestScript} >&2")
|
||||||
|
'';
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
[
|
||||||
|
{
|
||||||
|
suffix = "base";
|
||||||
|
config = {
|
||||||
|
global = {
|
||||||
server_name = name;
|
server_name = name;
|
||||||
address = [ "0.0.0.0" ];
|
address = [ "0.0.0.0" ];
|
||||||
allow_registration = true;
|
allow_registration = true;
|
||||||
yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true;
|
yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true;
|
||||||
};
|
};
|
||||||
extraEnvironment.RUST_BACKTRACE = "yes";
|
|
||||||
};
|
};
|
||||||
networking.firewall.allowedTCPPorts = [ 6167 ];
|
}
|
||||||
};
|
{
|
||||||
client =
|
suffix = "with-room-version";
|
||||||
{ pkgs, ... }:
|
config = {
|
||||||
{
|
global = {
|
||||||
environment.systemPackages = [
|
server_name = name;
|
||||||
(pkgs.writers.writePython3Bin "do_test" { libraries = [ pkgs.python3Packages.matrix-nio ]; } ''
|
address = [ "0.0.0.0" ];
|
||||||
import asyncio
|
allow_registration = true;
|
||||||
import nio
|
yes_i_am_very_very_sure_i_want_an_open_registration_server_prone_to_abuse = true;
|
||||||
|
default_room_version = "12";
|
||||||
|
};
|
||||||
async def main() -> None:
|
|
||||||
# Connect to continuwuity
|
|
||||||
client = nio.AsyncClient("http://continuwuity:6167", "alice")
|
|
||||||
|
|
||||||
# Register as user alice
|
|
||||||
response = await client.register("alice", "my-secret-password")
|
|
||||||
|
|
||||||
# Log in as user alice
|
|
||||||
response = await client.login("my-secret-password")
|
|
||||||
|
|
||||||
# Create a new room
|
|
||||||
response = await client.room_create(federate=False)
|
|
||||||
print("Matrix room create response:", response)
|
|
||||||
assert isinstance(response, nio.RoomCreateResponse)
|
|
||||||
room_id = response.room_id
|
|
||||||
|
|
||||||
# Join the room
|
|
||||||
response = await client.join(room_id)
|
|
||||||
print("Matrix join response:", response)
|
|
||||||
assert isinstance(response, nio.JoinResponse)
|
|
||||||
|
|
||||||
# Send a message to the room
|
|
||||||
response = await client.room_send(
|
|
||||||
room_id=room_id,
|
|
||||||
message_type="m.room.message",
|
|
||||||
content={
|
|
||||||
"msgtype": "m.text",
|
|
||||||
"body": "Hello continuwuity!"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
print("Matrix room send response:", response)
|
|
||||||
assert isinstance(response, nio.RoomSendResponse)
|
|
||||||
|
|
||||||
# Sync responses
|
|
||||||
response = await client.sync(timeout=30000)
|
|
||||||
print("Matrix sync response:", response)
|
|
||||||
assert isinstance(response, nio.SyncResponse)
|
|
||||||
|
|
||||||
# Check the message was received by continuwuity
|
|
||||||
last_message = response.rooms.join[room_id].timeline.events[-1].body
|
|
||||||
assert last_message == "Hello continuwuity!"
|
|
||||||
|
|
||||||
# Leave the room
|
|
||||||
response = await client.room_leave(room_id)
|
|
||||||
print("Matrix room leave response:", response)
|
|
||||||
assert isinstance(response, nio.RoomLeaveResponse)
|
|
||||||
|
|
||||||
# Close the client
|
|
||||||
await client.close()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
asyncio.run(main())
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
]
|
||||||
testScript = ''
|
))
|
||||||
start_all()
|
|
||||||
|
|
||||||
with subtest("start continuwuity"):
|
|
||||||
continuwuity.wait_for_unit("continuwuity.service")
|
|
||||||
continuwuity.wait_for_open_port(6167)
|
|
||||||
|
|
||||||
with subtest("ensure messages can be exchanged"):
|
|
||||||
client.succeed("do_test >&2")
|
|
||||||
'';
|
|
||||||
|
|
||||||
};
|
|
||||||
}))
|
|
||||||
builtins.listToAttrs
|
builtins.listToAttrs
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ use service::{
|
|||||||
rooms::{
|
rooms::{
|
||||||
state::RoomMutexGuard,
|
state::RoomMutexGuard,
|
||||||
state_compressor::{CompressedState, HashSetCompressStateEvent},
|
state_compressor::{CompressedState, HashSetCompressStateEvent},
|
||||||
timeline::pdu_fits,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -574,13 +573,6 @@ async fn join_room_by_id_helper_remote(
|
|||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if !pdu_fits(&mut value.clone()) {
|
|
||||||
warn!(
|
|
||||||
"dropping incoming PDU {event_id} in room {room_id} from room join because \
|
|
||||||
it exceeds 65535 bytes or is otherwise too large."
|
|
||||||
);
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
services.rooms.outlier.add_pdu_outlier(&event_id, &value);
|
services.rooms.outlier.add_pdu_outlier(&event_id, &value);
|
||||||
if let Some(state_key) = &pdu.state_key {
|
if let Some(state_key) = &pdu.state_key {
|
||||||
let shortstatekey = services
|
let shortstatekey = services
|
||||||
|
|||||||
@@ -703,10 +703,13 @@ pub struct Config {
|
|||||||
pub allow_unstable_room_versions: bool,
|
pub allow_unstable_room_versions: bool,
|
||||||
|
|
||||||
/// Default room version continuwuity will create rooms with.
|
/// Default room version continuwuity will create rooms with.
|
||||||
|
/// Note that this has to be a string since the room version is a string
|
||||||
|
/// rather than an integer. Forgetting the quotes will make the server fail
|
||||||
|
/// to start!
|
||||||
///
|
///
|
||||||
/// Per spec, room version 11 is the default.
|
/// Per spec, room version "11" is the default.
|
||||||
///
|
///
|
||||||
/// default: 11
|
/// default: "11"
|
||||||
#[serde(default = "default_default_room_version")]
|
#[serde(default = "default_default_room_version")]
|
||||||
pub default_room_version: RoomVersionId,
|
pub default_room_version: RoomVersionId,
|
||||||
|
|
||||||
|
|||||||
@@ -177,6 +177,11 @@ where
|
|||||||
|
|
||||||
// [synapse] do_sig_check check the event has valid signatures for member events
|
// [synapse] do_sig_check check the event has valid signatures for member events
|
||||||
|
|
||||||
|
// TODO do_size_check is false when called by `iterative_auth_check`
|
||||||
|
// do_size_check is also mostly accomplished by ruma with the exception of
|
||||||
|
// checking event_type, state_key, and json are below a certain size (255 and
|
||||||
|
// 65_536 respectively)
|
||||||
|
|
||||||
let sender = incoming_event.sender();
|
let sender = incoming_event.sender();
|
||||||
|
|
||||||
// Implementation of https://spec.matrix.org/latest/rooms/v1/#authorization-rules
|
// Implementation of https://spec.matrix.org/latest/rooms/v1/#authorization-rules
|
||||||
|
|||||||
@@ -31,13 +31,12 @@ impl crate::Service for Service {
|
|||||||
|
|
||||||
let turn_secret = config.turn_secret_file.as_ref().map_or_else(
|
let turn_secret = config.turn_secret_file.as_ref().map_or_else(
|
||||||
|| config.turn_secret.clone(),
|
|| config.turn_secret.clone(),
|
||||||
|path| match std::fs::read_to_string(path) {
|
|path| {
|
||||||
| Ok(secret) => secret.trim().to_owned(),
|
std::fs::read_to_string(path).unwrap_or_else(|e| {
|
||||||
| Err(e) => {
|
|
||||||
error!("Failed to read the TURN secret file: {e}");
|
error!("Failed to read the TURN secret file: {e}");
|
||||||
|
|
||||||
config.turn_secret.clone()
|
config.turn_secret.clone()
|
||||||
},
|
})
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -50,7 +49,7 @@ impl crate::Service for Service {
|
|||||||
return config.registration_token.clone();
|
return config.registration_token.clone();
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(token.trim().to_owned())
|
Some(token)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+16
-24
@@ -590,10 +590,6 @@ async fn fix_readreceiptid_readreceipt_duplicates(services: &Services) -> Result
|
|||||||
|
|
||||||
const FIXED_CORRUPT_MSC4133_FIELDS_MARKER: &[u8] = b"fix_corrupt_msc4133_fields";
|
const FIXED_CORRUPT_MSC4133_FIELDS_MARKER: &[u8] = b"fix_corrupt_msc4133_fields";
|
||||||
async fn fix_corrupt_msc4133_fields(services: &Services) -> Result {
|
async fn fix_corrupt_msc4133_fields(services: &Services) -> Result {
|
||||||
// Due to an old bug, some conduwuit databases have `us.cloke.msc4175.tz` user
|
|
||||||
// profile fields with raw strings instead of quoted JSON ones.
|
|
||||||
// This migration fixes that.
|
|
||||||
|
|
||||||
use serde_json::{Value, from_slice};
|
use serde_json::{Value, from_slice};
|
||||||
type KeyVal<'a> = ((OwnedUserId, String), &'a [u8]);
|
type KeyVal<'a> = ((OwnedUserId, String), &'a [u8]);
|
||||||
|
|
||||||
@@ -610,28 +606,24 @@ async fn fix_corrupt_msc4133_fields(services: &Services) -> Result {
|
|||||||
async |(mut total, mut fixed),
|
async |(mut total, mut fixed),
|
||||||
((user, key), value): KeyVal<'_>|
|
((user, key), value): KeyVal<'_>|
|
||||||
-> Result<(usize, usize)> {
|
-> Result<(usize, usize)> {
|
||||||
match from_slice::<Value>(value) {
|
if let Err(error) = from_slice::<Value>(value) {
|
||||||
// corrupted timezone field
|
// Due to an old bug, some conduwuit databases have `us.cloke.msc4175.tz` user
|
||||||
| Err(_) if key == "us.cloke.msc4175.tz" => {
|
// profile fields with raw strings instead of quoted JSON ones.
|
||||||
let new_value = Value::String(String::from_utf8(value.to_vec())?);
|
// This migration fixes that.
|
||||||
useridprofilekey_value.put((user, key), Json(new_value));
|
let new_value = if key == "us.cloke.msc4175.tz" {
|
||||||
fixed = fixed.saturating_add(1);
|
Value::String(String::from_utf8(value.to_vec())?)
|
||||||
},
|
} else {
|
||||||
// corrupted value for some other key
|
return Err!(
|
||||||
| Err(error) => {
|
"failed to deserialize msc4133 key {} of user {}: {}",
|
||||||
warn!(
|
key,
|
||||||
"deleting MSC4133 key {} for user {} due to deserialization \
|
user,
|
||||||
failure: {}",
|
error
|
||||||
key, user, error
|
|
||||||
);
|
);
|
||||||
useridprofilekey_value.del((user, key));
|
};
|
||||||
},
|
|
||||||
// other key with no issues
|
|
||||||
| Ok(_) => {
|
|
||||||
// do nothing
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
useridprofilekey_value.put((user, key), Json(new_value));
|
||||||
|
fixed = fixed.saturating_add(1);
|
||||||
|
}
|
||||||
total = total.saturating_add(1);
|
total = total.saturating_add(1);
|
||||||
|
|
||||||
Ok((total, fixed))
|
Ok((total, fixed))
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use futures::{
|
|||||||
use ruma::{CanonicalJsonValue, EventId, RoomId, ServerName, UserId, events::StateEventType};
|
use ruma::{CanonicalJsonValue, EventId, RoomId, ServerName, UserId, events::StateEventType};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::rooms::timeline::{RawPduId, pdu_fits};
|
use crate::rooms::timeline::RawPduId;
|
||||||
|
|
||||||
/// When receiving an event one needs to:
|
/// When receiving an event one needs to:
|
||||||
/// 0. Check the server is in the room
|
/// 0. Check the server is in the room
|
||||||
@@ -62,13 +62,6 @@ pub async fn handle_incoming_pdu<'a>(
|
|||||||
if let Ok(pdu_id) = self.services.timeline.get_pdu_id(event_id).await {
|
if let Ok(pdu_id) = self.services.timeline.get_pdu_id(event_id).await {
|
||||||
return Ok(Some(pdu_id));
|
return Ok(Some(pdu_id));
|
||||||
}
|
}
|
||||||
if !pdu_fits(&mut value.clone()) {
|
|
||||||
warn!(
|
|
||||||
"dropping incoming PDU {event_id} in room {room_id} from {origin} because it \
|
|
||||||
exceeds 65535 bytes or is otherwise too large."
|
|
||||||
);
|
|
||||||
return Err!(Request(TooLarge("PDU is too large")));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1.1 Check the server is in the room
|
// 1.1 Check the server is in the room
|
||||||
let meta_exists = self.services.metadata.exists(room_id).map(Ok);
|
let meta_exists = self.services.metadata.exists(room_id).map(Ok);
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
use std::collections::{BTreeMap, HashMap, hash_map};
|
use std::collections::{BTreeMap, HashMap, hash_map};
|
||||||
|
|
||||||
use conduwuit::{
|
use conduwuit::{
|
||||||
Err, Event, PduEvent, Result, debug, debug_info, debug_warn, err, implement, state_res,
|
Err, Event, PduEvent, Result, debug, debug_info, debug_warn, err, implement, state_res, trace,
|
||||||
trace, warn,
|
|
||||||
};
|
};
|
||||||
use futures::future::ready;
|
use futures::future::ready;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
@@ -11,7 +10,6 @@ use ruma::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{check_room_id, get_room_version_id, to_room_version};
|
use super::{check_room_id, get_room_version_id, to_room_version};
|
||||||
use crate::rooms::timeline::pdu_fits;
|
|
||||||
|
|
||||||
#[implement(super::Service)]
|
#[implement(super::Service)]
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
@@ -27,13 +25,6 @@ pub(super) async fn handle_outlier_pdu<'a, Pdu>(
|
|||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event + Send + Sync,
|
||||||
{
|
{
|
||||||
if !pdu_fits(&mut value.clone()) {
|
|
||||||
warn!(
|
|
||||||
"dropping incoming PDU {event_id} in room {room_id} from {origin} because it \
|
|
||||||
exceeds 65535 bytes or is otherwise too large."
|
|
||||||
);
|
|
||||||
return Err!(Request(TooLarge("PDU is too large")));
|
|
||||||
}
|
|
||||||
// 1. Remove unsigned field
|
// 1. Remove unsigned field
|
||||||
value.remove("unsigned");
|
value.remove("unsigned");
|
||||||
|
|
||||||
|
|||||||
@@ -23,40 +23,6 @@ use serde_json::value::{RawValue, to_raw_value};
|
|||||||
|
|
||||||
use super::RoomMutexGuard;
|
use super::RoomMutexGuard;
|
||||||
|
|
||||||
pub fn pdu_fits(owned_obj: &mut CanonicalJsonObject) -> bool {
|
|
||||||
// room IDs, event IDs, senders, types, and state keys must all be <= 255 bytes
|
|
||||||
if let Some(CanonicalJsonValue::String(room_id)) = owned_obj.get("room_id") {
|
|
||||||
if room_id.len() > 255 {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(CanonicalJsonValue::String(event_id)) = owned_obj.get("event_id") {
|
|
||||||
if event_id.len() > 255 {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(CanonicalJsonValue::String(sender)) = owned_obj.get("sender") {
|
|
||||||
if sender.len() > 255 {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(CanonicalJsonValue::String(kind)) = owned_obj.get("type") {
|
|
||||||
if kind.len() > 255 {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(CanonicalJsonValue::String(state_key)) = owned_obj.get("state_key") {
|
|
||||||
if state_key.len() > 255 {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Now check the full PDU size
|
|
||||||
match serde_json::to_string(owned_obj) {
|
|
||||||
| Ok(s) => s.len() <= 65535,
|
|
||||||
| Err(_) => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[implement(super::Service)]
|
#[implement(super::Service)]
|
||||||
pub async fn create_hash_and_sign_event(
|
pub async fn create_hash_and_sign_event(
|
||||||
&self,
|
&self,
|
||||||
@@ -182,6 +148,19 @@ pub async fn create_hash_and_sign_event(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if event_type != TimelineEventType::RoomCreate && prev_events.is_empty() {
|
||||||
|
// return Err!(Request(Unknown("Event incorrectly had zero prev_events.")));
|
||||||
|
// }
|
||||||
|
// if state_key.is_none() && depth.lt(&uint!(2)) {
|
||||||
|
// // The first two events in a room are always m.room.create and
|
||||||
|
// m.room.member, // so any other events with that same depth are illegal.
|
||||||
|
// warn!(
|
||||||
|
// "Had unsafe depth {depth} when creating non-state event in {}. Cowardly
|
||||||
|
// aborting", room_id.expect("room_id is Some here").as_str()
|
||||||
|
// );
|
||||||
|
// return Err!(Request(Unknown("Unsafe depth for non-state event.")));
|
||||||
|
// }
|
||||||
|
|
||||||
let mut pdu = PduEvent {
|
let mut pdu = PduEvent {
|
||||||
event_id: ruma::event_id!("$thiswillbefilledinlater").into(),
|
event_id: ruma::event_id!("$thiswillbefilledinlater").into(),
|
||||||
room_id: room_id.map(ToOwned::to_owned),
|
room_id: room_id.map(ToOwned::to_owned),
|
||||||
@@ -290,16 +269,8 @@ pub async fn create_hash_and_sign_event(
|
|||||||
}
|
}
|
||||||
// Generate event id
|
// Generate event id
|
||||||
pdu.event_id = gen_event_id(&pdu_json, &room_version_id)?;
|
pdu.event_id = gen_event_id(&pdu_json, &room_version_id)?;
|
||||||
pdu_json.insert("event_id".into(), CanonicalJsonValue::String(pdu.event_id.clone().into()));
|
|
||||||
// Verify that the *full* PDU isn't over 64KiB.
|
|
||||||
// Ruma only validates that it's under 64KiB before signing and hashing.
|
|
||||||
// Has to be cloned to prevent mutating pdu_json itself :(
|
|
||||||
if !pdu_fits(&mut pdu_json.clone()) {
|
|
||||||
// feckin huge PDU mate
|
|
||||||
return Err!(Request(TooLarge("Message/PDU is too long (exceeds 65535 bytes)")));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check with the policy server
|
// Check with the policy server
|
||||||
|
pdu_json.insert("event_id".into(), CanonicalJsonValue::String(pdu.event_id.clone().into()));
|
||||||
if room_id.is_some() {
|
if room_id.is_some() {
|
||||||
trace!(
|
trace!(
|
||||||
"Checking event in room {} with policy server",
|
"Checking event in room {} with policy server",
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ use ruma::{
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use self::data::Data;
|
use self::data::Data;
|
||||||
pub use self::{create::pdu_fits, data::PdusIterItem};
|
pub use self::data::PdusIterItem;
|
||||||
use crate::{
|
use crate::{
|
||||||
Dep, account_data, admin, appservice, globals, pusher, rooms, sending, server_keys, users,
|
Dep, account_data, admin, appservice, globals, pusher, rooms, sending, server_keys, users,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user