Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ProxyResource.cs
1using System;
3using System.Text;
4using System.Threading.Tasks;
9using Waher.Things;
12
14{
19 {
20 private readonly ICommunicationLayer comLayer;
21
26 : base(null, null)
27 {
28 this.LocalResource = 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
51 int RemotePort, bool Encrypted, bool UseSession, int TimeoutMs, string Privilege,
53 : base(Source, Parent)
54 {
55 this.LocalResource = LocalResource;
56 this.RemoteDomain = RemoteDomain;
57 this.RemoteFolder = RemoteFolder;
58 this.RemotePort = RemotePort;
59 this.Encrypted = Encrypted;
60 this.UseSession = UseSession;
61 this.TimeoutMs = TimeoutMs;
62 this.Privilege = Privilege;
63 this.comLayer = CommunicationLayer;
64 }
65
69 [Page(7, "Configuration")]
70 [Header(85, "Local Resource:")]
71 [ToolTip(86, "Local Resource that will act as a reverse proxy.")]
72 [Required]
73 public string LocalResource { get; set; }
74
78 [Page(7, "Configuration")]
79 [Header(87, "Remote Domain:")]
80 [ToolTip(88, "Domain of web server to forward requests to.")]
81 [Required]
82 public string RemoteDomain { get; set; }
83
87 [Page(7, "Configuration")]
88 [Header(89, "Remote Folder:")]
89 [ToolTip(90, "Base folder on remote domain that requests will be forwarded to.")]
90 public string RemoteFolder { get; set; }
91
95 [Page(7, "Configuration")]
96 [Header(91, "Remote Port:")]
97 [ToolTip(92, "Port number of remote domain that requests will be forwarded to.")]
98 [Range(1, 65535)]
99 [Required]
100 public int RemotePort { get; set; }
101
105 [Page(7, "Configuration")]
106 [Header(93, "Use encryption.")]
107 [ToolTip(94, "If forwarded requests are encrypted (HTTPS) or not (HTTP).")]
108 [Required]
109 public bool Encrypted { get; set; }
110
114 [Page(7, "Configuration")]
115 [Header(95, "Use proxy-session.")]
116 [ToolTip(96, "If the proxy uses a session itself.")]
117 [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.")]
118 public bool UseSession { get; set; }
119
123 [Page(7, "Configuration")]
124 [Header(34, "Timeout (ms):")]
125 [ToolTip(98, "Timeout afforded to forwarded requests, in milliseconds, before they are assumed to have failed.")]
126 [Range(1, 120 * 1000)]
127 [Text(TextPosition.AfterField, 63, "Note: Changes will take effect after broker has been restarted.")]
128 public int TimeoutMs { get; set; }
129
133 [Page(7, "Configuration")]
134 [Header(247, "Required Privilege:")]
135 [ToolTip(248, "Required privilege to access the resource. If not specified, the resource is public.")]
136 public string Privilege { get; set; }
137
141 public override string NodeId => this.LocalResource;
142
147 public override Task<string> GetTypeNameAsync(Language Language) => Language.GetStringAsync(typeof(GatewayConfigSource), 99, "Reverse Proxy Resource");
148
154 public override Task<bool> AcceptsParentAsync(INode Parent)
155 {
156 return Task.FromResult(Parent is WebServer);
157 }
158
165 public override async Task<IEnumerable<Parameter>> GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
166 {
167 LinkedList<Parameter> Parameters = new LinkedList<Parameter>();
169
170 StringBuilder sb = new StringBuilder();
171
172 sb.Append("http");
173 if (this.Encrypted)
174 sb.Append('s');
175
176 sb.Append("://");
177 sb.Append(this.RemoteDomain);
178
180 {
181 sb.Append(':');
182 sb.Append(this.RemotePort.ToString());
183 }
184
185 sb.Append(this.RemoteFolder);
186
187 Parameters.AddLast(new StringParameter("Location", await Namespace.GetStringAsync(82, "Location"), sb.ToString()));
188 Parameters.AddLast(new BooleanParameter("UseSession", await Namespace.GetStringAsync(53, "Session"), this.UseSession));
189 Parameters.AddLast(new Int32Parameter("TimeoutMs", await Namespace.GetStringAsync(54, "Timeout (ms)"), this.TimeoutMs));
190 Parameters.AddLast(new StringParameter("Privilege", await Namespace.GetStringAsync(249, "Privilege"), this.Privilege));
191
192 return Parameters;
193 }
194
195 #region ICommunicationLayer
196
201 public bool DecoupledEvents => this.comLayer?.DecoupledEvents ?? false;
202
207 public void Add(ISniffer Sniffer)
208 {
209 this.comLayer?.Add(Sniffer);
210 }
211
216 public void AddRange(IEnumerable<ISniffer> Sniffers)
217 {
218 this.comLayer?.AddRange(Sniffers);
219 }
220
226 public bool Remove(ISniffer Sniffer) => this.comLayer?.Remove(Sniffer) ?? false;
227
231 public ISniffer[] Sniffers => this.comLayer?.Sniffers;
232
236 public bool HasSniffers => this.comLayer?.HasSniffers ?? false;
237
242 public IEnumerator<ISniffer> GetEnumerator() => this.comLayer?.GetEnumerator();
243
248 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => this.comLayer?.GetEnumerator();
249
254 public void ReceiveBinary(int Count) => this.comLayer?.ReceiveBinary(Count);
255
262 public void ReceiveBinary(bool ConstantBuffer, byte[] Data) => this.comLayer?.ReceiveBinary(ConstantBuffer, Data);
263
272 public void ReceiveBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count) => this.comLayer?.ReceiveBinary(ConstantBuffer, Data, Offset, Count);
273
278 public void TransmitBinary(int Count) => this.comLayer?.TransmitBinary(Count);
279
286 public void TransmitBinary(bool ConstantBuffer, byte[] Data) => this.comLayer?.TransmitBinary(ConstantBuffer, Data);
287
296 public void TransmitBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count) => this.comLayer?.TransmitBinary(ConstantBuffer, Data, Offset, Count);
297
302 public void ReceiveText(string Text) => this.comLayer?.ReceiveText(Text);
303
308 public void TransmitText(string Text) => this.comLayer?.TransmitText(Text);
309
314 public void Information(string Comment) => this.comLayer?.Information(Comment);
315
320 public void Warning(string Warning) => this.comLayer?.Warning(Warning);
321
326 public void Error(string Error) => this.comLayer?.Error(Error);
327
332 public void Exception(Exception Exception) => this.comLayer?.Exception(Exception);
333
338 public void Exception(string Exception) => this.comLayer?.Exception(Exception);
339
345 public void ReceiveBinary(DateTime Timestamp, int Count) => this.comLayer?.ReceiveBinary(Timestamp, Count);
346
354 public void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data) => this.comLayer?.ReceiveBinary(Timestamp, ConstantBuffer, Data);
355
365 public void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count) => this.comLayer?.ReceiveBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
366
372 public void TransmitBinary(DateTime Timestamp, int Count) => this.comLayer?.TransmitBinary(Timestamp, Count);
373
381 public void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data) => this.comLayer?.TransmitBinary(Timestamp, ConstantBuffer, Data);
382
392 public void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count) => this.comLayer?.TransmitBinary(Timestamp, ConstantBuffer, Data, Offset, Count);
393
399 public void ReceiveText(DateTime Timestamp, string Text) => this.comLayer?.ReceiveText(Timestamp, Text);
400
406 public void TransmitText(DateTime Timestamp, string Text) => this.comLayer?.TransmitText(Timestamp, Text);
407
413 public void Information(DateTime Timestamp, string Comment) => this.comLayer?.Information(Timestamp, Comment);
414
420 public void Warning(DateTime Timestamp, string Warning) => this.comLayer?.Warning(Timestamp, Warning);
421
427 public void Error(DateTime Timestamp, string Error) => this.comLayer?.Error(Timestamp, Error);
428
434 public void Exception(DateTime Timestamp, string Exception) => this.comLayer?.Exception(Timestamp, Exception);
435
441 public void Exception(DateTime Timestamp, Exception Exception) => this.comLayer?.Exception(Timestamp, Exception);
442
443 #endregion
444
445 }
446}
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 resource to act as a reverse proxy.
void Information(DateTime Timestamp, string Comment)
Called to inform the viewer of something.
void TransmitBinary(DateTime Timestamp, int Count)
Called when binary data has been transmitted.
void Error(DateTime Timestamp, string Error)
Called to inform the viewer of an error state.
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
bool Encrypted
If forwarded requests are encrypted (HTTPS) or not (HTTP).
string RemoteDomain
Location client is redirected to.
void ReceiveBinary(DateTime Timestamp, int Count)
Called when binary data has been received.
void Exception(DateTime Timestamp, Exception Exception)
Called to inform the viewer of an exception state.
void ReceiveBinary(int Count)
Called when binary data has been received.
void Add(ISniffer Sniffer)
Adds a sniffer to the node.
ProxyResource(GatewayConfigSource Source, WebServer Parent, string LocalResource, string RemoteDomain, string RemoteFolder, int RemotePort, bool Encrypted, bool UseSession, int TimeoutMs, string Privilege, ICommunicationLayer CommunicationLayer)
Defines a proxy resource to act as a reverse proxy.
void TransmitBinary(int Count)
Called when binary data has been transmitted.
void TransmitText(string Text)
Called when text has been transmitted.
bool DecoupledEvents
If events raised from the communication layer are decoupled, i.e. executed in parallel with the sourc...
void AddRange(IEnumerable< ISniffer > Sniffers)
Adds a range of sniffers to the node.
bool Remove(ISniffer Sniffer)
Removes a sniffer, if registered.
void ReceiveText(string Text)
Called when text has been received.
bool UseSession
If forwarded requests are encrypted (HTTPS) or not (HTTP).
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.
IEnumerator< ISniffer > GetEnumerator()
Returns an enumerator that iterates through the collection.
void Information(string Comment)
Called to inform the viewer of something.
void ReceiveBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been received.
void TransmitBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
ProxyResource()
Defines a proxy resource to act as a reverse proxy.
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been transmitted.
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 ReceiveBinary(bool ConstantBuffer, byte[] Data, int Offset, int Count)
Called when binary data has been received.
void Error(string Error)
Called to inform the viewer of an error state.
override async Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
void TransmitBinary(DateTime Timestamp, bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
int TimeoutMs
If redirection is permanent (true) or temporary (false).
void Warning(DateTime Timestamp, string Warning)
Called to inform the viewer of a warning state.
bool HasSniffers
If there are sniffers registered on the object.
void TransmitBinary(bool ConstantBuffer, byte[] Data)
Called when binary data has been transmitted.
void TransmitText(DateTime Timestamp, string Text)
Called when text has been transmitted.
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...
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).
string Privilege
Required privilege to access the resource. If not specified, the resource is public.
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