예제 #1
0
    private void poll(object source, System.Timers.ElapsedEventArgs e)
    {
        #region CONSENSUS
        //This is our vote.
        int voteCount  = NodeStatus.count(multiplier, proposal, consensus);
        int totalCount = multiplier + 1;
        //We are just going to poll everyone since we don't yet expect large N.
        //When we start to test this on larger peer counts, we will add subsampling.
        foreach (NodeStatus status in nodes.Values)
        {
            if (status.peer.CurrentState == SignaledPeer.ConnectionStateMachine.NOMINAL)
            {
                voteCount  += status.count(multiplier);
                totalCount += multiplier + 1;
            }
        }

        bool sampleConsensus = voteCount > totalCount / 2;


        if (sampleConsensus != consensus)
        {
            consensus = sampleConsensus;
            Rpc("UpdateNodeStatus", proposal, consensus);
        }
        #endregion

        #region CONFIDENCE
        if (consensus)
        {
            confidence1 += 1;
            confidence0 -= 2;
        }
        else
        {
            confidence0 += 1;
            confidence1 -= 2;
        }
        confidence0 = Clamp(confidence0, 0, 10);
        confidence1 = Clamp(confidence1, 0, 10);
        #endregion
    }