Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NeuroLedgerModule.cs
1using System;
3using System.IO;
4using System.Threading;
5using System.Threading.Tasks;
6using System.Xml;
8using Waher.Events;
30
32{
36 [Singleton]
38 {
39 private const string DefaultDataProtectionAgreementTemplate = "25e2a2b5-4184-5cc8-a824-8b9e562c081b@legal.waher.se";
40 private static NeuroLedgerModule instance = null;
41
42 private NeuroLedgerClient client = null;
43 private NeuroLedgerProvider provider = null;
44 private HttpResource synchronizationResource;
45 private readonly ManualResetEvent p2pInitiationComplete = new ManualResetEvent(false);
46 private EndpointSecurity e2eEncryption;
47 private XmppServerlessMessaging serverlessMessaging;
48 private bool disposeE2eEncryption = false;
49 private bool started = false;
50 private bool presenceSent = false;
51
56 {
57 }
58
62 public async Task Start()
63 {
64 instance = this;
65
66 this.provider = Ledger.Provider as NeuroLedgerProvider;
67 if (this.provider is null)
68 return;
69
70 try
71 {
72 Database.ObjectInserted += Database_ObjectInserted;
73 Database.ObjectUpdated += Database_ObjectUpdated;
74 Database.ObjectDeleted += Database_ObjectDeleted;
75 Database.CollectionCleared += this.Database_CollectionCleared;
76 Database.CollectionRepaired += Database_CollectionRepaired;
77
78 RosterConfiguration.OnGetGroupSuggestions += this.RosterConfiguration_OnGetGroupSuggestions;
79
80 Gateway.OnAfterBackup += this.AfterBackup;
81
82 Gateway.XmppClient.EntityHashFunction = Security.HashFunction.SHA256;
83 Gateway.XmppClient.EntityNode = "http://waher.se/NL";
84 Gateway.XmppClient.SetTag("ShowE2E", true);
85
86 List<ISniffer> P2PSniffers = new List<ISniffer>();
88 bool HasSniffers = false;
89
90 foreach (ISniffer Sniffer in Gateway.XmppClient.Sniffers)
91 {
92 HasSniffers = true;
93
94 XmlFileSniffer = Sniffer as XmlFileSniffer;
95 if (!(XmlFileSniffer is null))
96 {
97 XmlFileSniffer = new XmlFileSniffer(Path.Combine(Gateway.AppDataFolder, "UPnP", "UPnP Log %YEAR%-%MONTH%-%DAY%T%HOUR%.xml"),
98 Path.Combine(Gateway.AppDataFolder, "Transforms", "SnifferXmlToHtml.xslt"), 7, BinaryPresentationMethod.ByteCount);
99
100 P2PSniffers.Add(XmlFileSniffer);
101 }
102 }
103
104 Gateway.XmppClient.OnStateChanged += this.XmppClient_OnStateChanged;
105
106 this.p2pInitiationComplete.Reset();
107 this.serverlessMessaging = new XmppServerlessMessaging("Neuro-Ledger", Gateway.XmppClient.FullJID,
108 (ushort)await RuntimeSettings.GetAsync("NL.P2P.LocalPort", 0),
109 (ushort)await RuntimeSettings.GetAsync("NL.P2P.ExternalPort", 0), P2PSniffers.ToArray());
110 this.serverlessMessaging.Network.OnStateChange += this.P2PNetwork_OnStateChange;
111 this.serverlessMessaging.OnNewXmppClient += this.ServerlessMessaging_OnNewXmppClient;
112 this.serverlessMessaging.OnResynch += this.ServerlessMessaging_OnResynch;
113
116 {
117 if (Networking.XMPP.P2P.EndpointSecurity.TryGetEndpointSecurity(
119 {
120 this.e2eEncryption = EndpointSecurity;
121 }
122 else
123 {
124 this.e2eEncryption = new EndpointSecurity(Gateway.XmppClient, this.serverlessMessaging, 128);
125 this.disposeE2eEncryption = true;
126 }
127 }
128
129 this.e2eEncryption.PeerUnavailable += this.E2eEncryption_PeerUnavailable;
130
131 Gateway.AvatarClient.E2E = this.e2eEncryption;
132
133 if (HasSniffers)
134 {
135 ChunkCounter Counter = new ChunkCounter(true, Gateway.XmppClient, false);
136 Gateway.XmppClient.OnReceiveText += Counter.ShortenChunks;
137 Gateway.XmppClient.OnInformation += Counter.RemoveChunkMessage;
138 Gateway.XmppClient.OnDisposed += Counter.Client_OnDisposed;
139
140 Counter = new ChunkCounter(false, Gateway.XmppClient, false);
141 Gateway.XmppClient.OnTransmitText += Counter.ShortenChunks;
142 Gateway.XmppClient.OnDisposed += Counter.Client_OnDisposed;
143 }
144
145 if (!(Gateway.HttpxProxy is null))
146 {
148 Gateway.HttpxProxy.ServerlessMessaging = this.serverlessMessaging;
149
151 Gateway.HttpxProxy.DefaultHttpxClient.E2e = this.e2eEncryption;
152 }
153
154 if (!(Gateway.HttpxServer is null))
155 Gateway.HttpxServer.RequiresE2e = true;
156
157 Gateway.ContractsClient.PetitionForIdentityReceived += this.ContractsClient_PetitionForIdentityReceived;
158
159 this.client = new NeuroLedgerClient(Gateway.XmppClient, this.e2eEncryption, Gateway.HttpServer, this.provider);
160 this.synchronizationResource = Gateway.HttpServer.Register(new SynchronizationResource("/NL/Synchronize", this.client, "User"));
161
162 this.p2pInitiationComplete.WaitOne(60000);
163
164 this.started = true;
165 Log.Informational("Neuro-Ledger successfully started.");
166
167 if (!(Gateway.XmppClient is null) && Gateway.XmppClient.State == XmppState.Connected)
168 {
169 if (!this.presenceSent)
170 await this.SetPresence();
171
172 await this.CheckContracts();
173 }
174 }
175 catch (Exception ex)
176 {
177 Log.Exception(ex);
178 }
179 }
180
181 private async Task ContractsClient_PetitionForIdentityReceived(object Sender, LegalIdentityPetitionEventArgs e)
182 {
184 {
185 bool Accept = !(Id.State == IdentityState.Compromised || Id.State == IdentityState.Rejected);
187
188 List<KeyValuePair<string, object>> Tags = new List<KeyValuePair<string, object>>()
189 {
190 new KeyValuePair<string, object>("RequestorFullJid", e.RequestorFullJid),
191 new KeyValuePair<string, object>("Provider", e.RequestorIdentity.Provider)
192 };
193
194 foreach (Property P in e.RequestorIdentity.Properties)
195 Tags.Add(new KeyValuePair<string, object>(P.Name, P.Value));
196
197 Log.Informational("Legal ID petitioned.", e.RequestedIdentityId, e.RequestedIdentityId, "IdPetition", Tags.ToArray());
198 }
199 else
201 }
202
203 private Task RosterConfiguration_OnGetGroupSuggestions(object Sender, SuggestionEventArgs e)
204 {
206 {
207 foreach (string Collection in NeuroLedgerProvider.Collections)
208 e.AddSuggestion(Collection);
209 }
210
211 return Task.CompletedTask;
212 }
213
217 public async Task Stop()
218 {
219 instance = null;
220 this.started = false;
221
222 if (!(this.client is null))
223 {
224 this.client.Dispose();
225 this.client = null;
226
227 if (this.disposeE2eEncryption)
228 this.e2eEncryption?.Dispose();
229
230 this.e2eEncryption = null;
231
232 if (!(this.serverlessMessaging is null))
233 {
234 await this.serverlessMessaging.DisposeAsync();
235 this.serverlessMessaging = null;
236 }
237
238 Gateway.OnAfterBackup -= this.AfterBackup;
239
240 RosterConfiguration.OnGetGroupSuggestions -= this.RosterConfiguration_OnGetGroupSuggestions;
241
242 Database.ObjectInserted -= Database_ObjectInserted;
243 Database.ObjectUpdated -= Database_ObjectUpdated;
244 Database.ObjectDeleted -= Database_ObjectDeleted;
245 Database.CollectionCleared -= this.Database_CollectionCleared;
246 Database.CollectionRepaired -= Database_CollectionRepaired;
247
248 Gateway.XmppClient.OnStateChanged -= this.XmppClient_OnStateChanged;
249
250 Gateway.ContractsClient.PetitionForIdentityReceived -= this.ContractsClient_PetitionForIdentityReceived;
251
252 Gateway.HttpServer.Unregister(this.synchronizationResource);
253 this.synchronizationResource = null;
254 }
255 }
256
257 private Task CheckContracts()
258 {
259 return this.CheckContracts(null);
260 }
261
262 private async Task CheckContracts(object P)
263 {
264 Contract Dpa;
265
266 if (!string.IsNullOrEmpty(LedgerConfiguration.Instance.DataProtectionAgreementId))
267 {
268 if (Gateway.ContractsClient is null)
269 {
270 Gateway.ScheduleEvent(this.CheckContracts, DateTime.Now.AddMinutes(1), null);
271 return;
272 }
273 else
275 }
276 else
277 {
278 try
279 {
280 string Xml = File.ReadAllText(Path.Combine(Gateway.AppDataFolder, "Contracts", "BlockSubscription.xml"));
281 XmlDocument Doc = XML.ParseXml(Xml, true);
282
283 ParsedContract Parsed = await Contract.Parse(Doc.DocumentElement, Gateway.ContractsClient, true);
284 Contract Template = Parsed.Contract;
285
286 string TemplateId = await RuntimeSettings.GetAsync("NL.DPA.TemplateId", DefaultDataProtectionAgreementTemplate);
287 if (string.IsNullOrEmpty(TemplateId))
288 {
289 Template = await Gateway.ContractsClient.CreateContractAsync(Template.ForMachines, Template.ForHumans,
290 Template.Roles, Template.Parts, Template.Parameters, Template.Visibility, Template.PartsMode, Template.Duration,
291 Template.ArchiveRequired, Template.ArchiveOptional, Template.SignAfter, Template.SignBefore, true);
292
293 await RuntimeSettings.SetAsync("NL.DPA.TemplateId", TemplateId = Template.ContractId);
294 }
295
296 Dpa = await Gateway.ContractsClient.CreateContractAsync(TemplateId, Array.Empty<Part>(),
297 new Parameter[]
298 {
299 new StringParameter()
300 {
301 Name = "Source",
302 Value = Gateway.XmppClient.BareJID
303 }
304 },
305 ContractVisibility.Public, ContractParts.Open, Template.Duration, Template.ArchiveRequired,
306 Template.ArchiveOptional, null, null, false);
307 }
308 catch (Exception ex)
309 {
310 Log.Error("Unable to create Data Protection Smart Contract.",
311 new KeyValuePair<string, object>("Message", ex.Message));
312 return;
313 }
314
315 LedgerConfiguration.Instance.DataProtectionAgreementId = Dpa.ContractId;
317 }
318
319 bool GeneratorSigned = false;
320
321 if (!(Dpa?.ClientSignatures is null))
322 {
324 {
325 if (Signature.Role == "Generator")
326 {
327 GeneratorSigned = true;
328 break;
329 }
330 }
331 }
332
333 if (!GeneratorSigned)
334 {
335 await Gateway.RequestContractSignature(Dpa, "Generator", "Data Protection Agreement required to be signed by " +
336 "designated parties before they can access blocks generated by the Neuro-Ledger on this machine.");
337 }
338 }
339
340 private static readonly Dictionary<Type, bool> processInLedger = new Dictionary<Type, bool>();
341
342 private static async Task<bool> Process(object Object)
343 {
344 Type T = Object.GetType();
345 bool Result;
346
347 lock (processInLedger)
348 {
349 if (processInLedger.TryGetValue(T, out Result))
350 return Result;
351 }
352
354 {
356 Result = Serializer.ArchiveObjects;
357 }
358 else
359 Result = false;
360
361 lock (processInLedger)
362 {
363 processInLedger[T] = Result;
364 }
365
366 return Result;
367 }
368
369 private static async void Database_ObjectInserted(object Sender, ObjectEventArgs e)
370 {
371 try
372 {
373 if (!await Process(e.Object))
374 return;
375
377 await Ledger.NewEntry(Obj);
378 }
379 catch (Exception ex)
380 {
381 Log.Exception(ex);
382 }
383 }
384
385 private static async void Database_ObjectUpdated(object Sender, ObjectEventArgs e)
386 {
387 try
388 {
389 if (!await Process(e.Object))
390 return;
391
393 await Ledger.UpdatedEntry(Obj);
394 }
395 catch (Exception ex)
396 {
397 Log.Exception(ex);
398 }
399 }
400
401 private static async void Database_ObjectDeleted(object Sender, ObjectEventArgs e)
402 {
403 try
404 {
405 if (!await Process(e.Object))
406 return;
407
409 await Ledger.DeletedEntry(Obj);
410 }
411 catch (Exception ex)
412 {
413 Log.Exception(ex);
414 }
415 }
416
417 private async Task Database_CollectionCleared(object Sender, CollectionEventArgs e)
418 {
419 try
420 {
421 string Collection = e.Collection;
422
423 if (Array.IndexOf(this.provider.Collections, Collection) >= 0)
424 await Ledger.ClearedCollection(Collection);
425 }
426 catch (Exception ex)
427 {
428 Log.Exception(ex);
429 }
430 }
431
432 private async Task XmppClient_OnStateChanged(object Sender, XmppState NewState)
433 {
434 try
435 {
436 if (Gateway.XmppClient is null)
437 return;
438
439 switch (NewState)
440 {
441 case XmppState.RequestingSession:
442 if (!(this.serverlessMessaging is null))
443 this.serverlessMessaging.FullJid = Gateway.XmppClient.FullJID;
444 break;
445
446 case XmppState.Connected:
447 foreach (RosterItem Item in Gateway.XmppClient.Roster)
448 {
451 }
452
453 await this.CheckContracts();
454 break;
455 }
456 }
457 catch (Exception ex)
458 {
459 Log.Exception(ex);
460 }
461 }
462
463 private Task ServerlessMessaging_OnNewXmppClient(object Sender, PeerConnectionEventArgs e)
464 {
465 XmppClient Client = e.Client;
467 HttpxClient HttpxClient = new HttpxClient(Client, this.e2eEncryption, 32768)
468 {
469 PostResource = Gateway.HttpxProxy.PostResource
470 };
472 bool Sniffers = false;
473
474 HttpxServer.RequiresE2e = true;
475
476 Client.SetTag("HttpxServer", HttpxServer);
477 Client.SetTag("HttpxClient", HttpxClient);
478 Client.SetTag("ShowE2E", false);
479 Client.SetTag("ExpectedSender", e.RemoteJid.ToLower());
480
481 Client.OnValidateSender += this.PeerClient_OnValidateSender;
482 Client.OnDisposed += this.P2PClient_OnDisposed;
483
484 this.e2eEncryption.RegisterHandlers(Client);
485
486 try
487 {
488 foreach (ISniffer Sniffer in Gateway.XmppClient.Sniffers)
489 {
490 Sniffers = true;
491
492 XmlFileSniffer = Sniffer as XmlFileSniffer;
493 if (!(XmlFileSniffer is null) && Types.TryGetModuleParameter("AppData", out string AppDataFolder))
494 {
495 XmlFileSniffer = new XmlFileSniffer(AppDataFolder + "XMPP" + Path.DirectorySeparatorChar +
496 e.RemoteJid + Path.DirectorySeparatorChar + "XMPP Log %YEAR%-%MONTH%-%DAY%T%HOUR%.xml",
497 AppDataFolder + "Transforms" + Path.DirectorySeparatorChar + "SnifferXmlToHtml.xslt",
498 7, BinaryPresentationMethod.ByteCount);
499
500 Client.Add(XmlFileSniffer);
501 }
502 else
503 Client.Add(Sniffer);
504 }
505 }
506 catch (Exception ex)
507 {
508 Log.Exception(ex);
509 }
510
511 if (Sniffers)
512 {
513 ChunkCounter Counter = new ChunkCounter(true, Client, true);
514 Client.OnReceiveText += Counter.ShortenChunks;
515 Client.OnInformation += Counter.RemoveChunkMessage;
516 Client.OnDisposed += Counter.Client_OnDisposed;
517
518 Counter = new ChunkCounter(false, Client, true);
519 Client.OnTransmitText += Counter.ShortenChunks;
520 Client.OnDisposed += Counter.Client_OnDisposed;
521 }
522
523 return Task.CompletedTask;
524 }
525
526 private Task ServerlessMessaging_OnResynch(object Sender, ResynchEventArgs e)
527 {
528 this.e2eEncryption?.SynchronizeE2e(e.RemoteFullJid, (Sender2, e2) =>
529 {
530 e.Done(e2.Ok);
531 return Task.CompletedTask;
532 });
533
534 return Task.CompletedTask;
535 }
536
537 private Task PeerClient_OnValidateSender(object Sender, ValidateSenderEventArgs e)
538 {
539 if (!e.Client.TryGetTag("ExpectedSender", out object Obj) || !(Obj is string s) || string.Compare(e.From, s, true) != 0)
540 e.Reject();
541
542 return Task.CompletedTask;
543 }
544
545 private async Task P2PClient_OnDisposed(object Sender, EventArgs e)
546 {
547 if (Sender is XmppClient Client)
548 {
549 this.e2eEncryption?.UnregisterHandlers(Client);
550
551 if (Client.TryGetTag("HttpxServer", out object Obj))
552 {
553 if (Obj is IDisposableAsync DisposableAsync)
554 await DisposableAsync.DisposeAsync();
555 else if (Obj is IDisposable Disposable)
556 Disposable.Dispose();
557 }
558
559 if (Client.TryGetTag("HttpxClient", out Obj))
560 {
561 if (Obj is IDisposableAsync DisposableAsync)
562 await DisposableAsync.DisposeAsync();
563 else if (Obj is IDisposable Disposable)
564 Disposable.Dispose();
565 }
566 }
567 }
568
569 private async Task P2PNetwork_OnStateChange(object _, PeerToPeerNetworkState NewState)
570 {
571 if (this.serverlessMessaging is null)
572 return;
573
574 try
575 {
576 PeerToPeerNetwork P2P = this.serverlessMessaging.Network;
577
578 switch (NewState)
579 {
580 case PeerToPeerNetworkState.Ready:
581 Log.Informational("Gateway available on Peer-to-Peer network: " + P2P.ExternalEndpoint.ToString());
582
583 P2P.DesiredLocalPort = (ushort)P2P.LocalEndpoint.Port;
584 P2P.DesiredExternalPort = (ushort)P2P.ExternalEndpoint.Port;
585
586 await RuntimeSettings.SetAsync("NL.P2P.LocalPort", P2P.LocalEndpoint.Port);
587 await RuntimeSettings.SetAsync("NL.P2P.ExternalPort", P2P.ExternalEndpoint.Port);
588
589 if (this.started && Gateway.XmppClient.State == XmppState.Connected)
590 await this.SetPresence();
591
592 this.p2pInitiationComplete.Set();
593 break;
594
595 case PeerToPeerNetworkState.Error:
596 P2P.DesiredLocalPort = 0;
597 P2P.DesiredExternalPort = 0;
598
599 this.p2pInitiationComplete.Set();
600 break;
601 }
602 }
603 catch (Exception ex)
604 {
605 Log.Exception(ex);
606 }
607 }
608
609 private Task E2eEncryption_PeerUnavailable(object Sender, PresenceEventArgs e)
610 {
611 this.serverlessMessaging?.RemovePeerAddresses(e.From);
612 return Task.CompletedTask;
613 }
614
618 public static XmppServerlessMessaging ServerlessMessaging
619 {
620 get { return instance?.serverlessMessaging; }
621 }
622
626 public static EndpointSecurity E2eEncryption
627 {
628 get { return instance?.e2eEncryption; }
629 }
630
631 private async Task SetPresence()
632 {
633 if (!(Gateway.XmppClient is null) && this.started)
634 {
636 this.presenceSent = true;
637 }
638 }
639
640 private async Task AfterBackup(object Sender, EventArgs e)
641 {
642 try
643 {
644 this.e2eEncryption.GenerateNewKey();
645 await this.SetPresence();
646 }
647 catch (Exception ex)
648 {
649 Log.Exception(ex);
650 }
651 }
652
653 private static Task Database_CollectionRepaired(object Sender, CollectionEventArgs e)
654 {
655 return LedgerConfiguration.Instance?.Database_CollectionRepaired(Sender, e) ?? Task.CompletedTask;
656 }
657
661 public static Task ProcessBlockRequest(Networking.HTTP.HeaderFields.HttpFieldAccept Accept, HttpResponse Response, BlockReference Ref)
662 {
663 return instance.client.ProcessBlockRequest(Accept, Response, Ref);
664 }
665
666 }
667}
Helps with common XML-related tasks.
Definition: XML.cs:21
static XmlDocument ParseXml(string Xml)
Parses an XML Document from its string representation.
Definition: XML.cs:713
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:14
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Definition: Log.cs:1657
static void Error(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an error event.
Definition: Log.cs:692
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Definition: Log.cs:344
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static HttpxProxy HttpxProxy
HTTPX Proxy resource
Definition: Gateway.cs:4128
static HttpServer HttpServer
HTTP Server
Definition: Gateway.cs:4118
static string AppDataFolder
Application data folder.
Definition: Gateway.cs:3132
static async Task RequestContractSignature(Contract Contract, string Role, string Purpose)
Requests the operator to sign a smart contract.
Definition: Gateway.cs:5326
static ContractsClient ContractsClient
XMPP Contracts Client, if such a compoent is available on the XMPP broker.
Definition: Gateway.cs:5299
static DateTime ScheduleEvent(Action< object > Callback, DateTime When, object State)
Schedules a one-time event.
Definition: Gateway.cs:4253
static HttpxServer HttpxServer
HTTPX Server
Definition: Gateway.cs:4123
static XmppClient XmppClient
XMPP Client connection of gateway.
Definition: Gateway.cs:4038
Event arguments for suggestion event handlers.
void AddSuggestion(string Suggestion)
Adds a suggestion.
ISniffer[] Sniffers
Registered sniffers.
virtual void Add(ISniffer Sniffer)
ICommunicationLayer.Add
Base class for all HTTP resources.
Definition: HttpResource.cs:23
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
HttpResource Register(HttpResource Resource)
Registers a resource with the server.
Definition: HttpServer.cs:1568
bool Unregister(HttpResource Resource)
Unregisters a resource from the server.
Definition: HttpServer.cs:1743
Manages a peer-to-peer network that can receive connections from outside of a NAT-enabled firewall.
IPEndPoint ExternalEndpoint
External IP Endpoint.
ushort DesiredExternalPort
Desired external port number. If 0, a dynamic port number will be assigned.
Outputs sniffed data to an XML file.
Represents a digital signature on a contract.
Contains the definition of a contract
Definition: Contract.cs:22
static Task< ParsedContract > Parse(XmlDocument Xml)
Validates a contract XML Document, and returns the contract definition in it.
Definition: Contract.cs:441
Parameter[] Parameters
Defined parameters for the smart contract.
Definition: Contract.cs:267
Duration? ArchiveRequired
Requied time to archive a signed smart contract, after it becomes obsolete.
Definition: Contract.cs:202
ClientSignature[] ClientSignatures
Client signatures of the contract.
Definition: Contract.cs:309
HumanReadableText[] ForHumans
Human-readable contents of the contract.
Definition: Contract.cs:300
Duration? ArchiveOptional
Optional time to archive a signed smart contract, after it becomes obsolete, and after its required a...
Definition: Contract.cs:211
XmlElement ForMachines
Machine-readable contents of the contract.
Definition: Contract.cs:276
Role[] Roles
Roles defined in the smart contract.
Definition: Contract.cs:240
DateTime? SignAfter
Signatures will only be accepted after this point in time.
Definition: Contract.cs:166
ContractParts PartsMode
How parts are defined in the smart contract.
Definition: Contract.cs:249
string ContractId
Contract identity
Definition: Contract.cs:65
Part[] Parts
Defined parts for the smart contract.
Definition: Contract.cs:258
Duration? Duration
Duration of the contract. Is counted from the time it is signed by the required parties.
Definition: Contract.cs:193
DateTime? SignBefore
Signatures will only be accepted until this point in time.
Definition: Contract.cs:175
ContractVisibility Visibility
Contrat Visibility
Definition: Contract.cs:184
Adds support for legal identities, smart contracts and signatures to an XMPP client.
Task PetitionIdentityResponseAsync(string LegalId, string PetitionId, string RequestorFullJid, bool Response)
Sends a response to a petition for information about a legal identity. When a petition is received,...
Task< Contract > GetContractAsync(string ContractId)
Gets a contract
const string E2eKeySemaphoreName
Name of semaphore used to synchronize access to End-to-End Encryption keys used for legal identities ...
Task< Contract > CreateContractAsync(XmlElement ForMachines, HumanReadableText[] ForHumans, Role[] Roles, Part[] Parts, Parameter[] Parameters, ContractVisibility Visibility, ContractParts PartsMode, Duration? Duration, Duration? ArchiveRequired, Duration? ArchiveOptional, DateTime? SignAfter, DateTime? SignBefore, bool CanActAsTemplate)
Creates a new contract.
LegalIdentity RequestorIdentity
Legal Identity of requesting entity.
Abstract base class for contractual parameters
Definition: Parameter.cs:17
Contains information about a parsed contract.
Class defining a part in a contract
Definition: Part.cs:30
Abstract base class of signatures
Definition: Signature.cs:10
string Id
ID attribute of message stanza.
Event arguments for presence events.
string From
From where the presence was received.
Event arguments for sender validation events.
string From
From where the stanza was received.
void Reject()
Called from an event handler to reject the sender.
IEndToEndEncryption E2e
Optional end-to-end encryption interface to use in requests.
Definition: HttpxClient.cs:88
XmppServerlessMessaging ServerlessMessaging
Serverless messaging manager.
Definition: HttpxProxy.cs:107
HttpxClient DefaultHttpxClient
Default HTTPX client.
Definition: HttpxProxy.cs:141
Task ProcessBlockRequest(HTTP.HeaderFields.HttpFieldAccept Accept, HTTP.HttpResponse Response, BlockReference Ref)
TODO
Class managing end-to-end encryption.
virtual void RegisterHandlers(XmppClient Client)
Registers XMPP stanza handlers
virtual void UnregisterHandlers(XmppClient Client)
Unregisters XMPP stanza handlers
Task SynchronizeE2e(string FullJID, EventHandlerAsync< IqResultEventArgs > Callback)
Synchronizes End-to-End Encryption and Peer-to-Peer connectivity parameters with a remote entity.
void GenerateNewKey()
Generates new local keys.
virtual void Dispose()
IDisposable.Dispose
XmppClient Client
XMPP client, if aquired, or null otherwise.
Peer connection event arguments.
string RemoteFullJid
JID of the remote end-point.
Class managing peer-to-peer serveless XMPP communication.
PeerToPeerNetwork Network
Peer-to-peer network.
async Task RemovePeerAddresses(string FullJID)
Removes a JID from the recognized set of JIDs.
Maintains information about an item in the roster.
Definition: RosterItem.cs:75
string BareJid
Bare JID of the roster item.
Definition: RosterItem.cs:276
PendingSubscription PendingSubscription
If there's a pending unanswered presence subscription or unsubscription request made to the contact.
Definition: RosterItem.cs:291
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:58
XmppState State
Current state of connection.
Definition: XmppClient.cs:985
Task RequestPresenceSubscription(string BareJid)
Requests subscription of presence information from a contact.
Definition: XmppClient.cs:4969
void SetTag(string TagName, object Tag)
Sets a tag value.
Definition: XmppClient.cs:7312
Task SetPresence()
Sets the presence of the connection. Add a CustomPresenceXml event handler to add custom presence XML...
Definition: XmppClient.cs:4825
bool TryGetTag(string TagName, out object Tag)
Tries to get a tag from the client. Tags can be used to attached application specific objects to the ...
Definition: XmppClient.cs:7270
RosterItem[] Roster
Items in the roster.
Definition: XmppClient.cs:4720
Event arguments for collection events.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static async Task Update(object Object)
Updates an object in the database.
Definition: Database.cs:1211
static Task< GenericObject > Generalize(object Object)
Creates a generalized representation of an object.
Definition: Database.cs:2473
Static interface for ledger persistence. In order to work, a ledger provider has to be assigned to it...
Definition: Ledger.cs:14
static async Task DeletedEntry(object Object)
Deletes an entry in the ledger.
Definition: Ledger.cs:158
static ILedgerProvider Provider
Registered ledger provider.
Definition: Ledger.cs:83
static async Task NewEntry(object Object)
Adds an entry to the ledger.
Definition: Ledger.cs:118
static async Task ClearedCollection(string Collection)
Clears a collection in the ledger.
Definition: Ledger.cs:178
static async Task UpdatedEntry(object Object)
Updates an entry in the ledger.
Definition: Ledger.cs:138
string[] Collections
Array of collections archived in the ledger.
Task< ObjectSerializer > GetObjectSerializerEx(object Object)
Gets the object serializer corresponding to a specific object.
Contains a reference to a block in the ledger.
Event arguments for database object events.
Generic object. Contains a sequence of properties.
Serializes a class, taking into account attributes defined in Attributes.
bool ArchiveObjects
If objects of this type can be archived.
Static class that dynamically manages types and interfaces available in the runtime environment.
Definition: Types.cs:15
static bool TryGetModuleParameter(string Name, out object Value)
Tries to get a module parameter value.
Definition: Types.cs:607
Static class managing persistent settings.
static async Task< string > GetAsync(string Key, string DefaultValue)
Gets a string-valued setting.
static async Task< bool > SetAsync(string Key, string Value)
Sets a string-valued setting.
Represents a named semaphore, i.e. an object, identified by a name, that allows single concurrent wri...
Definition: Semaphore.cs:19
Static class of application-wide semaphores that can be used to order access to editable objects.
Definition: Semaphores.cs:17
static async Task< Semaphore > BeginWrite(string Key)
Waits until the semaphore identified by Key is ready for writing. Each call to BeginWrite must be fo...
Definition: Semaphores.cs:91
static Task ProcessBlockRequest(Networking.HTTP.HeaderFields.HttpFieldAccept Accept, HttpResponse Response, BlockReference Ref)
TODO
string DataProtectionAgreementId
Data Protection Agreement to use before allowing access to the Neuro-Ledger.
static LedgerConfiguration Instance
Current instance of configuration.
Allows operators to manually start network synchronization.
Interface for asynchronously disposable objects.
Interface for sniffers. Sniffers can be added to ICommunicationLayer classes to eavesdrop on communic...
Definition: ISniffer.cs:10
Interface for late-bound modules loaded at runtime.
Definition: IModule.cs:9
Definition: ImplTypes.g.cs:58
PeerToPeerNetworkState
State of Peer-to-peer network.
BinaryPresentationMethod
How binary data is to be presented.
IdentityState
Lists recognized legal identity states.
ContractParts
How the parts of the contract are defined.
Definition: Part.cs:9
ContractVisibility
Visibility types for contracts.
Definition: Enumerations.cs:56
Availability
Resource availability.
Definition: Availability.cs:7
XmppState
State of XMPP connection.
Definition: XmppState.cs:7
PendingSubscription
Pending subscription states.
Definition: RosterItem.cs:54