internal void GenerateTestTransactions() { var physicianKeys = EncryptionHandler.GenerateNewKeys(); var tempTransactions = new TransactionGenerator(physicianKeys.PrivateKey); var physicianRegistration = tempTransactions.InitializeAsNewPhysician(physicianKeys.PublicKey, "Austria", "Vienna", "Der Herbert"); var physicianVoting = transactionGenerator.GenerateVotingTransaction(physicianRegistration.TransactionId, true); var patientRegistration = tempTransactions.GeneratePatientRegistrationTransaction("Austria", "Vienna", "1992"); var treatment = tempTransactions.GenerateTreatmentTransaction(physicianRegistration.TransactionId, patientRegistration.TransactionId); var symptom = tempTransactions.GenerateSymptomTransaction(treatment.TransactionId, new List <string>() { "R05", "R50.80" }); var diagnoses = tempTransactions.GenerateDiagnosesTransaction(treatment.TransactionId, new List <string>() { "B34.2" }); node.OnReceiveTransaction(physicianRegistration); node.OnReceiveTransaction(physicianVoting); Thread.Sleep(4000); node.OnReceiveTransaction(patientRegistration); node.OnReceiveTransaction(treatment); Thread.Sleep(1000); node.OnReceiveTransaction(symptom); node.OnReceiveTransaction(diagnoses); }
internal void SetupNewPublisher(string country, string region, string entityName) { var keys = EncryptionHandler.GenerateNewKeys(); transactionGenerator = new TransactionGenerator(keys.PrivateKey); ITransaction registration = transactionGenerator.InitializeAsNewPublisher(keys.PublicKey, country, region, entityName); node.User = new UserProperties() { Username = currentUser , Keys = keys , PublisherAddress = registration.TransactionId }; if (!node.IsChainInitialized()) { ITransaction vote = transactionGenerator.GenerateVotingTransaction(registration.TransactionId, true); node.RequestChainInitialization(registration, vote); } else { node.OnReveiceTransaction(registration); } }
public void RegistrateAndVotePhysician() { #region Set up Publisher var keysPublisher = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGeneratorPublisher = new TransactionGenerator(keysPublisher.PrivateKey); var registrationPublisher = transactionGeneratorPublisher.InitializeAsNewPublisher(keysPublisher.PublicKey, "Austria", "Vienna", "Publisher"); var votePublisher = transactionGeneratorPublisher.GenerateVotingTransaction(registrationPublisher.TransactionId, true); PublisherNode publisher = new PublisherNode(); publisher.User = new NodeManagement.Entities.UserProperties() { Keys = keysPublisher, UserAddress = registrationPublisher.TransactionId, Username = "******" }; publisher.InitializeEmptyChain(registrationPublisher, votePublisher); Assert.IsTrue(publisher.participantHandler.HasPublisher(registrationPublisher.TransactionId)); #endregion #region Generate registration for physician var keysPhysician = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGeneratorPhyisician = new TransactionGenerator(keysPhysician.PrivateKey); var registrationPhysician = transactionGeneratorPhyisician.InitializeAsNewPhysician(keysPhysician.PublicKey, "Austria", "Vienna", "Physician"); var votePhysician = transactionGeneratorPublisher.GenerateVotingTransaction(registrationPhysician.TransactionId, true); #endregion publisher.OnReceiveTransaction(registrationPhysician); Assert.IsFalse(publisher.participantHandler.HasPhysician(registrationPhysician.TransactionId)); publisher.OnReceiveTransaction(votePhysician); publisher.BundleOpenTransactionsManually(); publisher.PublishOpenBlocks(publisher); Assert.IsTrue(publisher.participantHandler.HasPhysician(registrationPhysician.TransactionId)); }
public void AddBlockToChain() { var keys = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGenerator = new TransactionGenerator(keys.PrivateKey); var registration = transactionGenerator.InitializeAsNewPublisher(keys.PublicKey, "Austria", "Vienna", "Master"); var vote = transactionGenerator.GenerateVotingTransaction(registration.TransactionId, true); Block block = new Block(); block.Index = 0; block.Publisher = registration.TransactionId; block.AddTransaction(registration); block.AddTransaction(vote); block.Sign(keys.PrivateKey); Chain chain = new Chain(); chain.Add(block); Assert.IsTrue(chain.ValidateContextual(new ParticipantHandler(), null)); }
internal void StartAsNewPublisher(string country, string region, string entityName, ServerAddress selfAddress, ServerAddress initializerAddress) { var keys = EncryptionHandler.GenerateNewKeys(); transactionGenerator = new TransactionGenerator(keys.PrivateKey); ITransaction registration = transactionGenerator.InitializeAsNewPublisher(keys.PublicKey, country, region, entityName); node.User = new UserProperties() { Username = currentUser , Keys = keys , UserAddress = registration.TransactionId }; serverSettings = selfAddress; node.SetSelfAddress(serverSettings); Start(); if (initializerAddress != null) { RegisterAt(initializerAddress); UpdateKnownNodes(); } if (!node.IsChainInitialized()) { ITransaction vote = transactionGenerator.GenerateVotingTransaction(registration.TransactionId, true); node.InitializeEmptyChain(registration, vote); } else { node.OnReceiveTransaction(registration); } }
public void MeasureTransactionProcessing() { #region Set up Publisher var keysPublisher = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGeneratorPublisher = new TransactionGenerator(keysPublisher.PrivateKey); var registrationPublisher = transactionGeneratorPublisher.InitializeAsNewPublisher(keysPublisher.PublicKey, "Austria", "Vienna", "Publisher"); var votePublisher = transactionGeneratorPublisher.GenerateVotingTransaction(registrationPublisher.TransactionId, true); PublisherNode publisher = new PublisherNode(); publisher.User = new NodeManagement.Entities.UserProperties() { Keys = keysPublisher, UserAddress = registrationPublisher.TransactionId, Username = "******" }; publisher.InitializeEmptyChain(registrationPublisher, votePublisher); Assert.IsTrue(publisher.participantHandler.HasPublisher(registrationPublisher.TransactionId)); #endregion var referencePhysicianKeys = EncryptionHandler.GenerateNewKeys(); var referencePhysicianGenerator = new TransactionGenerator(referencePhysicianKeys.PrivateKey); var referencePhysician = referencePhysicianGenerator.InitializeAsNewPhysician(referencePhysicianKeys.PrivateKey, "Austria", "Vienna", "Physician"); var referencePhysicianVote = transactionGeneratorPublisher.GenerateVotingTransaction(referencePhysician.TransactionId, true); var referencePatient = referencePhysicianGenerator.GeneratePatientRegistrationTransaction("Austria", "Vienna", "1990"); var referenceTreatment = referencePhysicianGenerator.GenerateTreatmentTransaction(referencePhysician.TransactionId, referencePatient.TransactionId); publisher.OnReceiveTransaction(referencePhysician); publisher.OnReceiveTransaction(referencePhysicianVote); publisher.OnReceiveTransaction(referencePatient); publisher.OnReceiveTransaction(referenceTreatment); publisher.BundleOpenTransactionsManually(); publisher.PublishOpenBlocks(publisher); Assert.AreEqual(1, publisher.GetChain().Blockhead.Index); Random random = new Random(); for (int i = 0; i < 50000; i++) { int choice = random.Next(1, 6); switch (choice) { case 1: var keysNewPhysician = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGeneratorNewPhysician = new TransactionGenerator(keysNewPhysician.PrivateKey); var transaction = transactionGeneratorNewPhysician.InitializeAsNewPhysician(keysNewPhysician.PublicKey, "Austria", "Vienna", "Physician"); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); publisher.OnReceiveTransaction(transaction); stopwatch.Stop(); string log = "PHYSICIAN\t" + (i % maxBlockSize) + "\t" + maxBlockSize + "\t" + publisher.GetChain().Blockhead.Index + "\t" + publisher.GetChain().GetTransactions().Count + "\t" + stopwatch.ElapsedMilliseconds + "\t" + GetRAMUsage() + "\n"; FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\TransactionLog.txt", log); break; case 2: transaction = referencePhysicianGenerator.GeneratePatientRegistrationTransaction("Austria", "Vienna", "Patient"); stopwatch = new Stopwatch(); stopwatch.Start(); publisher.OnReceiveTransaction(transaction); stopwatch.Stop(); log = "PATIENT\t" + (i % maxBlockSize) + "\t" + maxBlockSize + "\t" + publisher.GetChain().Blockhead.Index + "\t" + publisher.GetChain().GetTransactions().Count + "\t" + stopwatch.ElapsedMilliseconds + "\t" + GetRAMUsage() + "\n"; FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\TransactionLog.txt", log); break; case 3: var patients = (from x in publisher.GetChain().GetTransactions() where x.GetType() == typeof(PatientRegistrationTransaction) select x.TransactionId).ToList(); var p = patients.Count() > 1 ? patients[random.Next(1, patients.Count()) - 1] : referencePatient.TransactionId; transaction = referencePhysicianGenerator.GenerateTreatmentTransaction(referencePhysician.TransactionId, p); stopwatch = new Stopwatch(); stopwatch.Start(); publisher.OnReceiveTransaction(transaction); stopwatch.Stop(); log = "TREATMENT\t" + (i % maxBlockSize) + "\t" + maxBlockSize + "\t" + publisher.GetChain().Blockhead.Index + "\t" + publisher.GetChain().GetTransactions().Count + "\t" + stopwatch.ElapsedMilliseconds + "\t" + GetRAMUsage() + "\n"; FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\TransactionLog.txt", log); break; case 4: var treatments = (from x in publisher.GetChain().GetTransactions() where x.GetType() == typeof(TreatmentTransaction) select x.TransactionId).ToList(); var t = treatments.Count() > 1 ? treatments[random.Next(1, treatments.Count()) - 1] : referenceTreatment.TransactionId; transaction = referencePhysicianGenerator.GenerateSymptomTransaction(t, new List <string>() { "Symptom" }); stopwatch = new Stopwatch(); stopwatch.Start(); publisher.OnReceiveTransaction(transaction); stopwatch.Stop(); log = "SYMPTOM\t" + (i % maxBlockSize) + "\t" + maxBlockSize + "\t" + publisher.GetChain().Blockhead.Index + "\t" + publisher.GetChain().GetTransactions().Count + "\t" + stopwatch.ElapsedMilliseconds + "\t" + GetRAMUsage() + "\n"; FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\TransactionLog.txt", log); break; case 5: transaction = transactionGeneratorPublisher.GenerateVotingTransaction(referencePhysician.TransactionId, true); stopwatch = new Stopwatch(); stopwatch.Start(); publisher.OnReceiveTransaction(transaction); stopwatch.Stop(); log = "VOTING\t" + (i % maxBlockSize) + "\t" + maxBlockSize + "\t" + publisher.GetChain().Blockhead.Index + "\t" + publisher.GetChain().GetTransactions().Count + "\t" + stopwatch.ElapsedMilliseconds + "\t" + GetRAMUsage() + "\n"; FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\TransactionLog.txt", log); break; default: break; } publisher.participantHandler.EvaluateParkedTransactions(); if (i % maxBlockSize == 0) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); publisher.BundleOpenTransactionsManually(); publisher.PublishOpenBlocks(publisher); stopwatch.Stop(); string log = "BLOCK\t" + (i % maxBlockSize) + "\t" + maxBlockSize + "\t" + publisher.GetChain().Blockhead.Index + "\t" + publisher.GetChain().GetTransactions().Count + "\t" + stopwatch.ElapsedMilliseconds + "\n"; FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\BlockLog.txt", log); stopwatch = new Stopwatch(); stopwatch.Start(); publisher.ValidateChain(); stopwatch.Stop(); log = "VALIDATION\t" + (i % maxBlockSize) + "\t" + maxBlockSize + "\t" + publisher.GetChain().Blockhead.Index + "\t" + publisher.GetChain().GetTransactions().Count + "\t" + stopwatch.ElapsedMilliseconds + "\n"; FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\ValidationLog.txt", log); QueryNode query = new QueryNode(); query.UpdateChain(publisher.GetChain()); stopwatch = new Stopwatch(); stopwatch.Start(); query.ExtractData((PatientRegistrationTransaction p) => true, (TreatmentTransaction t) => true, (SymptomsTransaction s) => true, (DiagnosesTransaction d) => true); stopwatch.Stop(); log = "QUERY\t" + (i % maxBlockSize) + "\t" + maxBlockSize + "\t" + publisher.GetChain().Blockhead.Index + "\t" + publisher.GetChain().GetTransactions().Count + "\t" + stopwatch.ElapsedMilliseconds + "\n"; FileHandler.Append("D:\\DiagnosticChain\\DiagnosticChain\\QueryLog.txt", log); } } }
internal void VoteFor(Guid address, bool vote) { var votingTransaction = transactionGenerator.GenerateVotingTransaction(address, vote); node.SendTransaction(votingTransaction); }
public void ProcessPatientData() { #region Set up Publisher var keysPublisher = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGeneratorPublisher = new TransactionGenerator(keysPublisher.PrivateKey); var registrationPublisher = transactionGeneratorPublisher.InitializeAsNewPublisher(keysPublisher.PublicKey, "Austria", "Vienna", "Publisher"); var votePublisher = transactionGeneratorPublisher.GenerateVotingTransaction(registrationPublisher.TransactionId, true); PublisherNode publisher = new PublisherNode(); publisher.User = new NodeManagement.Entities.UserProperties() { Keys = keysPublisher, UserAddress = registrationPublisher.TransactionId, Username = "******" }; publisher.InitializeEmptyChain(registrationPublisher, votePublisher); Assert.IsTrue(publisher.participantHandler.HasPublisher(registrationPublisher.TransactionId)); #endregion #region Register physician var keysPhysician = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGeneratorPhyisician = new TransactionGenerator(keysPhysician.PrivateKey); var registrationPhysician = transactionGeneratorPhyisician.InitializeAsNewPhysician(keysPhysician.PublicKey, "Austria", "Vienna", "Physician"); var votePhysician = transactionGeneratorPublisher.GenerateVotingTransaction(registrationPhysician.TransactionId, true); publisher.OnReceiveTransaction(registrationPhysician); publisher.OnReceiveTransaction(votePhysician); publisher.BundleOpenTransactionsManually(); publisher.PublishOpenBlocks(publisher); Assert.IsTrue(publisher.participantHandler.HasPhysician(registrationPhysician.TransactionId)); #endregion var patientA = transactionGeneratorPhyisician.GeneratePatientRegistrationTransaction("Austria", "Vienna", "1990"); publisher.OnReceiveTransaction(patientA); Assert.IsTrue(publisher.participantHandler.parkedPatients.Contains(patientA)); Assert.IsFalse(publisher.participantHandler.HasPatient(patientA.TransactionId)); publisher.BundleOpenTransactionsManually(); publisher.PublishOpenBlocks(publisher); Assert.IsTrue(publisher.participantHandler.parkedPatients.Contains(patientA)); Assert.IsFalse(publisher.participantHandler.HasPatient(patientA.TransactionId)); for (int i = 0; i < 2; i++) { publisher.OnReceiveTransaction( transactionGeneratorPhyisician.GeneratePatientRegistrationTransaction("Austria", "Vienna", "1990") ); } Assert.IsTrue(publisher.participantHandler.parkedPatients.Contains(patientA)); Assert.IsFalse(publisher.participantHandler.HasPatient(patientA.TransactionId)); publisher.EvaluateParkedTransactions(); publisher.BundleOpenTransactionsManually(); publisher.PublishOpenBlocks(publisher); Assert.IsFalse(publisher.participantHandler.parkedPatients.Contains(patientA)); Assert.IsTrue(publisher.participantHandler.HasPatient(patientA.TransactionId)); }
public void ConsolidateChains() { #region Set up Publisher A var keysA = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGeneratorA = new TransactionGenerator(keysA.PrivateKey); var registrationA = transactionGeneratorA.InitializeAsNewPublisher(keysA.PublicKey, "Austria", "Vienna", "PublisherA"); var voteA = transactionGeneratorA.GenerateVotingTransaction(registrationA.TransactionId, true); PublisherNode publisherA = new PublisherNode(); publisherA.User = new NodeManagement.Entities.UserProperties() { Keys = keysA, UserAddress = registrationA.TransactionId, Username = "******" }; publisherA.InitializeEmptyChain(registrationA, voteA); #endregion #region Set up Publisher B var keysB = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGeneratorB = new TransactionGenerator(keysB.PrivateKey); var registrationB = transactionGeneratorB.InitializeAsNewPublisher(keysB.PublicKey, "Austria", "Vienna", "PublisherB"); PublisherNode publisherB = new PublisherNode(); publisherB.User = new NodeManagement.Entities.UserProperties() { Keys = keysB, UserAddress = registrationB.TransactionId, Username = "******" }; publisherB.OnReceiveChain(publisherA.GetChain()); publisherB.OnReceiveTransaction(registrationB); publisherB.BundleOpenTransactionsManually(); publisherB.PublishOpenBlocks(publisherB); #endregion #region Authorize Publisher B publisherA.OnReceiveChain(publisherB.GetChainDelta(0)); Assert.AreEqual(publisherA.GetChain().AsXML(), publisherB.GetChain().AsXML()); var voteB = transactionGeneratorA.GenerateVotingTransaction(registrationB.TransactionId, true); publisherA.OnReceiveTransaction(voteB); publisherA.BundleOpenTransactionsManually(); publisherA.PublishOpenBlocks(publisherA); publisherB.OnReceiveChain(publisherA.GetChainDelta(1)); Assert.AreEqual(publisherA.GetChain().AsXML(), publisherB.GetChain().AsXML()); #endregion var transactionA = transactionGeneratorA.GenerateVotingTransaction(registrationB.TransactionId, true); var transactionB = transactionGeneratorB.GenerateVotingTransaction(registrationA.TransactionId, true); var transactionC = transactionGeneratorB.GenerateVotingTransaction(registrationA.TransactionId, true); #region Send transactions to publishers publisherA.OnReceiveTransaction(transactionA); publisherA.BundleOpenTransactionsManually(); publisherA.PublishOpenBlocks(publisherA); publisherB.OnReceiveTransaction(transactionB); publisherB.BundleOpenTransactionsManually(); publisherB.PublishOpenBlocks(publisherB); publisherB.OnReceiveTransaction(transactionC); publisherB.BundleOpenTransactionsManually(); publisherB.PublishOpenBlocks(publisherB); #endregion publisherA.OnReceiveChain(publisherB.GetChainDelta(2)); var hit = from t in publisherA.GetChain().GetTransactions() where t.TransactionId == transactionA.TransactionId select t; Assert.AreEqual(hit.Count(), 0); publisherA.BundleOpenTransactionsManually(); publisherA.PublishOpenBlocks(publisherA); hit = from t in publisherA.GetChain().GetTransactions() where t.TransactionId == transactionA.TransactionId select t; Assert.AreEqual(1, hit.Count()); }
public void RegistrateAndVotePublisher() { #region Set up Publisher A var keysA = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGeneratorA = new TransactionGenerator(keysA.PrivateKey); var registrationA = transactionGeneratorA.InitializeAsNewPublisher(keysA.PublicKey, "Austria", "Vienna", "PublisherA"); var voteA = transactionGeneratorA.GenerateVotingTransaction(registrationA.TransactionId, true); PublisherNode publisherA = new PublisherNode(); publisherA.User = new NodeManagement.Entities.UserProperties() { Keys = keysA, UserAddress = registrationA.TransactionId, Username = "******" }; publisherA.InitializeEmptyChain(registrationA, voteA); Assert.IsTrue(publisherA.participantHandler.HasPublisher(registrationA.TransactionId)); #endregion #region Set up Publisher B var keysB = EncryptionHandler.GenerateNewKeys(); TransactionGenerator transactionGeneratorB = new TransactionGenerator(keysB.PrivateKey); var registrationB = transactionGeneratorB.InitializeAsNewPublisher(keysB.PublicKey, "Austria", "Vienna", "PublisherB"); PublisherNode publisherB = new PublisherNode(); publisherB.User = new NodeManagement.Entities.UserProperties() { Keys = keysB, UserAddress = registrationB.TransactionId, Username = "******" }; publisherB.OnReceiveChain(publisherA.GetChain()); publisherB.OnReceiveTransaction(registrationB); publisherB.BundleOpenTransactionsManually(); publisherB.PublishOpenBlocks(publisherB); #endregion Assert.IsFalse(publisherA.participantHandler.HasPublisher(registrationB.TransactionId)); Assert.IsFalse(publisherB.participantHandler.HasPublisher(registrationB.TransactionId)); #region Authorize Publisher B publisherA.OnReceiveChain(publisherB.GetChainDelta(0)); Assert.AreEqual(publisherA.GetChain().AsXML(), publisherB.GetChain().AsXML()); var voteB = transactionGeneratorA.GenerateVotingTransaction(registrationB.TransactionId, true); publisherA.OnReceiveTransaction(voteB); publisherA.BundleOpenTransactionsManually(); publisherA.PublishOpenBlocks(publisherA); publisherB.OnReceiveChain(publisherA.GetChainDelta(1)); Assert.AreEqual(publisherA.GetChain().AsXML(), publisherB.GetChain().AsXML()); #endregion Assert.IsTrue(publisherA.participantHandler.HasPublisher(registrationB.TransactionId)); Assert.IsTrue(publisherB.participantHandler.HasPublisher(registrationB.TransactionId)); }