Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ProxyDomain.cs
1using System;
3using System.Text;
4using System.Threading.Tasks;
9using Waher.Things;
12
14{
19 {
20 private readonly ICommunicationLayer comLayer;
21
25 public ProxyDomain()
26 : base(null, null)
27 {
28 this.LocalDomain = string.Empty;
29 this.RemoteDomain = string.Empty;
30 this.RemoteFolder = string.Empty;
31 this.RemotePort = 0;
32 this.Encrypted = false;
33 this.UseSession = false;
34 this.TimeoutMs = 30000;
35 this.Privilege = string.Empty;
36 }
37
54 : base(Source, Parent)
55 {
56 this.LocalDomain = LocalDomain;
57 this.RemoteDomain = RemoteDomain;
58 this.RemoteFolder = RemoteFolder;
59 this.RemotePort = RemotePort;
60 this.Encrypted = Encrypted;
61 this.UseSession = UseSession;
62 this.TimeoutMs = TimeoutMs;
63 this.Privilege = Privilege;
64 this.comLayer = CommunicationLayer;
65 }
66
70 [Page(7, "Configuration")]
71 [Header(139, "Local Domain:")]
72 [ToolTip(140, "Local Domain that will act as a reverse proxy.")]
73 [Required]
74 public string LocalDomain { get; set; }
75
79 [Page(7, "Configuration")]
80 [Header(87, "Remote Domain:")]
81 [ToolTip(88, "Domain of web server to forward requests to.")]
82 [Required]
83 public string RemoteDomain { get; set; }
84
88 [Page(7, "Configuration")]
89 [Header(89, "Remote Folder:")]
90 [ToolTip(90, "Base folder on remote domain that requests will be forwarded to.")]
91 public string RemoteFolder { get; set; }
92
96 [Page(7, "Configuration")]
97 [Header(91, "Remote Port:")]
98 [ToolTip(92, "Port number of remote domain that requests will be forwarded to.")]
99 [Range(1, 65535)]
100 [Required]
101 public int RemotePort { get; set; }
102
106 [Page(7, "Configuration")]
107 [Header(93, "Use encryption.")]
108 [ToolTip(94, "If forwarded requests are encrypted (HTTPS) or not (HTTP).")]
109 [Required]
110 public bool Encrypted { get; set; }
111
115 [Page(7, "Configuration")]
116 [Header(95, "Use proxy-session.")]
117 [ToolTip(96, "If the proxy uses a session itself.")]
118 [Text(TextPosition.AfterField, 97, "Note: By making the proxy use a proxy-session itself, the broker can add SSO token information in forwarded requests, making underlying services aware of the currently logged in user identity.")]
119 public bool UseSession { get; set; }
120
124 [Page(7, "Configuration")]
125 [Header(34, "Timeout (ms):")]
126 [ToolTip(98, "Timeout afforded to forwarded requests, in milliseconds, before they are assumed to have failed.")]
127 [Range(1, 120 * 1000)]
128 [Text(TextPosition.AfterField, 63, "Note: Changes will take effect after broker has been restarted.")]
129 public int TimeoutMs { get; set; }
130
134 [Page(7, "Configuration")]
135 [Header(247, "Required Privilege:")]
136 [ToolTip(248, "Required privilege to access the resource. If not specified, the resource is public.")]
137 public string Privilege { get; set; }
138
142 public override string NodeId => this.LocalDomain;
143
148 public override Task<string> GetTypeNameAsync(Language Language) => Language.GetStringAsync(typeof(GatewayConfigSource), 141, "Reverse Proxy Domain");
149
155 public override Task<bool> AcceptsParentAsync(INode Parent)
156 {
157 return Task.FromResult(Parent is WebServer);
158 }
159
166 public override async Task<IEnumerable<Parameter>> GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
167 {
168 LinkedList<Parameter> Parameters = new LinkedList<Parameter>();
170
171 StringBuilder sb = new StringBuilder();
172
173 sb.Append("http");
174 if (this.Encrypted)
175 sb.Append('s');
176
177 sb.Append("://");
178 sb.Append(this.RemoteDomain);
179
181 {
182 sb.Append(':');
183 sb.Append(this.RemotePort.ToString());
184 }
185
186 sb.Append(this.RemoteFolder);
187
188 Parameters.AddLast(new StringParameter("Location", await Namespace.GetStringAsync(82, "Location"), sb.ToString()));
189 Parameters.AddLast(new BooleanParameter("UseSession", await Namespace.GetStringAsync(53, "Session"), this.UseSession));
190 Parameters.AddLast(new Int32Parameter("TimeoutMs", await Namespace.GetStringAsync(54, "Timeout (ms)"), this.TimeoutMs));
191 Parameters.AddLast(new StringParameter("Privilege", await Namespace.GetStringAsync(249, "Privilege"), this.Privilege));
192
193 return Parameters;
194 }
195
196 #region ICommunicationLayer
197
202 public bool DecoupledEvents => this.comLayer?.DecoupledEvents ?? false;
203
208 public void Add(ISniffer Sniffer)
209 {
210 this.comLayer?.Add(Sniffer);
211 }
212
217 public void AddRange(IEnumerable<ISniffer> Sniffers)
218 {
219 this.comLayer?.AddRange(Sniffers);
220 }
221
227 public bool Remove(ISniffer Sniffer) => this.comLayer?.Remove(Sniffer) ?? false;
228
232 public ISniffer[] Sniffers => this.comLayer?.Sniffers;
233
237 public bool HasSniffers => this.comLayer?.HasSniffers ?? false;
238
243 public IEnumerator<ISniffer> GetEnumerator() => this.comLayer?.GetEnumerator();
244
249 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => this.comLayer?.GetEnumerator();
250
255 public void ReceiveBinary(int Count) => this.comLayer?.ReceiveBinary(Count);
256
263 public void ReceiveBinary(bool ConstantBuffer, byte[] Data) => this.comLayer?.ReceiveBinary(ConstantBuffer, Data);
264
273 public void ReceiveBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count) => this.comLayer?.ReceiveBinary(ConstantBuffer, Data, Offset, Count);
274
279 public void TransmitBinary(int Count) => this.comLayer?.TransmitBinary(Count);
280
287 public void TransmitBinary(bool ConstantBuffer, byte[] Data) => this.comLayer?.TransmitBinary(ConstantBuffer, Data);
288
297 public void TransmitBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count) => this.comLayer?.TransmitBinary(ConstantBuffer, Data, Offset, Count);
298
303 public void ReceiveText(string Text) => this.comLayer?.ReceiveText(Text);
304
309 public void TransmitText(string Text) => this.comLayer?.TransmitText(Text);
310
315 public void Information(string Comment) => this.comLayer?.Information(Comment);
316
321 public void Warning(string Warning) => this.comLayer?.Warning(Warning);
322
327 public void Error(string Error) => this.comLayer?.Error(Error);
328
333 public void Exception(Exception Exception) => this.comLayer?.Exception(Exception);
334
339 public void Exception(string Exception) => this.comLayer?.Exception(Exception);
340
346 public void ReceiveBinary(DateTime Timestamp, int Count) => this.comLayer?.ReceiveBinary(Timestamp, Count);
347
355 public void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data) => this.comLayer?.ReceiveBinary(Timestamp, ConstantBuffer, Data);
356
366 public void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count) => this.comLayer?.ReceiveBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
367
373 public void TransmitBinary(DateTime Timestamp, int Count) => this.comLayer?.TransmitBinary(Timestamp, Count);
374
382 public void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data) => this.comLayer?.TransmitBinary(Timestamp, ConstantBuffer, Data);
383
393 public void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count) => this.comLayer?.TransmitBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
394
400 public void ReceiveText(DateTime Timestamp, string Text) => this.comLayer?.ReceiveText(Timestamp, Text);
401
407 public void TransmitText(DateTime Timestamp, string Text) => this.comLayer?.TransmitText(Timestamp, Text);
408
414 public void Information(DateTime Timestamp, string Comment) => this.comLayer?.Information(Timestamp, Comment);
415
421 public void Warning(DateTime Timestamp, string Warning) => this.comLayer?.Warning(Timestamp, Warning);
422
428 public void Error(DateTime Timestamp, string Error) => this.comLayer?.Error(Timestamp, Error);
429
435 public void Exception(DateTime Timestamp, string Exception) => this.comLayer?.Exception(Timestamp, Exception);
436
442 public void Exception(DateTime Timestamp, Exception Exception) => this.comLayer?.Exception(Timestamp, Exception);
443
444 #endregion
445
446 }
447}
Simple base class for classes implementing communication protocols.
Implements an HTTP server.
Definition: HttpServer.cs:41
const int DefaultHttpPort
Default HTTP Port (80).
Definition: HttpServer.cs:45
const int DefaultHttpsPort
Default HTTPS port (443).
Definition: HttpServer.cs:50
Contains information about a language.
Definition: Language.cs:17
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Definition: Language.cs:209
async Task< Namespace > GetNamespaceAsync(string Name)
Gets the namespace object, given its name, if available.
Definition: Language.cs:99
Contains information about a namespace in a language.
Definition: Namespace.cs:17
Task< LanguageString > GetStringAsync(int Id)
Gets the string object, given its ID, if available.
Definition: Namespace.cs:65
Abstract base class for gateway configuration nodes.
virtual INode Parent
Parent Node, or null if a root node.
GatewayConfigSource Source
Source hosting the node.
Defines a proxy domain to act as a reverse proxy for a specific domain name.
Definition: ProxyDomain.cs:19
string RemoteDomain
Location client is redirected to.
Definition: ProxyDomain.cs:83
ProxyDomain()
Defines a proxy domain to act as a reverse proxy for a specific domain name.
Definition: ProxyDomain.cs:25
void TransmitText(DateTime Timestamp, string Text)
Called when text has been transmitted.
void AddRange(IEnumerable< ISniffer > Sniffers)
Adds a range of sniffers to the node.
Definition: ProxyDomain.cs:217
void TransmitBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
void TransmitBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
void ReceiveText(DateTime Timestamp, string Text)
Called when text has been received.
void ReceiveBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
string RemoteFolder
If sub-paths should be included in the redirection.
Definition: ProxyDomain.cs:91
override Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a presumptive parent, i.e. can be added to that parent (if that parent accepts th...
Definition: ProxyDomain.cs:155
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
void Warning(string Warning)
Called to inform the viewer of a warning state.
void Exception(string Exception)
Called to inform the viewer of an exception state.
void Information(string Comment)
Called to inform the viewer of something.
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
Definition: ProxyDomain.cs:202
void Add(ISniffer Sniffer)
Adds a sniffer to the node.
Definition: ProxyDomain.cs:208
void Error(string Error)
Called to inform the viewer of an error state.
void Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
void TransmitText(string Text)
Called when text has been transmitted.
bool HasSniffers
If there are sniffers registered on the object.
Definition: ProxyDomain.cs:237
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
int TimeoutMs
If redirection is permanent (true) or temporary (false).
Definition: ProxyDomain.cs:129
void Exception(DateTime Timestamp, string Exception)
Called to inform the viewer of an exception state.
int RemotePort
If redirection is permanent (true) or temporary (false).
Definition: ProxyDomain.cs:101
IEnumerator< ISniffer > GetEnumerator()
Returns an enumerator that iterates through the collection.
override async Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
Definition: ProxyDomain.cs:166
bool UseSession
If forwarded requests are encrypted (HTTPS) or not (HTTP).
Definition: ProxyDomain.cs:119
void TransmitBinary(int Count)
Called when binary data has been transmitted.
void Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
bool Encrypted
If forwarded requests are encrypted (HTTPS) or not (HTTP).
Definition: ProxyDomain.cs:110
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
void Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
void TransmitBinary(DateTime Timestamp, int Count)
Called when binary data has been transmitted.
void ReceiveBinary(DateTime Timestamp, int Count)
Called when binary data has been received.
void Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
void ReceiveBinary(int Count)
Called when binary data has been received.
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
void ReceiveBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
void ReceiveText(string Text)
Called when text has been received.
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
ProxyDomain(GatewayConfigSource Source, WebServer Parent, string LocalDomain, string RemoteDomain, string RemoteFolder, int RemotePort, bool Encrypted, bool UseSession, int TimeoutMs, string Privilege, ICommunicationLayer CommunicationLayer)
Defines a proxy domain to act as a reverse proxy for a specific domain name.
Definition: ProxyDomain.cs:52
string Privilege
Required privilege to access the resource. If not specified, the resource is public.
Definition: ProxyDomain.cs:137
bool Remove(ISniffer Sniffer)
Removes a sniffer, if registered.
Tokens available in request.
Definition: RequestOrigin.cs:9
Interface for observable classes implementing communication protocols.
Interface for sniffers. Sniffers can be added to ICommunicationLayer classes to eavesdrop on communic...
Definition: ISniffer.cs:10
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
TextPosition
Where the instructions are to be place.
Definition: TextAttribute.cs:9