public override void HandleMessage(int fromId, Msg msg) { if (CurrentRound == null && msg.Type == MsgType.NextRound) { // want to start the next round if (IntermediateRoundsRemaining > 0) { CurrentRound = new ShareRenewalRound(Me, Quorums[FROM], Quorums[TO], Shares, Prime, Shares.Length, 3 * Shares.Length, ProtocolId); } else { CurrentRound = new ShareRenewalRound(Me, Quorums[FROM], Quorums[TO], Shares, Prime, Shares.Length, 1, ProtocolId); FinalRound = true; } CurrentRound.Start(); } else { CurrentRound.HandleMessage(fromId, msg); if (CurrentRound.IsCompleted) { if (FinalRound) { if (Quorums[TO].HasMember(Me.Id)) { Debug.Assert(CurrentRound.Result.Length == 1); Result = new Share <BigZp>(CurrentRound.Result[0], false); } IsCompleted = true; } else { Shares = CurrentRound.Result; IntermediateRoundsRemaining--; CurrentRound = null; Send(Me.Id, new Msg(MsgType.NextRound)); // use this to ensure all of the parties stay on the same round } } } }
public override void Start() { // determine how many rounds we will need so that the total number of shares is within a factor of 3 of the number in the receiving quorum IntermediateRoundsRemaining = 0; int shareCount = Quorums[FROM].Size; while (3 * shareCount < Quorums[TO].Size) { IntermediateRoundsRemaining++; shareCount *= 3; } FinalRoundInitialSharesPerParty = shareCount / Quorums[FROM].Size; if (Quorums[FROM].HasMember(Me.Id)) { if (IntermediateRoundsRemaining > 0) { // set up the first intermediate round CurrentRound = new ShareRenewalRound(Me, Quorums[FROM], Quorums[FROM], Shares, Prime, 1, 3, ProtocolId); FinalRound = false; } else { // set up the final round CurrentRound = new ShareRenewalRound(Me, Quorums[FROM], Quorums[TO], Shares, Prime, 1, 1, ProtocolId); FinalRound = true; } } else { // I'm only receiving, so I want to set up the final round CurrentRound = new ShareRenewalRound(Me, Quorums[FROM], Quorums[TO], null, Prime, FinalRoundInitialSharesPerParty, 1, ProtocolId); FinalRound = true; } CurrentRound.Start(); if (CurrentRound.IsCompleted && FinalRound) { IsCompleted = true; } }