Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1764 from matrix-org/markjh/fix_send_pdu
Browse files Browse the repository at this point in the history
Only send events that originate on this server.
  • Loading branch information
NegativeMjark authored Jan 5, 2017
2 parents 0d766c8 + f784980 commit 6028718
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ def is_outlier(self):
def is_invite_from_remote(self):
return getattr(self, "invite_from_remote", False)

def get_send_on_behalf_of(self):
"""Whether this server should send the event on behalf of another server.
This is used by the federation "send_join" API to forward the initial join
event for a server in the room.
returns a str with the name of the server this event is sent on behalf of.
"""
return getattr(self, "get_send_on_behalf_of", None)


def _event_dict_property(key):
def getter(self):
Expand Down
12 changes: 12 additions & 0 deletions synapse/federation/transaction_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, hs):
self.transport_layer = hs.get_federation_transport_client()

self.clock = hs.get_clock()
self.is_mine_id = hs.is_mine_id

# Is a mapping from destinations -> deferreds. Used to keep track
# of which destinations have transactions in flight and when they are
Expand Down Expand Up @@ -152,6 +153,12 @@ def notify_new_events(self, current_id):
break

for event in events:
# Only send events for this server.
send_on_behalf_of = event.internal_metadata.get_send_on_behalf_of()
is_mine = self.is_mine_id(event.event_id)
if not is_mine and send_on_behalf_of is None:
continue

# Get the state from before the event.
# We need to make sure that this is the state from before
# the event and not from after it.
Expand All @@ -167,6 +174,11 @@ def notify_new_events(self, current_id):
destinations = set(
get_domain_from_id(user_id) for user_id in users_in_room
)
if send_on_behalf_of is not None:
# If we are sending the event on behalf of another server
# then it already has the event and there is no reason to
# send the event to it.
destinations.discard(send_on_behalf_of)

logger.debug("Sending %s to %r", event, destinations)

Expand Down
4 changes: 4 additions & 0 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,10 @@ def on_send_join_request(self, origin, pdu):
)

event.internal_metadata.outlier = False
# Send this event on behalf of the origin server since they may not
# have an up to data view of the state of the room at this event so
# will not know which servers to send the event to.
event.internal_metadata.send_on_behalf_of = origin

context, event_stream_id, max_stream_id = yield self._handle_new_event(
origin, event
Expand Down

0 comments on commit 6028718

Please sign in to comment.