StringFloatHashtable * TopologyWorldState::sendProbabilitiesInternal (RemoteNodeInfo *pRNI)
{
    // Create a probabilities table with the info on how to reach remote node pRNI
    StringFloatHashtable *pIndProb = NULL;
    if (isPeerAlive (pRNI)) { // Alive node
        pIndProb = new StringFloatHashtable();
        float fHigh1 = (float) _fProbContact;
        float *pHigh1 = &fHigh1;
        pIndProb->put (_pDisService->getNodeId(), pHigh1);
    }
    else { // Dead node
        if (pRNI->getIndirectProbabilities()) {
            float fHigh1 = 0.0f;
            const char *pszHigh1 = NULL;
            float fHigh2 = 0.0f;
            const char *pszHigh2 = NULL;
            for (StringFloatHashtable::Iterator iNodes = pRNI->getIndirectProbabilities()->getAllElements(); !iNodes.end(); iNodes.nextElement()) {
                if (isActiveNeighbor (iNodes.getKey())) {
                    float prob = *(iNodes.getValue());
                    if (prob > fHigh1 && prob > fHigh2) {
                        fHigh2 = fHigh1;
                        pszHigh2 = pszHigh1;
                        fHigh1 = prob;
                        pszHigh1 = iNodes.getKey();
                    }
                    else if (prob > fHigh2) {
                        fHigh2 = prob;
                        pszHigh2 = iNodes.getKey();
                    }
                }
            }
            if (fHigh1 > 0.0f) { 
                pIndProb = new StringFloatHashtable();
                float *pHigh1 = &fHigh1;
                pIndProb->put (pszHigh1, pHigh1);
                if (fHigh2 > 0.0f) {
                    float *pHigh2 = &fHigh2;
                    pIndProb->put (pszHigh2, pHigh2);
                }
            }
        }
    }
    return pIndProb;
}
Exemple #2
0
void RemoteNodeInfo::ageIndirectProbabilities (float fAgeParam, float fProbThreshold, int iTimeSinceLastAging)
{
    // Ages the indirect probabilities
    // TODO: find a better way, instead of creating a temporary table
    // _pIndirectProbabilities: gatewayNodeId->probValue
    if (_pIndirectProbabilities) {
        StringFloatHashtable * pIndProbTemp = new StringFloatHashtable();
        for (StringFloatHashtable::Iterator iNodes = _pIndirectProbabilities->getAllElements(); !iNodes.end(); iNodes.nextElement()) {
            float fProb = *(iNodes.getValue()) * pow (fAgeParam, iTimeSinceLastAging);
            if (fProb > fProbThreshold) {
                float *pProb = &fProb;
                pIndProbTemp->put (iNodes.getKey(), pProb);
            }
        }
        delete _pIndirectProbabilities;
        _pIndirectProbabilities = pIndProbTemp;
    }
}