mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-11-13 02:50:37 -05:00
Merge branch 'develop' of github.com:matrix-org/synapse into federation_authorization
Conflicts: synapse/federation/transport.py synapse/handlers/message.py
This commit is contained in:
commit
bb4a20174c
57 changed files with 563 additions and 6425 deletions
|
|
@ -96,7 +96,7 @@ class PduCodec(object):
|
|||
if k not in ["event_id", "room_id", "type", "prev_events"]
|
||||
})
|
||||
|
||||
if "ts" not in kwargs:
|
||||
kwargs["ts"] = int(self.clock.time_msec())
|
||||
if "origin_server_ts" not in kwargs:
|
||||
kwargs["origin_server_ts"] = int(self.clock.time_msec())
|
||||
|
||||
return Pdu(**kwargs)
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ class TransactionActions(object):
|
|||
transaction.prev_ids = yield self.store.prep_send_transaction(
|
||||
transaction.transaction_id,
|
||||
transaction.destination,
|
||||
transaction.ts,
|
||||
transaction.origin_server_ts,
|
||||
[(p["pdu_id"], p["origin"]) for p in transaction.pdus]
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -321,7 +321,7 @@ class ReplicationLayer(object):
|
|||
|
||||
if hasattr(transaction, "edus"):
|
||||
for edu in [Edu(**x) for x in transaction.edus]:
|
||||
self.received_edu(edu.origin, edu.edu_type, edu.content)
|
||||
self.received_edu(transaction.origin, edu.edu_type, edu.content)
|
||||
|
||||
results = yield defer.DeferredList(dl)
|
||||
|
||||
|
|
@ -474,7 +474,7 @@ class ReplicationLayer(object):
|
|||
return Transaction(
|
||||
origin=self.server_name,
|
||||
pdus=pdus,
|
||||
ts=int(self._clock.time_msec()),
|
||||
origin_server_ts=int(self._clock.time_msec()),
|
||||
destination=None,
|
||||
)
|
||||
|
||||
|
|
@ -654,7 +654,7 @@ class _TransactionQueue(object):
|
|||
logger.debug("TX [%s] Persisting transaction...", destination)
|
||||
|
||||
transaction = Transaction.create_new(
|
||||
ts=self._clock.time_msec(),
|
||||
origin_server_ts=self._clock.time_msec(),
|
||||
transaction_id=str(self._next_txn_id),
|
||||
origin=self.server_name,
|
||||
destination=destination,
|
||||
|
|
|
|||
|
|
@ -301,6 +301,11 @@ class TransportLayer(object):
|
|||
|
||||
auth_headers = request.requestHeaders.getRawHeaders(b"Authorization")
|
||||
|
||||
if not auth_headers:
|
||||
raise SynapseError(
|
||||
401, "Missing Authorization headers", Codes.UNAUTHORIZED,
|
||||
)
|
||||
|
||||
for auth in auth_headers:
|
||||
if auth.startswith("X-Matrix"):
|
||||
(origin, key, sig) = parse_auth_header(auth)
|
||||
|
|
@ -319,13 +324,13 @@ class TransportLayer(object):
|
|||
def _with_authentication(self, handler):
|
||||
@defer.inlineCallbacks
|
||||
def new_handler(request, *args, **kwargs):
|
||||
(origin, content) = yield self._authenticate_request(request)
|
||||
try:
|
||||
(origin, content) = yield self._authenticate_request(request)
|
||||
response = yield handler(
|
||||
origin, content, request.args, *args, **kwargs
|
||||
)
|
||||
except:
|
||||
logger.exception("Callback failed")
|
||||
logger.exception("_authenticate_request failed")
|
||||
raise
|
||||
defer.returnValue(response)
|
||||
return new_handler
|
||||
|
|
@ -496,9 +501,13 @@ class TransportLayer(object):
|
|||
defer.returnValue((400, {"error": "Invalid transaction"}))
|
||||
return
|
||||
|
||||
code, response = yield self.received_handler.on_incoming_transaction(
|
||||
transaction_data
|
||||
)
|
||||
try:
|
||||
code, response = yield self.received_handler.on_incoming_transaction(
|
||||
transaction_data
|
||||
)
|
||||
except:
|
||||
logger.exception("on_incoming_transaction failed")
|
||||
raise
|
||||
|
||||
defer.returnValue((code, response))
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Pdu(JsonEncodedObject):
|
|||
|
||||
{
|
||||
"pdu_id": "78c",
|
||||
"ts": 1404835423000,
|
||||
"origin_server_ts": 1404835423000,
|
||||
"origin": "bar",
|
||||
"prev_ids": [
|
||||
["23b", "foo"],
|
||||
|
|
@ -55,7 +55,7 @@ class Pdu(JsonEncodedObject):
|
|||
"pdu_id",
|
||||
"context",
|
||||
"origin",
|
||||
"ts",
|
||||
"origin_server_ts",
|
||||
"pdu_type",
|
||||
"destinations",
|
||||
"transaction_id",
|
||||
|
|
@ -82,7 +82,7 @@ class Pdu(JsonEncodedObject):
|
|||
"pdu_id",
|
||||
"context",
|
||||
"origin",
|
||||
"ts",
|
||||
"origin_server_ts",
|
||||
"pdu_type",
|
||||
"content",
|
||||
]
|
||||
|
|
@ -118,6 +118,7 @@ class Pdu(JsonEncodedObject):
|
|||
"""
|
||||
if pdu_tuple:
|
||||
d = copy.copy(pdu_tuple.pdu_entry._asdict())
|
||||
d["origin_server_ts"] = d.pop("ts")
|
||||
|
||||
d["content"] = json.loads(d["content_json"])
|
||||
del d["content_json"]
|
||||
|
|
@ -156,11 +157,15 @@ class Edu(JsonEncodedObject):
|
|||
]
|
||||
|
||||
required_keys = [
|
||||
"origin",
|
||||
"destination",
|
||||
"edu_type",
|
||||
]
|
||||
|
||||
# TODO: SYN-103: Remove "origin" and "destination" keys.
|
||||
# internal_keys = [
|
||||
# "origin",
|
||||
# "destination",
|
||||
# ]
|
||||
|
||||
|
||||
class Transaction(JsonEncodedObject):
|
||||
""" A transaction is a list of Pdus and Edus to be sent to a remote home
|
||||
|
|
@ -182,7 +187,7 @@ class Transaction(JsonEncodedObject):
|
|||
"transaction_id",
|
||||
"origin",
|
||||
"destination",
|
||||
"ts",
|
||||
"origin_server_ts",
|
||||
"previous_ids",
|
||||
"pdus",
|
||||
"edus",
|
||||
|
|
@ -199,7 +204,7 @@ class Transaction(JsonEncodedObject):
|
|||
"transaction_id",
|
||||
"origin",
|
||||
"destination",
|
||||
"ts",
|
||||
"origin_server_ts",
|
||||
"pdus",
|
||||
]
|
||||
|
||||
|
|
@ -221,10 +226,10 @@ class Transaction(JsonEncodedObject):
|
|||
@staticmethod
|
||||
def create_new(pdus, **kwargs):
|
||||
""" Used to create a new transaction. Will auto fill out
|
||||
transaction_id and ts keys.
|
||||
transaction_id and origin_server_ts keys.
|
||||
"""
|
||||
if "ts" not in kwargs:
|
||||
raise KeyError("Require 'ts' to construct a Transaction")
|
||||
if "origin_server_ts" not in kwargs:
|
||||
raise KeyError("Require 'origin_server_ts' to construct a Transaction")
|
||||
if "transaction_id" not in kwargs:
|
||||
raise KeyError(
|
||||
"Require 'transaction_id' to construct a Transaction"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue