'Called when we have a new pdu. We need to do auth checks and put it
through the StateHandler.'

@log_function
@defer.inlineCallbacks
def _process_received_pdu(self, origin, pdu, state, auth_chain):

    event = pdu
    logger.debug('Processing    event:    %s', event)
    if (state and auth_chain and (not event.internal_metadata.is_outlier())):
        is_in_room = (yield self.auth.check_host_in_room(event.room_id, self.server_name))
    else:
        is_in_room = True
    if (not is_in_room):
        logger.info("Got    event    for    room    we're    not    in:    %r    %r", event.room_id, event.event_id)
        try:
            (event_stream_id, max_stream_id) = (yield self._persist_auth_tree(origin, auth_chain, state, event))
        except AuthError as e:
            raise FederationError('ERROR', e.code, e.msg, affected=event.event_id)
    else:
        event_ids = set()
        if state:
            event_ids |= {e.event_id for e in state}
        if auth_chain:
            event_ids |= {e.event_id for e in auth_chain}
        seen_ids = set((yield self.store.have_events(event_ids)).keys())
        if (state and (auth_chain is not None)):
            event_infos = []
            for e in itertools.chain(auth_chain, state):
                if (e.event_id in seen_ids):
                    continue
                e.internal_metadata.outlier = True
                auth_ids = [e_id for (e_id, _) in e.auth_events]
                auth = {(e.type, e.state_key): e for e in auth_chain if ((e.event_id in auth_ids) or (e.type == EventTypes.Create))}
                event_infos.append({'event': e, 'auth_events': auth})
                seen_ids.add(e.event_id)
            (yield self._handle_new_events(origin, event_infos))
        try:
            (context, event_stream_id, max_stream_id) = (yield self._handle_new_event(origin, event, state=state))
        except AuthError as e:
            raise FederationError('ERROR', e.code, e.msg, affected=event.event_id)
    room = (yield self.store.get_room(event.room_id))
    if (not room):
        try:
            (yield self.store.store_room(room_id=event.room_id, room_creator_user_id='', is_public=False))
        except StoreError:
            logger.exception('Failed    to    store    room.')
    extra_users = []
    if (event.type == EventTypes.Member):
        target_user_id = event.state_key
        target_user = UserID.from_string(target_user_id)
        extra_users.append(target_user)
    self.notifier.on_new_room_event(event, event_stream_id, max_stream_id, extra_users=extra_users)
    if (event.type == EventTypes.Member):
        if (event.membership == Membership.JOIN):
            newly_joined = True
            prev_state_id = context.prev_state_ids.get((event.type, event.state_key))
            if prev_state_id:
                prev_state = (yield self.store.get_event(prev_state_id, allow_none=True))
                if (prev_state and (prev_state.membership == Membership.JOIN)):
                    newly_joined = False
            if newly_joined:
                user = UserID.from_string(event.state_key)
                (yield user_joined_room(self.distributor, user, event.room_id))
