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
6ac0b4ad
Commit
6ac0b4ad
authored
10 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Fix 'age' key to update on retries
parent
34d7896b
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
synapse/federation/replication.py
+16
-3
16 additions, 3 deletions
synapse/federation/replication.py
synapse/federation/transport.py
+15
-2
15 additions, 2 deletions
synapse/federation/transport.py
synapse/http/client.py
+10
-3
10 additions, 3 deletions
synapse/http/client.py
with
41 additions
and
8 deletions
synapse/federation/replication.py
+
16
−
3
View file @
6ac0b4ad
...
...
@@ -292,8 +292,8 @@ class ReplicationLayer(object):
transaction
=
Transaction
(
**
transaction_data
)
for
p
in
transaction
.
pdus
:
if
"
age
"
in
p
:
p
[
"
age
_ts
"
]
=
int
(
self
.
clock
.
time_msec
())
-
int
(
p
[
"
age
"
])
if
"
age
_ts
"
in
p
:
p
[
"
age
"
]
=
int
(
self
.
_
clock
.
time_msec
())
-
int
(
p
[
"
age
_ts
"
])
pdu_list
=
[
Pdu
(
**
p
)
for
p
in
transaction
.
pdus
]
...
...
@@ -602,8 +602,21 @@ class _TransactionQueue(object):
logger
.
debug
(
"
TX [%s] Sending transaction...
"
,
destination
)
# Actually send the transaction
# FIXME (erikj): This is a bit of a hack to make the Pdu age
# keys work
def
cb
(
transaction
):
now
=
int
(
self
.
_clock
.
time_msec
())
if
"
pdus
"
in
transaction
:
for
p
in
transaction
[
"
pdus
"
]:
if
"
age_ts
"
in
p
:
p
[
"
age
"
]
=
now
-
int
(
p
[
"
age_ts
"
])
return
transaction
code
,
response
=
yield
self
.
transport_layer
.
send_transaction
(
transaction
transaction
,
on_send_callback
=
cb
,
)
logger
.
debug
(
"
TX [%s] Sent transaction
"
,
destination
)
...
...
This diff is collapsed.
Click to expand it.
synapse/federation/transport.py
+
15
−
2
View file @
6ac0b4ad
...
...
@@ -144,7 +144,7 @@ class TransportLayer(object):
@defer.inlineCallbacks
@log_function
def
send_transaction
(
self
,
transaction
):
def
send_transaction
(
self
,
transaction
,
on_send_callback
=
None
):
"""
Sends the given Transaction to it
'
s destination
Args:
...
...
@@ -165,10 +165,23 @@ class TransportLayer(object):
data
=
transaction
.
get_dict
()
# FIXME (erikj): This is a bit of a hack to make the Pdu age
# keys work
def
cb
(
destination
,
method
,
path_bytes
,
producer
):
if
not
on_send_callback
:
return
transaction
=
json
.
loads
(
producer
.
body
)
new_transaction
=
on_send_callback
(
transaction
)
producer
.
reset
(
new_transaction
)
code
,
response
=
yield
self
.
client
.
put_json
(
transaction
.
destination
,
path
=
PREFIX
+
"
/send/%s/
"
%
transaction
.
transaction_id
,
data
=
data
data
=
data
,
on_send_callback
=
cb
,
)
logger
.
debug
(
...
...
This diff is collapsed.
Click to expand it.
synapse/http/client.py
+
10
−
3
View file @
6ac0b4ad
...
...
@@ -122,7 +122,7 @@ class TwistedHttpClient(HttpClient):
self
.
hs
=
hs
@defer.inlineCallbacks
def
put_json
(
self
,
destination
,
path
,
data
):
def
put_json
(
self
,
destination
,
path
,
data
,
on_send_callback
=
None
):
if
destination
in
_destination_mappings
:
destination
=
_destination_mappings
[
destination
]
...
...
@@ -131,7 +131,8 @@ class TwistedHttpClient(HttpClient):
"
PUT
"
,
path
.
encode
(
"
ascii
"
),
producer
=
_JsonProducer
(
data
),
headers_dict
=
{
"
Content-Type
"
:
[
"
application/json
"
]}
headers_dict
=
{
"
Content-Type
"
:
[
"
application/json
"
]},
on_send_callback
=
on_send_callback
,
)
logger
.
debug
(
"
Getting resp body
"
)
...
...
@@ -218,7 +219,7 @@ class TwistedHttpClient(HttpClient):
@defer.inlineCallbacks
def
_create_request
(
self
,
destination
,
method
,
path_bytes
,
param_bytes
=
b
""
,
query_bytes
=
b
""
,
producer
=
None
,
headers_dict
=
{},
retry_on_dns_fail
=
True
):
retry_on_dns_fail
=
True
,
on_send_callback
=
None
):
"""
Creates and sends a request to the given url
"""
headers_dict
[
b
"
User-Agent
"
]
=
[
b
"
Synapse
"
]
...
...
@@ -242,6 +243,9 @@ class TwistedHttpClient(HttpClient):
endpoint
=
self
.
_getEndpoint
(
reactor
,
destination
);
while
True
:
if
on_send_callback
:
on_send_callback
(
destination
,
method
,
path_bytes
,
producer
)
try
:
response
=
yield
self
.
agent
.
request
(
destination
,
...
...
@@ -310,6 +314,9 @@ class _JsonProducer(object):
"""
Used by the twisted http client to create the HTTP body from json
"""
def
__init__
(
self
,
jsn
):
self
.
reset
(
jsn
)
def
reset
(
self
,
jsn
):
self
.
body
=
encode_canonical_json
(
jsn
)
self
.
length
=
len
(
self
.
body
)
...
...
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