public void Search1() { var trust = TrustBuilder.CreateTrust("A", "B", TrustBuilder.CreateTrustTrue()); var trusts = new List <TrustModel>(); trusts.Add(trust); var search = BuildSearch(trusts); var query = new RequestQuery(); query.Issuers = new List <byte[]>(); query.Issuers.Add(trust.Issuer.Id); query.Subjects = new List <SubjectQuery>(); query.Subjects.Add(new SubjectQuery { Id = trust.Issuer.Subjects[0].Id, Type = trust.Issuer.Subjects[0].IdType }); query.Scope = trust.Issuer.Subjects[0].Scope; query.Claim = trust.Issuer.Subjects[0].Claim; var json = JsonConvert.SerializeObject(query, Formatting.Indented); Console.WriteLine(json); var result = search.Query(query); Assert.NotNull(result.Nodes); PrintResult(result.Nodes, search.GraphService, 1); }
public IHttpActionResult Add([FromBody] PackageModel package) { try { var trustBuilder = new TrustBuilder(package); trustBuilder.Verify(); graphBuilder.Append(package); #if RELEASE var buildserverUrl = App.Config["buildserver"].ToStringValue("http://127.0.01:12601"); if (!string.IsNullOrEmpty(buildserverUrl)) { var fullUrl = new UriBuilder(buildserverUrl); fullUrl.Path = Path; using (var client = new HttpClient()) { var response = client.PostAsJsonAsync(fullUrl.ToString(), package); Task.WaitAll(response); var result = response.Result; if (result.StatusCode != System.Net.HttpStatusCode.OK) { return(InternalServerError()); } } } #endif return(Ok(new { status = "succes" })); } catch (Exception ex) { return(new ExceptionResult(ex, this)); } }
public void BuildEdge2() { var trusts = new List <TrustModel>(); trusts.Add(TrustBuilder.CreateTrust("A", "B", TrustBuilder.CreateTrustTrue())); trusts.Add(TrustBuilder.CreateTrust("B", "C", TrustBuilder.CreateTrustTrue())); Assert.AreEqual(trusts[0].Issuer.Subjects[0].Id, trusts[1].Issuer.Id); var graphService = new GraphContext(); var builder = new GraphBuilder(graphService); builder.Build(trusts); Assert.IsTrue(graphService.Graph.Address.Count == 3); Assert.IsTrue(graphService.Graph.Address[0].Edges.Length == 1); Assert.IsTrue(graphService.Graph.Address[0].Edges[0].Claim.Flags == ClaimType.Trust); Assert.IsTrue(graphService.Graph.Address[0].Edges[0].SubjectId == 1); Assert.IsTrue(graphService.Graph.Address[1].Edges.Length == 1); Assert.IsTrue(graphService.Graph.Address[1].Edges[0].Claim.Flags == ClaimType.Trust); Assert.IsTrue(graphService.Graph.Address[1].Edges[0].SubjectId == 2); Assert.IsTrue(graphService.Graph.AddressIndex.Count == 3); Assert.IsTrue(graphService.Graph.SubjectTypesIndex.Count == 2); Assert.IsTrue(graphService.Graph.SubjectTypesIndex.ContainsKey("person")); Assert.IsTrue(graphService.Graph.ScopeIndex.Count == 2); Assert.IsTrue(graphService.Graph.ScopeIndex.ContainsKey("global")); }
public void BuildEdge1() { var trust = TrustBuilder.CreateTrust("A", "B", TrustBuilder.CreateTrustTrue()); trust.Issuer.Subjects[0].Activate = (uint)DateTime.Now.UnixTimestamp() - 1000; trust.Issuer.Subjects[0].Expire = (uint)DateTime.Now.UnixTimestamp() + 1000; trust.Issuer.Subjects[0].Cost = 112; var trusts = new List <TrustModel>(); trusts.Add(trust); var graphService = new GraphContext(); var builder = new GraphBuilder(graphService); builder.Build(trusts); Assert.IsTrue(graphService.Graph.Address.Count == 2); Assert.IsTrue(graphService.Graph.Address[0].Edges.Length == 1); Assert.IsTrue(graphService.Graph.Address[0].Edges[0].Claim.Flags == ClaimType.Trust); Assert.IsTrue(graphService.Graph.Address[0].Edges[0].Claim.Types == ClaimType.Trust); Assert.IsTrue(graphService.Graph.Address[0].Edges[0].SubjectId == 1); Assert.IsTrue(graphService.Graph.Address[0].Edges[0].Cost == trust.Issuer.Subjects[0].Cost); Assert.IsTrue(graphService.Graph.Address[0].Edges[0].Activate == trust.Issuer.Subjects[0].Activate); Assert.IsTrue(graphService.Graph.Address[0].Edges[0].Expire == trust.Issuer.Subjects[0].Expire); Assert.IsTrue(graphService.Graph.AddressIndex.Count == 2); Assert.IsTrue(graphService.Graph.SubjectTypesIndex.Count == 2); Assert.IsTrue(graphService.Graph.SubjectTypesIndex.ContainsKey("person")); Assert.IsTrue(graphService.Graph.ScopeIndex.Count == 2); Assert.IsTrue(graphService.Graph.ScopeIndex.ContainsKey("global")); }
public void Execute() { var blockchain = "btc-testnet"; var timestampSynchronizationService = ServiceProvider.GetRequiredService <ITimestampSynchronizationService>(); var trustDBService = ServiceProvider.GetRequiredService <ITrustDBService>(); var workflowService = ServiceProvider.GetRequiredService <IWorkflowService>(); var proofService = ServiceProvider.GetRequiredService <ITimestampService>(); var timestampWorkflow = workflowService.Create <TimestampWorkflow>(); timestampSynchronizationService.CurrentWorkflowID = workflowService.Save(timestampWorkflow); var trustBuilder = new TrustBuilder(ServiceProvider); trustBuilder.SetServer("testserver"); trustBuilder.AddTrust("A", "B", TrustBuilder.BINARYTRUST_TC1, TrustBuilder.CreateBinaryTrustAttributes(true)); trustBuilder.AddTrust("B", "C", TrustBuilder.BINARYTRUST_TC1, TrustBuilder.CreateBinaryTrustAttributes(true)); trustBuilder.AddTrust("C", "D", TrustBuilder.BINARYTRUST_TC1, TrustBuilder.CreateBinaryTrustAttributes(true)); trustBuilder.Build().Sign(); trustDBService.Add(trustBuilder.Package); foreach (var trust in trustBuilder.Package.Trusts) { proofService.Add(trust.Id); } var merkleStep = timestampWorkflow.GetStep <IMerkleStep>(); merkleStep.Execute(); timestampWorkflow.Proof.Blockchain = blockchain; timestampWorkflow.Proof.Receipt = Guid.NewGuid().ToByteArray(); timestampWorkflow.Proof.Confirmations = 1; workflowService.Save(timestampWorkflow); trustDBService.DBContext.SaveChanges(); var trustTimestampWorkflow = workflowService.Create <TrustTimestampWorkflow>(); var trustTimestampStep = trustTimestampWorkflow.GetStep <ITrustTimestampStep>(); // Now execute! trustTimestampStep.Execute(); foreach (var trust in trustBuilder.Package.Trusts) { var dbTrust = trustDBService.GetTrustById(trust.Id); Assert.IsNotNull(dbTrust); foreach (var timestamp in dbTrust.Timestamps) { Assert.AreEqual(timestamp.Algorithm, blockchain); Assert.IsNotNull(timestamp.Receipt); Assert.IsTrue(timestamp.Receipt.Length > 0); } } }
public IHttpActionResult Get(string issuer, string subject, bool trust = true) { var query = new RequestQuery(); query.Issuers = new List <Byte[]>(); query.Issuers.Add(Convert.FromBase64String(issuer)); query.Subjects = new List <SubjectQuery>(); query.Subjects.Add(new SubjectQuery { Id = Convert.FromBase64String(subject), Type = "" }); query.Claim = TrustBuilder.CreateTrustTrue(); query.Scope = string.Empty; // Global return(ResolvePost(query)); }
public void SearchRating1() { var trusts = new List <TrustModel>(); var trustsource = TrustBuilder.CreateTrust("A", "B", TrustBuilder.CreateTrustTrue()); trusts.Add(trustsource); trusts.Add(TrustBuilder.CreateTrust("B", "C", TrustBuilder.CreateTrustTrue())); var trusttarget = TrustBuilder.CreateTrust("C", "D", TrustBuilder.CreateRating(100)); trusts.Add(trusttarget); trusts.Add(TrustBuilder.CreateTrust("B", "E", TrustBuilder.CreateTrustTrue())); trusts.Add(TrustBuilder.CreateTrust("E", "D", TrustBuilder.CreateRating(50))); trusts.Add(TrustBuilder.CreateTrust("B", "F", TrustBuilder.CreateTrustTrue())); trusts.Add(TrustBuilder.CreateTrust("F", "G", TrustBuilder.CreateTrustTrue())); trusts.Add(TrustBuilder.CreateTrust("G", "D", TrustBuilder.CreateRating(50))); trusts.Add(TrustBuilder.CreateTrust("A", "H", TrustBuilder.CreateTrustTrue())); trusts.Add(TrustBuilder.CreateTrust("H", "G", TrustBuilder.CreateTrustTrue())); trusts.Add(TrustBuilder.CreateTrust("G", "D", TrustBuilder.CreateRating(50))); var search = BuildSearch(trusts); var query = new RequestQuery(); var claim = TrustBuilder.CreateRating(0); // 0 is not used! query.Issuers = new List <byte[]>(); query.Issuers.Add(trustsource.Issuer.Id); query.Subjects = new List <SubjectQuery>(); query.Subjects.Add(new SubjectQuery { Id = trusttarget.Issuer.Subjects[0].Id, Type = trusttarget.Issuer.Subjects[0].IdType }); query.Scope = trusttarget.Issuer.Subjects[0].Scope; query.Claim = claim; var result = search.Query(query); Assert.NotNull(result.Nodes); //Assert.IsTrue(result.Node.Children.Count == 1); //Assert.IsTrue(result.Node.Children[0].Children.Count == 0); //Console.WriteLine("Start id: "+search.GraphService.Graph.IdIndex[0].ConvertToHex()); // A PrintResult(result.Nodes, search.GraphService, 1); PrintJson(result.Nodes); }
public void Search3() { var trust1 = TrustBuilder.CreateTrust("A", "B", TrustBuilder.CreateTrustTrue()); var trust2 = TrustBuilder.CreateTrust("B", "C", TrustBuilder.CreateTrustTrue()); var trust3 = TrustBuilder.CreateTrust("C", "D", TrustBuilder.CreateTrustTrue()); var trusts = new List <TrustModel>(); trusts.Add(trust1); trusts.Add(trust2); trusts.Add(trust3); trusts.Add(TrustBuilder.CreateTrust("B", "E", TrustBuilder.CreateTrustTrue())); trusts.Add(TrustBuilder.CreateTrust("E", "D", TrustBuilder.CreateTrustTrue())); trusts.Add(TrustBuilder.CreateTrust("B", "F", TrustBuilder.CreateTrustTrue())); trusts.Add(TrustBuilder.CreateTrust("F", "G", TrustBuilder.CreateTrustTrue())); trusts.Add(TrustBuilder.CreateTrust("G", "D", TrustBuilder.CreateTrustTrue())); // Long way, no trust var search = BuildSearch(trusts); var query = new RequestQuery(); query.Issuers = new List <byte[]>(); query.Issuers.Add(trust1.Issuer.Id); query.Subjects = new List <SubjectQuery>(); query.Subjects.Add(new SubjectQuery { Id = trust3.Issuer.Subjects[0].Id, Type = trust3.Issuer.Subjects[0].IdType }); query.Scope = trust2.Issuer.Subjects[0].Scope; query.Claim = trust2.Issuer.Subjects[0].Claim; var result = search.Query(query); Assert.NotNull(result.Nodes); //Assert.IsTrue(result.Node.Children.Count == 1); //Assert.IsTrue(result.Node.Children[0].Children.Count == 1); //Console.WriteLine("Start id: " + search.GraphService.Graph.IdIndex[0].ConvertToHex()); // A PrintResult(result.Nodes, search.GraphService, 0); }
public void Search2() { var trust1 = TrustBuilder.CreateTrust("A", "B", TrustBuilder.CreateTrustTrue()); var trust2 = TrustBuilder.CreateTrust("B", "C", TrustBuilder.CreateTrustTrue()); var sb = new StringBuilder(); sb.Append("/api/query/"); var trusts = new List <TrustModel>(); trusts.Add(trust1); trusts.Add(trust2); var search = BuildSearch(trusts); var query = new RequestQuery(); query.Issuers = new List <byte[]>(); query.Issuers.Add(trust1.Issuer.Id); query.Subjects = new List <SubjectQuery>(); query.Subjects.Add(new SubjectQuery { Id = trust2.Issuer.Subjects[0].Id, Type = trust2.Issuer.Subjects[0].IdType }); query.Scope = trust2.Issuer.Subjects[0].Scope; query.Claim = trust2.Issuer.Subjects[0].Claim; var json = JsonConvert.SerializeObject(query, Formatting.Indented); Console.WriteLine(json); var result = search.Query(query); Assert.NotNull(result.Nodes); //Console.WriteLine("Start id: "+search.GraphService.Graph.IdIndex[0].ConvertToHex()); // A PrintResult(result.Nodes, search.GraphService, 1); PrintJson(result.Nodes); }