Пример #1
0
static int lazy_update(slap_quorum_t *q) {
	unsigned total_links, ready_links;
	unsigned ready_rids, ready_sids, wanna_rids, wanna_sids;
	struct present* p;
	struct requirment* r;
	int state = 1;

	ready_rids = ready_sids = 0;
	wanna_rids = wanna_sids = 0;
	total_links = ready_links = 0;
	if (q->qr_present) {
		for(p = q->qr_present; p->ready > -1; ++p) {
			++total_links;
			ready_links += p->ready;
		}
	}

	if ((q->flags & QR_ALL_LINKS) && ready_links < total_links) {
		Debug( LDAP_DEBUG_SYNC, "syncrep_quorum: %s FORCE-LACK"
				" (all-links, not ready)\n",
			   q->qr_cluster );
		state = -1;
	}

	if (q->qr_requirements) {
		for(r = q->qr_requirements; r->type > -1; ++r) {
			if (QR_IS_SID(r->type)) {
				if (r->id == slap_serverID)
					continue;
				++wanna_sids;
				for(p = q->qr_present; p && p->ready > -1; ++p) {
					if (p->sid == r->id) {
						ready_sids += p->ready;
						break;
					}
				}
			} else {
				++wanna_rids;
				for(p = q->qr_present; p && p->ready > -1; ++p) {
					if (p->rid == r->id) {
						ready_rids += p->ready;
						break;
					}
				}
			}
			if (QR_IS_DEMAND(r->type) && (!p || p->ready < 1)) {
				Debug( LDAP_DEBUG_SYNC, "syncrep_quorum: %s FORCE-LACK"
						" (required %s%s %d not ready)\n",
					   q->qr_cluster,
					   QR_IS_AUTO(r->type) ? "auto-" : "",
					   QR_IS_SID(r->type) ? "sid" : "rid",
					   r->id );
				state = -1;
			}
		}

		if (state > 0 && (wanna_sids || wanna_rids))
			state = (quorum(total_links, wanna_sids, ready_sids)
					|| quorum(total_links, wanna_rids, ready_rids)) ? 1 : -1;
	}

	if ((q->flags & QR_AUTO_SIDS) && state > 0 && total_links
	&& ! quorum (total_links, total_links, wanna_sids)) {
		Debug( LDAP_DEBUG_SYNC, "syncrep_quorum: %s FORCE-LACK"
				" (auto-sids, not enough for voting)\n",
			   q->qr_cluster );
		state = -1;
	}

	Debug( LDAP_DEBUG_SYNC, "syncrep_quorum: %s %s (wanna/ready: "
							"link %d/%d, rid %d/%d, sid %d/%d)\n",
		   q->qr_cluster, (state > 0) ? "HAVE" : "LACK",
		   total_links, ready_links, wanna_rids, ready_rids, wanna_sids, ready_sids );
	return state;
}
Пример #2
0
Json::Value
ValidatorList::getJson() const
{
    Json::Value res(Json::objectValue);

    boost::shared_lock<boost::shared_mutex> read_lock{mutex_};

    res[jss::validation_quorum] = static_cast<Json::UInt>(quorum());

    if (auto when = expires())
    {
        if (*when == TimeKeeper::time_point::max())
            res[jss::validator_list_expires] = "never";
        else
            res[jss::validator_list_expires] = to_string(*when);
    }
    else
        res[jss::validator_list_expires] = "unknown";

    // Local static keys
    PublicKey local;
    Json::Value& jLocalStaticKeys =
        (res[jss::local_static_keys] = Json::arrayValue);
    auto it = publisherLists_.find(local);
    if (it != publisherLists_.end())
    {
        for (auto const& key : it->second.list)
            jLocalStaticKeys.append(
                toBase58(TokenType::TOKEN_NODE_PUBLIC, key));
    }

    // Publisher lists
    Json::Value& jPublisherLists =
        (res[jss::publisher_lists] = Json::arrayValue);
    for (auto const& p : publisherLists_)
    {
        if(local == p.first)
            continue;
        Json::Value& curr = jPublisherLists.append(Json::objectValue);
        curr[jss::pubkey_publisher] = strHex(p.first);
        curr[jss::available] = p.second.available;
        if(p.second.expiration != TimeKeeper::time_point{})
        {
            curr[jss::seq] = static_cast<Json::UInt>(p.second.sequence);
            curr[jss::expiration] = to_string(p.second.expiration);
            curr[jss::version] = requiredListVersion;
        }
        Json::Value& keys = (curr[jss::list] = Json::arrayValue);
        for (auto const& key : p.second.list)
        {
            keys.append(toBase58(TokenType::TOKEN_NODE_PUBLIC, key));
        }
    }

    // Trusted validator keys
    Json::Value& jValidatorKeys =
        (res[jss::trusted_validator_keys] = Json::arrayValue);
    for (auto const& k : trustedKeys_)
    {
        jValidatorKeys.append(toBase58(TokenType::TOKEN_NODE_PUBLIC, k));
    }

    // signing keys
    Json::Value& jSigningKeys = (res[jss::signing_keys] = Json::objectValue);
    validatorManifests_.for_each_manifest(
        [&jSigningKeys, this](Manifest const& manifest) {

            auto it = keyListings_.find(manifest.masterKey);
            if (it != keyListings_.end())
            {
                jSigningKeys[toBase58(
                    TokenType::TOKEN_NODE_PUBLIC, manifest.masterKey)] =
                    toBase58(TokenType::TOKEN_NODE_PUBLIC, manifest.signingKey);
            }
        });

    return res;
}