Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ProxyPorts.cs
1using System.Collections.Generic;
2using System.Text;
3using System.Threading.Tasks;
5
7{
11 public static class ProxyPorts
12 {
13 private static readonly Dictionary<string, ProxyPort> proxies = new Dictionary<string, ProxyPort>();
14
26 public static string GetKey(string Host, int Port, bool Tls, bool TrustServer, int ListeningPort, bool AuthorizedAccess, IpCidr[] RemoteIps)
27 {
28 StringBuilder sb = new StringBuilder();
29
30 sb.AppendLine(Host);
31 sb.AppendLine(Port.ToString());
32 sb.AppendLine(Tls.ToString());
33 sb.AppendLine(TrustServer.ToString());
34 sb.AppendLine(ListeningPort.ToString());
35 sb.AppendLine(AuthorizedAccess.ToString());
36
37 if (!(RemoteIps is null))
38 {
39 foreach (IpCidr Range in RemoteIps)
40 {
41 sb.AppendLine(Range.Address.ToString());
42 sb.AppendLine(Range.Range.ToString());
43 }
44 }
45
46 return Hashes.ComputeSHA1HashString(Encoding.UTF8.GetBytes(sb.ToString()));
47 }
48
62 public static async Task<ProxyPort> GetProxy(IpHostPortProxy Node, string Key, string Host, int Port, bool Tls, bool TrustServer, int ListeningPort,
63 bool AuthorizedAccess, IpCidr[] RemoteIps)
64 {
65 ProxyPort Proxy;
66
67 lock (proxies)
68 {
69 if (!proxies.TryGetValue(Key, out Proxy))
70 Proxy = null;
71 }
72
73 if (!(Proxy is null))
74 return Proxy;
75 else
76 {
77 Proxy = await ProxyPort.Create(Node, Host, Port, Tls, TrustServer, ListeningPort, AuthorizedAccess, RemoteIps);
78
79 lock (proxies)
80 {
81 if (proxies.ContainsKey(Key))
82 {
83 Proxy.Dispose();
84 return proxies[Key];
85 }
86 else
87 {
88 proxies[Key] = Proxy;
89 return Proxy;
90 }
91 }
92 }
93 }
94
99 public static void DestroyProxy(string Key)
100 {
101 ProxyPort Proxy;
102
103 lock (proxies)
104 {
105 if (!proxies.TryGetValue(Key, out Proxy))
106 return;
107
108 proxies.Remove(Key);
109 }
110
111 Proxy.Dispose();
112 }
113
114 }
115}
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
IP Address Rangee, expressed using CIDR format.
Definition: IpCidr.cs:10
IPAddress Address
Parsed IP Address
Definition: IpCidr.cs:41
Node representing a proxy port node.
Node acting as a TCP/IP proxy opening a port for incoming communication and proxying it to another po...
Definition: ProxyPort.cs:25
void Remove(ProxyClientConncetion Connection)
Removes a proxy client connection.
Definition: ProxyPort.cs:482
void Dispose()
IDisposable.Dispose
Definition: ProxyPort.cs:473
static async Task< ProxyPort > Create(IpHostPortProxy Node, string Host, int Port, bool Tls, bool TrustServer, int ListeningPort, bool AuthorizedAccess, IpCidr[] RemoteIps)
Creates a port proxy object.
Definition: ProxyPort.cs:66
Static class managing Port Proxies.
Definition: ProxyPorts.cs:12
static async Task< ProxyPort > GetProxy(IpHostPortProxy Node, string Key, string Host, int Port, bool Tls, bool TrustServer, int ListeningPort, bool AuthorizedAccess, IpCidr[] RemoteIps)
Gets a TCP/IP proxy node
Definition: ProxyPorts.cs:62
static void DestroyProxy(string Key)
Destroys a proxy node
Definition: ProxyPorts.cs:99
static string GetKey(string Host, int Port, bool Tls, bool TrustServer, int ListeningPort, bool AuthorizedAccess, IpCidr[] RemoteIps)
Gets sort key for Port Proxy
Definition: ProxyPorts.cs:26