Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmppBrokers.cs
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
44 public static XmppBroker GetCachedBroker(string Key)
45 {
46 lock (brokers)
47 {
48 if (brokers.TryGetValue(Key, out XmppBroker Broker))
49 return Broker;
50 else
51 return null;
52 }
53 }
54
69 public static async Task<XmppBroker> GetBroker(XmppBrokerNode Node, string Key, string Host, int Port, bool Tls,
70 string UserName, string Password, string PasswordMechanism, bool TrustServer, bool AllowInsecureMechanisms)
71 {
72 XmppBroker Broker;
73
74 lock (brokers)
75 {
76 if (brokers.TryGetValue(Key, out Broker))
77 return Broker;
78 }
79
80 Broker = await XmppBroker.Create(Node, Host, Port, Tls, UserName, Password, PasswordMechanism, TrustServer, AllowInsecureMechanisms);
81
82 lock (brokers)
83 {
84 if (brokers.ContainsKey(Key))
85 {
86 Broker.Dispose();
87 return brokers[Key];
88 }
89 else
90 {
91 brokers[Key] = Broker;
92 return Broker;
93 }
94 }
95 }
96
101 public static void DestroyBroker(string Key)
102 {
103 XmppBroker Broker;
104
105 lock (brokers)
106 {
107 if (!brokers.TryGetValue(Key, out Broker))
108 return;
109
110 brokers.Remove(Key);
111 }
112
113 Broker.Dispose();
114 }
115
116 }
117}
Contains methods for simple hash calculations.
Definition: Hashes.cs:57
static string ComputeSHA1HashString(byte[] Data)
Computes the SHA-1 hash of a block of binary data.
Definition: Hashes.cs:395
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 XmppBroker GetCachedBroker(string Key)
Gets an XMPP broker object instance, if available in the cache.
Definition: XmppBrokers.cs:44
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:69
static void DestroyBroker(string Key)
Destroys a broker object instance
Definition: XmppBrokers.cs:101
Node representing an XMPP broker.