private void SendProposal() { var proposal = new ElectionProposalMessage() { SourceID = _config.ID, DestinationID = Constants.NULL_DESTINATION, Proposal = _r.Next(0, 1000000) }; _proposals.Add(proposal.SourceID, proposal); Debug.WriteLine(string.Format("TX {0}", proposal.Type)); SendMessage(proposal, _group); }
private void HandleElectionProposal(ElectionProposalMessage msg) { Debug.WriteLine("HandleElectionProposal"); _proposals.Add(msg.SourceID, msg); bool ack = false; if (_proposals.ContainsKey(_config.ID)) { Debug.WriteLine("Proposals contains my id"); if (!_proposals[_config.ID].IsGreaterThan(msg)) { Debug.WriteLine("This id is larger than mine"); ack = true; } } else { Debug.WriteLine("Proposals does not contain my id"); ack = true; } if (ack) { _haveAcked = true; var ackMsg = new ElectionAckMessage() { SourceID = _config.ID, DestinationID = msg.SourceID }; Debug.WriteLine(string.Format("TX {0}", ackMsg.Type)); SendMessage(ackMsg, _group); } }