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