Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
428581dd
Commit
428581dd
authored
10 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
SYN-144: Remove bad keys from pdu json objects, convert age_ts to age
for all pdus sent.
parent
572a1ca4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/api/events/__init__.py
+12
-1
12 additions, 1 deletion
synapse/api/events/__init__.py
synapse/federation/replication.py
+17
-14
17 additions, 14 deletions
synapse/federation/replication.py
with
29 additions
and
15 deletions
synapse/api/events/__init__.py
+
12
−
1
View file @
428581dd
...
...
@@ -117,10 +117,21 @@ class SynapseEvent(JsonEncodedObject):
"""
raise
NotImplementedError
(
"
get_content_template not implemented.
"
)
def
get_pdu_json
(
self
):
def
get_pdu_json
(
self
,
time_now
=
None
):
pdu_json
=
self
.
get_full_dict
()
pdu_json
.
pop
(
"
destination
"
,
None
)
pdu_json
.
pop
(
"
outlier
"
,
None
)
pdu_json
.
pop
(
"
replaces_state
"
,
None
)
pdu_json
.
pop
(
"
redacted
"
,
None
)
state_hash
=
pdu_json
.
pop
(
"
state_hash
"
,
None
)
if
state_hash
is
not
None
:
pdu_json
.
setdefault
(
"
unsigned
"
,
{})[
"
state_hash
"
]
=
state_hash
content
=
pdu_json
.
get
(
"
content
"
,
{})
content
.
pop
(
"
prev
"
,
None
)
if
time_now
is
not
None
and
"
age_ts
"
in
pdu_json
:
age
=
time_now
-
pdu_json
[
"
age_ts
"
]
pdu_json
.
setdefault
(
"
unsigned
"
,
{})[
"
age
"
]
=
int
(
age
)
del
pdu_json
[
"
age_ts
"
]
return
pdu_json
...
...
This diff is collapsed.
Click to expand it.
synapse/federation/replication.py
+
17
−
14
View file @
428581dd
...
...
@@ -399,19 +399,21 @@ class ReplicationLayer(object):
@defer.inlineCallbacks
def
on_make_join_request
(
self
,
context
,
user_id
):
pdu
=
yield
self
.
handler
.
on_make_join_request
(
context
,
user_id
)
time_now
=
self
.
_clock
.
time_msec
()
defer
.
returnValue
({
"
event
"
:
pdu
.
get_pdu_json
(),
"
event
"
:
pdu
.
get_pdu_json
(
time_now
),
})
@defer.inlineCallbacks
def
on_invite_request
(
self
,
origin
,
content
):
pdu
=
self
.
event_from_pdu_json
(
content
)
ret_pdu
=
yield
self
.
handler
.
on_invite_request
(
origin
,
pdu
)
time_now
=
self
.
_clock
.
time_msec
()
defer
.
returnValue
(
(
200
,
{
"
event
"
:
ret_pdu
.
get_pdu_json
(),
"
event
"
:
ret_pdu
.
get_pdu_json
(
time_now
),
}
)
)
...
...
@@ -420,20 +422,21 @@ class ReplicationLayer(object):
def
on_send_join_request
(
self
,
origin
,
content
):
pdu
=
self
.
event_from_pdu_json
(
content
)
res_pdus
=
yield
self
.
handler
.
on_send_join_request
(
origin
,
pdu
)
time_now
=
self
.
_clock
.
time_msec
()
defer
.
returnValue
((
200
,
{
"
state
"
:
[
p
.
get_pdu_json
()
for
p
in
res_pdus
[
"
state
"
]],
"
auth_chain
"
:
[
p
.
get_pdu_json
()
for
p
in
res_pdus
[
"
auth_chain
"
]],
"
state
"
:
[
p
.
get_pdu_json
(
time_now
)
for
p
in
res_pdus
[
"
state
"
]],
"
auth_chain
"
:
[
p
.
get_pdu_json
(
time_now
)
for
p
in
res_pdus
[
"
auth_chain
"
]],
}))
@defer.inlineCallbacks
def
on_event_auth
(
self
,
origin
,
context
,
event_id
):
time_now
=
self
.
_clock
.
time_msec
()
auth_pdus
=
yield
self
.
handler
.
on_event_auth
(
event_id
)
defer
.
returnValue
(
(
200
,
{
"
auth_chain
"
:
[
a
.
get_pdu_json
()
for
a
in
auth_pdus
],
"
auth_chain
"
:
[
a
.
get_pdu_json
(
time_now
)
for
a
in
auth_pdus
],
}
)
)
...
...
@@ -454,11 +457,12 @@ class ReplicationLayer(object):
@defer.inlineCallbacks
def
send_join
(
self
,
destination
,
pdu
):
time_now
=
self
.
_clock
.
time_msec
()
_
,
content
=
yield
self
.
transport_layer
.
send_join
(
destination
,
pdu
.
room_id
,
pdu
.
event_id
,
pdu
.
get_pdu_json
(),
pdu
.
get_pdu_json
(
time_now
),
)
logger
.
debug
(
"
Got content: %s
"
,
content
)
...
...
@@ -479,11 +483,12 @@ class ReplicationLayer(object):
@defer.inlineCallbacks
def
send_invite
(
self
,
destination
,
context
,
event_id
,
pdu
):
time_now
=
self
.
_clock
.
time_msec
()
code
,
content
=
yield
self
.
transport_layer
.
send_invite
(
destination
=
destination
,
context
=
context
,
event_id
=
event_id
,
content
=
pdu
.
get_pdu_json
(),
content
=
pdu
.
get_pdu_json
(
time_now
),
)
pdu_dict
=
content
[
"
event
"
]
...
...
@@ -505,13 +510,8 @@ class ReplicationLayer(object):
"""
Returns a new Transaction containing the given PDUs suitable for
transmission.
"""
pdus
=
[
p
.
get_pdu_json
()
for
p
in
pdu_list
]
time_now
=
self
.
_clock
.
time_msec
()
for
p
in
pdus
:
if
"
age_ts
"
in
p
:
age
=
time_now
-
p
[
"
age_ts
"
]
p
.
setdefault
(
"
unsigned
"
,
{})[
"
age
"
]
=
int
(
age
)
del
p
[
"
age_ts
"
]
pdus
=
[
p
.
get_pdu_json
(
time_now
)
for
p
in
pdu_list
]
return
Transaction
(
origin
=
self
.
server_name
,
pdus
=
pdus
,
...
...
@@ -582,6 +582,9 @@ class ReplicationLayer(object):
#TODO: Check we have all the PDU keys here
pdu_json
.
setdefault
(
"
hashes
"
,
{})
pdu_json
.
setdefault
(
"
signatures
"
,
{})
state_hash
=
pdu_json
.
get
(
"
unsigned
"
,
{}).
pop
(
"
state_hash
"
,
None
)
if
state_hash
is
not
None
:
pdu_json
[
"
state_hash
"
]
=
state_hash
return
self
.
event_factory
.
create_event
(
pdu_json
[
"
type
"
],
outlier
=
outlier
,
**
pdu_json
)
...
...
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