Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
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
Maunium
synapse
Commits
8c8858e1
Unverified
Commit
8c8858e1
authored
4 years ago
by
Patrick Cloke
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Convert federation handler to async/await. (#7459)
parent
be309d99
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/7459.misc
+1
-0
1 addition, 0 deletions
changelog.d/7459.misc
synapse/handlers/federation.py
+14
-18
14 additions, 18 deletions
synapse/handlers/federation.py
synapse/handlers/room_member.py
+2
-3
2 additions, 3 deletions
synapse/handlers/room_member.py
with
17 additions
and
21 deletions
changelog.d/7459.misc
0 → 100644
+
1
−
0
View file @
8c8858e1
Convert the federation handler to async/await.
This diff is collapsed.
Click to expand it.
synapse/handlers/federation.py
+
14
−
18
View file @
8c8858e1
...
...
@@ -2681,8 +2681,7 @@ class FederationHandler(BaseHandler):
member_handler
=
self
.
hs
.
get_room_member_handler
()
await
member_handler
.
send_membership_event
(
None
,
event
,
context
)
@defer.inlineCallbacks
def
add_display_name_to_third_party_invite
(
async
def
add_display_name_to_third_party_invite
(
self
,
room_version
,
event_dict
,
event
,
context
):
key
=
(
...
...
@@ -2690,10 +2689,10 @@ class FederationHandler(BaseHandler):
event
.
content
[
"
third_party_invite
"
][
"
signed
"
][
"
token
"
],
)
original_invite
=
None
prev_state_ids
=
yield
context
.
get_prev_state_ids
()
prev_state_ids
=
await
context
.
get_prev_state_ids
()
original_invite_id
=
prev_state_ids
.
get
(
key
)
if
original_invite_id
:
original_invite
=
yield
self
.
store
.
get_event
(
original_invite
=
await
self
.
store
.
get_event
(
original_invite_id
,
allow_none
=
True
)
if
original_invite
:
...
...
@@ -2714,14 +2713,13 @@ class FederationHandler(BaseHandler):
builder
=
self
.
event_builder_factory
.
new
(
room_version
,
event_dict
)
EventValidator
().
validate_builder
(
builder
)
event
,
context
=
yield
self
.
event_creation_handler
.
create_new_client_event
(
event
,
context
=
await
self
.
event_creation_handler
.
create_new_client_event
(
builder
=
builder
)
EventValidator
().
validate_new
(
event
,
self
.
config
)
return
(
event
,
context
)
@defer.inlineCallbacks
def
_check_signature
(
self
,
event
,
context
):
async
def
_check_signature
(
self
,
event
,
context
):
"""
Checks that the signature in the event is consistent with its invite.
...
...
@@ -2738,12 +2736,12 @@ class FederationHandler(BaseHandler):
signed
=
event
.
content
[
"
third_party_invite
"
][
"
signed
"
]
token
=
signed
[
"
token
"
]
prev_state_ids
=
yield
context
.
get_prev_state_ids
()
prev_state_ids
=
await
context
.
get_prev_state_ids
()
invite_event_id
=
prev_state_ids
.
get
((
EventTypes
.
ThirdPartyInvite
,
token
))
invite_event
=
None
if
invite_event_id
:
invite_event
=
yield
self
.
store
.
get_event
(
invite_event_id
,
allow_none
=
True
)
invite_event
=
await
self
.
store
.
get_event
(
invite_event_id
,
allow_none
=
True
)
if
not
invite_event
:
raise
AuthError
(
403
,
"
Could not find invite
"
)
...
...
@@ -2792,7 +2790,7 @@ class FederationHandler(BaseHandler):
raise
try
:
if
"
key_validity_url
"
in
public_key_object
:
yield
self
.
_check_key_revocation
(
await
self
.
_check_key_revocation
(
public_key
,
public_key_object
[
"
key_validity_url
"
]
)
except
Exception
:
...
...
@@ -2806,8 +2804,7 @@ class FederationHandler(BaseHandler):
last_exception
=
e
raise
last_exception
@defer.inlineCallbacks
def
_check_key_revocation
(
self
,
public_key
,
url
):
async
def
_check_key_revocation
(
self
,
public_key
,
url
):
"""
Checks whether public_key has been revoked.
...
...
@@ -2821,7 +2818,7 @@ class FederationHandler(BaseHandler):
for revocation.
"""
try
:
response
=
yield
self
.
http_client
.
get_json
(
url
,
{
"
public_key
"
:
public_key
})
response
=
await
self
.
http_client
.
get_json
(
url
,
{
"
public_key
"
:
public_key
})
except
Exception
:
raise
SynapseError
(
502
,
"
Third party certificate could not be checked
"
)
if
"
valid
"
not
in
response
or
not
response
[
"
valid
"
]:
...
...
@@ -2916,8 +2913,7 @@ class FederationHandler(BaseHandler):
else
:
user_joined_room
(
self
.
distributor
,
user
,
room_id
)
@defer.inlineCallbacks
def
get_room_complexity
(
self
,
remote_room_hosts
,
room_id
):
async
def
get_room_complexity
(
self
,
remote_room_hosts
,
room_id
):
"""
Fetch the complexity of a remote room over federation.
...
...
@@ -2931,12 +2927,12 @@ class FederationHandler(BaseHandler):
"""
for
host
in
remote_room_hosts
:
res
=
yield
self
.
federation_client
.
get_room_complexity
(
host
,
room_id
)
res
=
await
self
.
federation_client
.
get_room_complexity
(
host
,
room_id
)
# We got a result, return it.
if
res
:
defer
.
returnValue
(
res
)
return
res
# We fell off the bottom, couldn't get the complexity from anyone. Oh
# well.
defer
.
returnValue
(
None
)
return
None
This diff is collapsed.
Click to expand it.
synapse/handlers/room_member.py
+
2
−
3
View file @
8c8858e1
...
...
@@ -875,8 +875,7 @@ class RoomMemberMasterHandler(RoomMemberHandler):
self
.
distributor
.
declare
(
"
user_joined_room
"
)
self
.
distributor
.
declare
(
"
user_left_room
"
)
@defer.inlineCallbacks
def
_is_remote_room_too_complex
(
self
,
room_id
,
remote_room_hosts
):
async
def
_is_remote_room_too_complex
(
self
,
room_id
,
remote_room_hosts
):
"""
Check if complexity of a remote room is too great.
...
...
@@ -888,7 +887,7 @@ class RoomMemberMasterHandler(RoomMemberHandler):
if unable to be fetched
"""
max_complexity
=
self
.
hs
.
config
.
limit_remote_rooms
.
complexity
complexity
=
yield
self
.
federation_handler
.
get_room_complexity
(
complexity
=
await
self
.
federation_handler
.
get_room_complexity
(
remote_room_hosts
,
room_id
)
...
...
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