'Tries to find at least one key for each verify request
For each verify_request, verify_request.deferred is called back with
params (server_name, key_id, VerifyKey) if a key is found, or errbacked
with a SynapseError if none of the keys are found.
Args:
verify_requests (list[VerifyKeyRequest]): list of verify requests'

def get_server_verify_keys(self, verify_requests):

    key_fetch_fns = (self.get_keys_from_store, self.get_keys_from_perspectives, self.get_keys_from_server)
    @defer.inlineCallbacks
    def do_iterations():
        with Measure(self.clock, 'get_server_verify_keys'):
            merged_results = {}
            missing_keys = {}
            for verify_request in verify_requests:
                missing_keys.setdefault(verify_request.server_name, set()).update(verify_request.key_ids)
            for fn in key_fetch_fns:
                results = (yield fn(missing_keys.items()))
                merged_results.update(results)
                missing_keys = {}
                requests_missing_keys = []
                for verify_request in verify_requests:
                    server_name = verify_request.server_name
                    result_keys = merged_results[server_name]
                    if verify_request.deferred.called:
                        continue
                    for key_id in verify_request.key_ids:
                        if (key_id in result_keys):
                            with PreserveLoggingContext():
                                verify_request.deferred.callback((server_name, key_id, result_keys[key_id]))
                            break
                    else:
                        missing_keys.setdefault(server_name, set()).update(verify_request.key_ids)
                        requests_missing_keys.append(verify_request)
                if (not missing_keys):
                    break
            for verify_request in requests_missing_keys.values():
                verify_request.deferred.errback(SynapseError(401, ('No    key    for    %s    with    id    %s' % (verify_request.server_name, verify_request.key_ids)), Codes.UNAUTHORIZED))
    def on_err(err):
        for verify_request in verify_requests:
            if (not verify_request.deferred.called):
                verify_request.deferred.errback(err)
    do_iterations().addErrback(on_err)
