Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
🥺
conduwuit
Commits
fe3b5d32
Unverified
Commit
fe3b5d32
authored
3 years ago
by
Timo Kösters
Browse files
Options
Downloads
Patches
Plain Diff
feat: send to-device events over federation
parent
e20f5597
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/client_server/keys.rs
+15
-5
15 additions, 5 deletions
src/client_server/keys.rs
src/client_server/to_device.rs
+29
-1
29 additions, 1 deletion
src/client_server/to_device.rs
src/database/sending.rs
+25
-7
25 additions, 7 deletions
src/database/sending.rs
with
69 additions
and
13 deletions
src/client_server/keys.rs
+
15
−
5
View file @
fe3b5d32
...
...
@@ -302,6 +302,7 @@ pub async fn get_keys_helper<F: Fn(&UserId) -> bool>(
.entry
(
user_id
.server_name
())
.or_insert_with
(
Vec
::
new
)
.push
((
user_id
,
device_ids
));
continue
;
}
if
device_ids
.is_empty
()
{
...
...
@@ -364,20 +365,29 @@ pub async fn get_keys_helper<F: Fn(&UserId) -> bool>(
let
mut
failures
=
BTreeMap
::
new
();
for
(
server
,
vec
)
in
get_over_federation
{
let
mut
device_keys
=
BTreeMap
::
new
();
let
mut
device_keys
_input_fed
=
BTreeMap
::
new
();
for
(
user_id
,
keys
)
in
vec
{
device_keys
.insert
(
user_id
.clone
(),
keys
.clone
());
device_keys
_input_fed
.insert
(
user_id
.clone
(),
keys
.clone
());
}
if
let
Err
(
_e
)
=
db
match
db
.sending
.send_federation_request
(
&
db
.globals
,
server
,
federation
::
keys
::
get_keys
::
v1
::
Request
{
device_keys
},
federation
::
keys
::
get_keys
::
v1
::
Request
{
device_keys
:
device_keys_input_fed
,
},
)
.await
{
failures
.insert
(
server
.to_string
(),
json!
({}));
Ok
(
response
)
=>
{
master_keys
.extend
(
response
.master_keys
);
self_signing_keys
.extend
(
response
.self_signing_keys
);
device_keys
.extend
(
response
.device_keys
);
}
Err
(
_e
)
=>
{
failures
.insert
(
server
.to_string
(),
json!
({}));
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/client_server/to_device.rs
+
29
−
1
View file @
fe3b5d32
use
std
::
collections
::
BTreeMap
;
use
crate
::{
database
::
DatabaseGuard
,
ConduitResult
,
Error
,
Ruma
};
use
ruma
::{
api
::
client
::{
error
::
ErrorKind
,
r0
::
to_device
::
send_event_to_device
},
api
::{
client
::{
error
::
ErrorKind
,
r0
::
to_device
::
send_event_to_device
},
federation
::{
self
,
transactions
::
edu
::
DirectDeviceContent
},
},
events
::
EventType
,
to_device
::
DeviceIdOrAllDevices
,
};
...
...
@@ -33,6 +39,28 @@ pub async fn send_event_to_device_route(
for
(
target_user_id
,
map
)
in
&
body
.messages
{
for
(
target_device_id_maybe
,
event
)
in
map
{
if
target_user_id
.server_name
()
!=
db
.globals
.server_name
()
{
let
mut
map
=
BTreeMap
::
new
();
map
.insert
(
target_device_id_maybe
.clone
(),
event
.clone
());
let
mut
messages
=
BTreeMap
::
new
();
messages
.insert
(
target_user_id
.clone
(),
map
);
db
.sending
.send_reliable_edu
(
target_user_id
.server_name
(),
&
serde_json
::
to_vec
(
&
federation
::
transactions
::
edu
::
Edu
::
DirectToDevice
(
DirectDeviceContent
{
sender
:
sender_user
.clone
(),
ev_type
:
EventType
::
from
(
&
body
.event_type
),
message_id
:
body
.txn_id
.clone
(),
messages
,
},
))
.expect
(
"DirectToDevice EDU can be serialized"
),
)
?
;
continue
;
}
match
target_device_id_maybe
{
DeviceIdOrAllDevices
::
DeviceId
(
target_device_id
)
=>
db
.users
.add_to_device_event
(
sender_user
,
...
...
This diff is collapsed.
Click to expand it.
src/database/sending.rs
+
25
−
7
View file @
fe3b5d32
...
...
@@ -164,9 +164,10 @@ pub fn start_handler(
// Find events that have been added since starting the last request
let
new_events
=
guard
.sending.servernamepduids
.scan_prefix
(
prefix
.clone
())
.map
(|(
k
,
_
)|
{
Se
ndingEventType
::
Pdu
(
k
[
prefix
.len
()
..
]
.to_vec
()
)
.
filter_
map
(|(
k
,
_
)|
{
Se
lf
::
parse_servercurrentevent
(
&
k
)
.ok
()
})
.map
(|(
_
,
event
)|
event
)
.take
(
30
)
.collect
::
<
Vec
<
_
>>
();
...
...
@@ -290,7 +291,14 @@ fn select_events(
if
let
OutgoingKind
::
Normal
(
server_name
)
=
outgoing_kind
{
if
let
Ok
((
select_edus
,
last_count
))
=
Self
::
select_edus
(
db
,
server_name
)
{
events
.extend_from_slice
(
&
select_edus
);
for
edu
in
&
select_edus
{
let
mut
full_key
=
vec!
[
b'*'
];
full_key
.extend_from_slice
(
&
edu
);
db
.sending.servercurrentevents
.insert
(
&
full_key
,
&
[])
?
;
}
events
.extend
(
select_edus
.into_iter
()
.map
(
SendingEventType
::
Edu
));
db
.sending
.servername_educount
.insert
(
server_name
.as_bytes
(),
&
last_count
.to_be_bytes
())
?
;
...
...
@@ -301,7 +309,7 @@ fn select_events(
Ok
(
Some
(
events
))
}
pub
fn
select_edus
(
db
:
&
Database
,
server
:
&
ServerName
)
->
Result
<
(
Vec
<
SendingEventType
>
,
u64
)
>
{
pub
fn
select_edus
(
db
:
&
Database
,
server
:
&
ServerName
)
->
Result
<
(
Vec
<
Vec
<
u8
>
>
,
u64
)
>
{
// u64: count of last edu
let
since
=
db
.sending
...
...
@@ -366,9 +374,7 @@ pub fn select_edus(db: &Database, server: &ServerName) -> Result<(Vec<SendingEve
}
};
events
.push
(
SendingEventType
::
Edu
(
serde_json
::
to_vec
(
&
federation_event
)
.expect
(
"json can be serialized"
),
));
events
.push
(
serde_json
::
to_vec
(
&
federation_event
)
.expect
(
"json can be serialized"
));
if
events
.len
()
>=
20
{
break
'outer
;
...
...
@@ -402,6 +408,18 @@ pub fn send_pdu(&self, server: &ServerName, pdu_id: &[u8]) -> Result<()> {
Ok
(())
}
#[tracing::instrument(skip(self))]
pub
fn
send_reliable_edu
(
&
self
,
server
:
&
ServerName
,
serialized
:
&
[
u8
])
->
Result
<
()
>
{
let
mut
key
=
server
.as_bytes
()
.to_vec
();
key
.push
(
0xff
);
key
.push
(
b'*'
);
key
.extend_from_slice
(
serialized
);
self
.servernamepduids
.insert
(
&
key
,
b""
)
?
;
self
.sender
.unbounded_send
(
key
)
.unwrap
();
Ok
(())
}
#[tracing::instrument(skip(self))]
pub
fn
send_pdu_appservice
(
&
self
,
appservice_id
:
&
str
,
pdu_id
:
&
[
u8
])
->
Result
<
()
>
{
let
mut
key
=
b"+"
.to_vec
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment