예제 #1
0
        private bool OnRoundEnd(int round, int bridgeCount, int blockedCount)
        {
            var userCount    = Simulator.NodeCount <User>();
            var corruptCount = Simulator.NodeCount <CorruptUser>();
            var thirstyCount = Simulator.GetNodes <User>().Where(u => u.IsThirsty && !(u is CorruptUser)).Count();

            int N = blockedSoFar + bridgeCount;

            blockedSoFar += blockedCount;

            // Add one new row to the grid view
            dgvStats.Rows.Add(new string[] {
                round.ToString(), userCount.ToString(), corruptCount.ToString(),
                (bridgeCount / repeatCount).ToString(), bridgeCount.ToString(),
                blockedCount.ToString(), N.ToString(), thirstyCount.ToString(),
            });
            runLog.Add(new RoundLog(round, userCount, corruptCount, thirstyCount, bridgeCount, blockedCount, Simulator.EmailCount));

            if (rbSingleRun.Checked)
            {
                // Add one point to the plot for this round for each plot
                // (cbLogY.Checked ? 1 : 0) prevents log(zero) in log plots
                chPlots.Series[cbThirsty.Text].Points.AddXY(round, thirstyCount + (cbLogY.Checked ? 1 : 0));
                chPlots.Series[cbm.Text].Points.AddXY(round, bridgeCount);
                chPlots.Series[cbb.Text].Points.AddXY(round, blockedCount + (cbLogY.Checked ? 1 : 0));
                chPlots.Series[cbN.Text].Points.AddXY(round, N);
                chPlots.Series[cbDistMessageCount.Text].Points.AddXY(round, Simulator.MessageCount);
                //chPlots.Series[cbEmailCount.Text].Points.AddXY(round, (double)Simulator.EmailCount / userCount);
            }

            Application.DoEvents();
            return(stopRequest);
        }
예제 #2
0
파일: User.cs 프로젝트: tartaruszen/bricks
        //public override void Receive<BrideAssignment>(int fromNode, BrideAssignment message, MessageType type)
        //{
        //    throw new NotImplementedException();
        //}

        public override void ReceiveEmail(long fromPseudonym, object message, MessageType type)
        {
            if (type == MessageType.UserAssignments)   // From a distributor: Here's a list of bridge id share for you.
            {
                var assignments = message as List <UserAssignment>;
                if (distributorPseudonyms.Count == 1)
                {
                    foreach (var a in assignments)
                    {
                        Bridges.Add(Simulator.GetNode <Bridge>((int)a.BridgeShare.Value));
                    }
                }
                else
                {
                    foreach (var a in assignments)
                    {
                        if (!BridgeShares.ContainsKey(a.BridgePseudonym))
                        {
                            BridgeShares[a.BridgePseudonym] = new List <Zp>();
                        }

                        BridgeShares[a.BridgePseudonym].Add(a.BridgeShare);

                        if (BridgeShares[a.BridgePseudonym].Count == distributorPseudonyms.Count)
                        {
                            // We have enough number of shares to reconstruct the bridge ID
                            int bridgeId = (int)ShamirSharing.Reconstruct(BridgeShares[a.BridgePseudonym],
                                                                          Simulator.PolynomialDegree, Simulator.Prime).Value;

                            Debug.Assert(Simulator.GetNodes <Bridge>().Any(b => b.Id == bridgeId), "Invalid bridge ID reconstructed from shares.");
                            Bridges.Add(Simulator.GetNode <Bridge>(bridgeId));
                            BridgeShares[a.BridgePseudonym] = null;
                        }
                    }
                }
            }
            else
            {
                throw new Exception("Invalid message received.");
            }
        }