Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmppBrokers.cs
1using System.Collections.Generic;
2using System.Text;
3using System.Threading.Tasks;
5
7{
11 public static class XmppBrokers
12 {
13 private static readonly Dictionary<string, XmppBroker> brokers = new Dictionary<string, XmppBroker>();
14
25 public static string GetKey(string Host, int Port, bool Tls, string UserName, string Password, string PasswordMechanism)
26 {
27 StringBuilder sb = new StringBuilder();
28
29 sb.AppendLine(Host);
30 sb.AppendLine(Port.ToString());
31 sb.AppendLine(Tls.ToString());
32 sb.AppendLine(UserName);
33 sb.AppendLine(Password);
34 sb.AppendLine(PasswordMechanism);
35
36 return Hashes.ComputeSHA1HashString(Encoding.UTF8.GetBytes(sb.ToString()));
37 }
38
53 public static async Task<XmppBroker> GetBroker(XmppBrokerNode Node, string Key, string Host, int Port, bool Tls,
54 string UserName, string Password, string PasswordMechanism, bool TrustServer, bool AllowInsecureMechanisms)
55 {
56 XmppBroker Broker;
57
58 lock (brokers)
59 {
60 if (brokers.TryGetValue(Key, out Broker))
61 return Broker;
62 }
63
64 Broker = await XmppBroker.Create(Node, Host, Port, Tls, UserName, Password, PasswordMechanism, TrustServer, AllowInsecureMechanisms);
65
66 lock (brokers)
67 {
68 if (brokers.ContainsKey(Key))
69 {
70 Broker.Dispose();
71 return brokers[Key];
72 }
73 else
74 {
75 brokers[Key] = Broker;
76 return Broker;
77 }
78 }
79 }
80
85 public static void DestroyBroker(string Key)
86 {
87 XmppBroker Broker;
88
89 lock (brokers)
90 {
91 if (!brokers.TryGetValue(Key, out Broker))
92 return;
93
94 brokers.Remove(Key);
95 }
96
97 Broker.Dispose();
98 }
99
100 }
101}
Contains methods for simple hash calculations.
Definition: Hashes.cs:59
static string ComputeSHA1HashString(byte[] Data)
Computes the SHA-1 hash of a block of binary data.
Definition: Hashes.cs:274
Represents an XMPP broker.
Definition: XmppBroker.cs:14
static async Task< XmppBroker > Create(XmppBrokerNode Node, string Host, int Port, bool Tls, string UserName, string Password, string PasswordMechanism, bool TrustServer, bool AllowInsecureMechanisms)
Creates an XMPP broker
Definition: XmppBroker.cs:65
void Dispose()
IDisposable.Dispose
Definition: XmppBroker.cs:150
Static class managing connections to XMPP brokers.
Definition: XmppBrokers.cs:12
static string GetKey(string Host, int Port, bool Tls, string UserName, string Password, string PasswordMechanism)
Gets sort key for XMPP broker
Definition: XmppBrokers.cs:25
static async Task< XmppBroker > GetBroker(XmppBrokerNode Node, string Key, string Host, int Port, bool Tls, string UserName, string Password, string PasswordMechanism, bool TrustServer, bool AllowInsecureMechanisms)
Gets an XMPP broker object instance.
Definition: XmppBrokers.cs:53
static void DestroyBroker(string Key)
Destroys a broker object instance
Definition: XmppBrokers.cs:85
Node representing an XMPP broker.