Example #1
0
        public async Task <ConsensusResult> DistributeEntry(object objectData, MethodType method)
        {
            var entries = new List <Entry>();
            var entry   = new Entry
            {
                ObjectType = objectData.GetType().FullName,
                Value      = objectData,
                Method     = method
            };

            entries.Add(entry);

            var tasks = SendAppendEntries(entries);

            try
            {
                await Task.WhenAll(tasks.ToArray());
            }
            catch (Exception exception)
            {
                _logger.LogDebug("Exception during distributing entries.", exception);
            }

            int successful = await CollectResponses(tasks);

            var allNodes = _consensusContext.NodeStates.Count + 1;

            if ((successful * 2) >= allNodes)
            {
                return(ConsensusResult.CreateSuccessful());
            }

            return(ConsensusResult.CreateError("Log wasn't replicated to majority amount of the nodes."));
        }
Example #2
0
 public override void Deserialize(BinaryReader reader)
 {
     base.Deserialize(reader);
     BlockIndex = reader.ReadInt64();
     BlockHash  = reader.ReadString();
     Commited   = reader.ReadBoolean();
     Consensus  = (ConsensusResult)reader.ReadInt32();
 }
Example #3
0
 public override void Deserialize(BinaryReader reader)
 {
     base.Deserialize(reader);
     Candidate = reader.ReadString();
     Consensus = (ConsensusResult)reader.ReadInt32();
 }