Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConnectionsExceeded.cs
1using System;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
9
11{
16 {
21 : base()
22 {
23 }
24
32 : base(Xml, Parent, Document)
33 {
34 }
35
39 public override string LocalName => nameof(ConnectionsExceeded);
40
48 public override WafAction Create(XmlElement Xml, WafAction Parent, WebApplicationFirewall Document) => new ConnectionsExceeded(Xml, Parent, Document);
49
55 public override async Task<WafResult?> Review(ProcessingState State)
56 {
57 string Endpoint = State.Request.RemoteEndPoint;
58 string Key = Endpoint.RemovePortNumber() + "|Connections";
59 long Count;
60
61 using (Semaphore Semaphore = await Semaphores.BeginWrite(Key))
62 {
63 if (State.TryGetCachedObject(Key, out Dictionary<string, bool> Connections))
64 Connections[Endpoint] = true;
65 else
66 {
67 Duration Duration = await this.EvaluateDurationAsync(State);
68
69 Connections = new Dictionary<string, bool>()
70 {
71 { Endpoint, true }
72 };
73
74 State.AddToCache(Key, Connections, DateTime.UtcNow + Duration);
75 }
76
77 Count = Connections.Count;
78 }
79
80 return await this.Review(State, Count);
81 }
82 }
83}
Represents a named semaphore, i.e. an object, identified by a name, that allows single concurrent wri...
Definition: Semaphore.cs:19
Static class of application-wide semaphores that can be used to order access to editable objects.
Definition: Semaphores.cs:17
static async Task< Semaphore > BeginWrite(string Key)
Waits until the semaphore identified by Key is ready for writing. Each call to BeginWrite must be fo...
Definition: Semaphores.cs:91
Checks if the remote endpoint has made too many connections.
override string LocalName
XML Local Name for the XML element defining the action.
override WafAction Create(XmlElement Xml, WafAction Parent, WebApplicationFirewall Document)
Creates a WAF action from its XML definition.
ConnectionsExceeded(XmlElement Xml, WafAction Parent, WebApplicationFirewall Document)
Checks if the remote endpoint has made too many connections.
ConnectionsExceeded()
Checks if the remote endpoint has made too many connections.
override async Task< WafResult?> Review(ProcessingState State)
Reviews the processing state, and returns a WAF result, if any.
Abstract base class for rate limit comparisons.
Task< Duration > EvaluateDurationAsync(ProcessingState State)
Evaluates the duration of the rate limit.
Contains the current state of a review process.
void AddToCache(string Key, object Value)
Adds a value to the cache.
HttpRequest Request
Current HTTP Request
Abstract base class for Web Application Firewall actions.
Definition: WafAction.cs:17
WebApplicationFirewall Document
Web Application Firewall document.
Definition: WafAction.cs:60
Web Application Firewall for HttpServer.
Represents a duration value, as defined by the xsd:duration data type: http://www....
Definition: Duration.cs:14