def build_federation_sender(self): if self.should_send_federation(): return FederationSender(self) elif not self.config.worker_app: return FederationRemoteSendQueue(self) else: raise Exception("Workers cannot send federation traffic")
def process_rows_for_federation( transaction_queue: FederationSender, rows: List[FederationStream.FederationStreamRow], ) -> None: """Parse a list of rows from the federation stream and put them in the transaction queue ready for sending to the relevant homeservers. Args: transaction_queue rows """ # The federation stream contains a bunch of different types of # rows that need to be handled differently. We parse the rows, put # them into the appropriate collection and then send them off. buff = ParsedFederationStreamData( presence=[], presence_destinations=[], keyed_edus={}, edus={}, ) # Parse the rows in the stream and add to the buffer for row in rows: if row.type not in TypeToRow: logger.error("Unrecognized federation row type %r", row.type) continue RowType = TypeToRow[row.type] parsed_row = RowType.from_data(row.data) parsed_row.add_to_buffer(buff) if buff.presence: transaction_queue.send_presence(buff.presence) for state, destinations in buff.presence_destinations: transaction_queue.send_presence_to_destinations( states=[state], destinations=destinations) for destination, edu_map in buff.keyed_edus.items(): for key, edu in edu_map.items(): transaction_queue.send_edu(edu, key) for destination, edu_list in buff.edus.items(): for edu in edu_list: transaction_queue.send_edu(edu, None)