コード例 #1
0
        void SetupConnections()
        {
            DummyConnection con1 = new DummyConnection();
            DummyConnection con2 = new DummyConnection();
            DummyConnection con3 = new DummyConnection();
            DummyConnection con4 = new DummyConnection();

            DummyConnection.CoupleConnections(con1, con2);
            DummyConnection.CoupleConnections(con3, con4);

            router = new Router(3);
            router.AddConnection(con2);
            router.AddConnection(con3);

            client1 = new Client(1);
            client1.SetConnection(con1);

            client2 = new Client(2);
            client2.SetConnection(con4);

            recievedBroadcasts.Clear();
            recievedMessages.Clear();

            client1.OnBroadcastRecieved += (sender, e) => recievedBroadcasts.Add(e);
            client1.OnMessageRecieved   += (sender, e) => recievedMessages.Add(e);
            client2.OnBroadcastRecieved += (sender, e) => recievedBroadcasts.Add(e);
            client2.OnMessageRecieved   += (sender, e) => recievedMessages.Add(e);
        }
コード例 #2
0
        void SetupConnections()
        {
            DummyConnection conA_1 = new DummyConnection();
            DummyConnection conA_2 = new DummyConnection();
            DummyConnection conB_1 = new DummyConnection();
            DummyConnection conB_2 = new DummyConnection();
            DummyConnection conC_1 = new DummyConnection();
            DummyConnection conC_2 = new DummyConnection();

            DummyConnection.CoupleConnections(conA_1, conA_2);
            DummyConnection.CoupleConnections(conB_1, conB_2);
            DummyConnection.CoupleConnections(conC_1, conC_2);

            idServ = new IDServer(conC_2);

            router = new Router(1);
            router.AddConnection(conA_1);
            router.AddConnection(conB_1);
            router.AddConnection(conC_1);

            client1 = new Client(0);
            client1.SetConnection(conA_2);

            client2 = new Client(2);
            client2.SetConnection(conB_2);
        }
コード例 #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public DummyBitFieldMessage(DummyEncryptedConnection encryptedConnection, DummyConnection connection, DummyConnecter connecter)
     : base(encryptedConnection)
 {
     this.connection = connection;
     this.connecter  = connecter;
     this.InitialBytesLength(connecter.PiecesNumber);
 }
コード例 #4
0
        public ConnectionServer()
        {
            Client       = new JBVClient(SoftwareID.ConnectionServer);
            router       = new Router();
            leaseHandler = new LeaseHandler();
            logHandler   = new LogHandler();



            DummyConnection cRouter1 = new DummyConnection();
            DummyConnection cRouter2 = new DummyConnection();
            DummyConnection cRouter3 = new DummyConnection();

            router.AddConnection(cRouter1);
            router.AddConnection(cRouter2);
            router.AddConnection(cRouter3);


            DummyConnection.CoupleConnections(cRouter1, Client.Connection);
            DummyConnection.CoupleConnections(cRouter2, leaseHandler.Connection);
            DummyConnection.CoupleConnections(cRouter3, logHandler.Connection);


            listener = new TcpSocketListener();
            listener.OnClientAccept += (sender, client) => router.AddConnection(new TCPConnection(client));
            listener.BeginListening(Settings.Items.ListenerPort);
        }
コード例 #5
0
        public DummyConnection CreateConnection(string someIdentifier, string hostname)
        {
            DummyConnection connection = new DummyConnection(someIdentifier, hostname, null);

            _connections.Add(connection);

            return(connection);
        }
コード例 #6
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="booleans">片断的BitField信息</param>
 public DummyBitFieldMessage(bool[] booleans)
     : base(null)
 {
     this.connection = null;
     this.connecter  = null;
     this.booleans   = booleans;
     this.InitialBytesLength(booleans.Length);
 }
コード例 #7
0
        public void TestReusableCallConnectionPool_AddOne()
        {
            var pool = new ReusableCallConnectionPool();

            var dummyConnection = new DummyConnection("1");

            pool.Register(dummyConnection);

            Assert.AreEqual(dummyConnection, pool.FindByNamespace("1"));
        }
コード例 #8
0
        public DummyConnection CreateConnectionToBeTimedOut(string someIdentifier, string hostname, TimeSpan throwTimeoutAt)
        {
            DummyConnection connection = new DummyConnection(someIdentifier, hostname, async() =>
            {
                await Task.Delay(throwTimeoutAt);
                DummyEventSource.Instance.ConnectionTimedOut(someIdentifier, hostname);
            });

            _connections.Add(connection);

            return(connection);
        }
コード例 #9
0
        public DummyConnection CreateConnectionToBeThrownException(string someIdentifier, string hostname, TimeSpan throwExceptionAt)
        {
            DummyConnection connection = new DummyConnection(someIdentifier, hostname, async() =>
            {
                await Task.Delay(throwExceptionAt);
                DummyEventSource.Instance.UnhandledException("An unhandled exception is occured in connection.");
            });

            _connections.Add(connection);

            return(connection);
        }
コード例 #10
0
        public void TestReusableCallConnectionPool_AddTwo()
        {
            var pool = new ReusableCallConnectionPool();

            var dummyConnection1 = new DummyConnection("ns");
            var dummyConnection2 = new DummyConnection("ns");

            pool.Register(dummyConnection1);
            pool.Register(dummyConnection2);

            Assert.AreEqual(dummyConnection1, pool.FindByNamespace("ns"));
            Assert.AreEqual(dummyConnection2, pool.FindByNamespace("ns"));
        }
コード例 #11
0
        public void TestReusableCallConnectionPool_IgnoreNotAlive()
        {
            var pool = new ReusableCallConnectionPool();

            var dummyConnection1 = new DummyConnection("ns");
            var dummyConnection2 = new DummyConnection("ns");

            pool.Register(dummyConnection1);
            pool.Register(dummyConnection2);

            dummyConnection1.IsAlive = false;

            Assert.AreEqual(dummyConnection2, pool.FindByNamespace("ns"));
        }
コード例 #12
0
        public void Initialize()
        {
            //get the grandparent folder of DeploymentDirectory to share with scraper
            resultDir = Directory.GetParent(Directory.GetParent(TestContext.DeploymentDirectory).FullName).FullName;
            Console.WriteLine("resultDir = {0}", resultDir);

            /* initialize a proxy and command handler */
            proxy = new WindowsProxy(new RootForm())
            {
                bPasscodeVerified = true
            };
            cmdhlr           = new CommandHandler(null, null, proxy);
            conn             = new DummyConnection();
            proxy.connection = conn;
        }
コード例 #13
0
ファイル: ScraperTest.cs プロジェクト: oscarlab/sinter
        public void Initialize()
        {
            //get the grandparent folder of DeploymentDirectory to share with proxy
            resultDir = Directory.GetParent(Directory.GetParent(TestContext.DeploymentDirectory).FullName).FullName;
            Console.WriteLine("resultDir = {0}", resultDir);

            /* initialize a scraper and command handler */
            scraper = new WindowsScraper("0000");
            scraper.bPasscodeVerified = true;
            cmdhlr                     = new CommandHandler(null, null, scraper);
            conn                       = new DummyConnection();
            conn.filepath              = string.Format(@"{0}\{1}.xml", resultDir, TestContext.TestName); /* set connection filepath to desired output file */
            scraper.connection         = conn;
            scraper.supportedProcesses = new string[] { "calc1", "notepad", "wordpad" };
        }
コード例 #14
0
 public Bridge()
 {
     DummyConnection.CoupleConnections(Con1, Con2);
 }
コード例 #15
0
ファイル: Test.cs プロジェクト: dbrgn/pi-vote
        /// <summary>
        /// Voting entity test.
        /// </summary>
        /// <remarks>
        /// Used only during development.
        /// </remarks>
        public void EntityTest()
        {
            IRpcConnection connection = new DummyConnection();

              DateTime validUntil = DateTime.Now.AddDays(1);
              var root = new CACertificate(null, "Root");
              root.CreateSelfSignature();
              var rootCrl = new RevocationList(root.Id, DateTime.Now, validUntil, new List<Guid>());
              var sigRootCrl = new Signed<RevocationList>(rootCrl, root);

              var intermediate = new CACertificate(null, "Intermediate");
              intermediate.CreateSelfSignature();
              intermediate.AddSignature(root, validUntil);
              var intCrl = new RevocationList(intermediate.Id, DateTime.Now, validUntil, new List<Guid>());
              var sigIntCrl = new Signed<RevocationList>(intCrl, intermediate);

              var admin = new AdminCertificate(Language.English, null, "Admin");
              admin.CreateSelfSignature();
              admin.AddSignature(intermediate, DateTime.Now.AddDays(1));

              var serverCert = new ServerCertificate("Server");
              serverCert.CreateSelfSignature();
              serverCert.AddSignature(intermediate, DateTime.Now.AddDays(1));

              VotingParameters parameters =
            new VotingParameters(
              new MultiLanguageString("Zufrieden"),
              new MultiLanguageString("Tada"),
              new MultiLanguageString(string.Empty),
              DateTime.Now,
              DateTime.Now.AddDays(1),
              0);
              parameters.GenerateNumbers(Files.TestDataPath);

              Question question = new Question(new MultiLanguageString("Zufrieden?"), new MultiLanguageString(string.Empty), new MultiLanguageString(string.Empty), 1);
              question.AddOption(new Option(new MultiLanguageString("Nein"), new MultiLanguageString("Dagegen"), new MultiLanguageString(string.Empty)));
              question.AddOption(new Option(new MultiLanguageString("Ja"), new MultiLanguageString("Dafür"), new MultiLanguageString(string.Empty)));
              parameters.AddQuestion(question);

              Signed<VotingParameters> signedParameters = new Signed<VotingParameters>(parameters, admin);

              DateTime start = DateTime.Now;
              Console.WriteLine();
              Console.Write("Voting begins...");

              CertificateStorage serverCertStorage = new CertificateStorage();
              serverCertStorage.AddRoot(root);
              serverCertStorage.Add(intermediate);
              serverCertStorage.AddRevocationList(sigRootCrl);
              serverCertStorage.AddRevocationList(sigIntCrl);

              VotingServerEntity vs = new VotingServerEntity(null, signedParameters, serverCertStorage, serverCert);

              var a1c = new AuthorityCertificate(Language.English, "Authority 1", null);
              a1c.CreateSelfSignature();
              a1c.AddSignature(intermediate, validUntil);
              var a2c = new AuthorityCertificate(Language.English, "Authority 2", null);
              a2c.CreateSelfSignature();
              a2c.AddSignature(intermediate, validUntil);
              var a3c = new AuthorityCertificate(Language.English, "Authority 3", null);
              a3c.CreateSelfSignature();
              a3c.AddSignature(intermediate, validUntil);
              var a4c = new AuthorityCertificate(Language.English, "Authority 4", null);
              a4c.CreateSelfSignature();
              a4c.AddSignature(intermediate, validUntil);
              var a5c = new AuthorityCertificate(Language.English, "Authority 5", null);
              a5c.CreateSelfSignature();
              a5c.AddSignature(intermediate, validUntil);

              var a1 = new AuthorityEntity(serverCertStorage, a1c);
              var a2 = new AuthorityEntity(serverCertStorage, a2c);
              var a3 = new AuthorityEntity(serverCertStorage, a3c);
              var a4 = new AuthorityEntity(serverCertStorage, a4c);
              var a5 = new AuthorityEntity(serverCertStorage, a5c);

              vs.AddAuthority(connection, a1.Certificate);
              vs.AddAuthority(connection, a2.Certificate);
              vs.AddAuthority(connection, a3.Certificate);
              vs.AddAuthority(connection, a4.Certificate);
              vs.AddAuthority(connection, a5.Certificate);

              a1.Prepare(1, vs.SignedParameters);
              a2.Prepare(2, vs.SignedParameters);
              a3.Prepare(3, vs.SignedParameters);
              a4.Prepare(4, vs.SignedParameters);
              a5.Prepare(5, vs.SignedParameters);

              a1.SetAuthorities(vs.AuthorityList);
              a2.SetAuthorities(vs.AuthorityList);
              a3.SetAuthorities(vs.AuthorityList);
              a4.SetAuthorities(vs.AuthorityList);
              a5.SetAuthorities(vs.AuthorityList);

              vs.DepositShares(connection, a1.GetShares());
              vs.DepositShares(connection, a2.GetShares());
              vs.DepositShares(connection, a3.GetShares());
              vs.DepositShares(connection, a4.GetShares());
              vs.DepositShares(connection, a5.GetShares());

              var r1 = a1.VerifyShares(vs.GetAllShares());
              var r2 = a2.VerifyShares(vs.GetAllShares());
              var r3 = a3.VerifyShares(vs.GetAllShares());
              var r4 = a4.VerifyShares(vs.GetAllShares());
              var r5 = a5.VerifyShares(vs.GetAllShares());

              vs.DepositShareResponse(connection, r1);
              vs.DepositShareResponse(connection, r2);
              vs.DepositShareResponse(connection, r3);
              vs.DepositShareResponse(connection, r4);
              vs.DepositShareResponse(connection, r5);

              var v1c = new VoterCertificate(Language.English, null, 0);
              v1c.CreateSelfSignature();
              v1c.AddSignature(intermediate, validUntil);

              var cs = new CertificateStorage();
              cs.AddRoot(root);
              var v1 = new VoterEntity(cs);

              IEnumerable<int> questionVota = new int[] { 0, 1 };

              var vote1 = v1.Vote(vs.GetVotingMaterial(), v1c, new IEnumerable<int>[] { questionVota }, null);

              vs.Vote(connection, vote1);

              int voters = 10;

              for (int i = 1000; i < 1000 + voters; i++)
              {
            var vc = new VoterCertificate(Language.English, null, 0);
            vc.CreateSelfSignature();
            vc.AddSignature(intermediate, validUntil);

            var vx = new VoterEntity(cs);

            IEnumerable<int> questionVota2 = new int[] { 0, 1 };
            var votex = vx.Vote(vs.GetVotingMaterial(), vc, new IEnumerable<int>[] { questionVota2 }, null);

            vs.Vote(connection, votex);
              }

              for (int i = 2000; i < 2000 + voters; i++)
              {
            var vc = new VoterCertificate(Language.English, null, 0);
            vc.CreateSelfSignature();
            vc.AddSignature(intermediate, validUntil);

            var vx = new VoterEntity(cs);

            IEnumerable<int> questionVota3 = new int[] { 1, 0 };
            var votex = vx.Vote(vs.GetVotingMaterial(), vc, new IEnumerable<int>[] { questionVota3 }, null);

            vs.Vote(connection, votex);
              }

              vs.EndVote();

              a1.TallyBegin(vs.GetVotingMaterial());
              a2.TallyBegin(vs.GetVotingMaterial());
              a3.TallyBegin(vs.GetVotingMaterial());
              a4.TallyBegin(vs.GetVotingMaterial());
              a5.TallyBegin(vs.GetVotingMaterial());

              for (int envelopeIndex = 0; envelopeIndex < vs.GetEnvelopeCount(); envelopeIndex++)
              {
            a1.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
            a2.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
            a3.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
            a4.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
            a5.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
              }

              var pd1 = a1.PartiallyDecipher();
              var pd2 = a2.PartiallyDecipher();
              var pd3 = a3.PartiallyDecipher();
              var pd4 = a4.PartiallyDecipher();
              var pd5 = a5.PartiallyDecipher();

              vs.DepositPartialDecipher(connection, pd1);
              vs.DepositPartialDecipher(connection, pd2);
              vs.DepositPartialDecipher(connection, pd3);
              vs.DepositPartialDecipher(connection, pd4);
              vs.DepositPartialDecipher(connection, pd5);

              v1.TallyBegin(vs.GetVotingMaterial(), BaseParameters.StandardProofCount);

              for (int envelopeIndex = 0; envelopeIndex < vs.GetEnvelopeCount(); envelopeIndex++)
              {
            v1.TallyAdd(envelopeIndex, vs.GetEnvelope(envelopeIndex), new Progress(null));
              }

              for (int authorityIndex = 1; authorityIndex < vs.Parameters.AuthorityCount + 1; authorityIndex++)
              {
            v1.TallyAddPartialDecipher(vs.GetPartialDecipher(authorityIndex));
              }

              var res1 = v1.TallyResult;

              TimeSpan duration = DateTime.Now.Subtract(start);
              Console.WriteLine("Succeded {0}", duration.ToString());
        }