SetNet.DdosGuard 1.1.0

dotnet add package SetNet.DdosGuard --version 1.1.0
                    
NuGet\Install-Package SetNet.DdosGuard -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SetNet.DdosGuard" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SetNet.DdosGuard" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SetNet.DdosGuard" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SetNet.DdosGuard --version 1.1.0
                    
#r "nuget: SetNet.DdosGuard, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SetNet.DdosGuard@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SetNet.DdosGuard&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SetNet.DdosGuard&version=1.1.0
                    
Install as a Cake Tool

<p align="center"> <img src="https://raw.githubusercontent.com/Povstalez/SetNet/master/assets/icon.png" alt="SetNet" width="96"> </p>

SetNet.DdosGuard

Connection-flood protection for SetNet.

Counts new connections per source IP over a sliding window and temporarily auto-bans any IP that opens too many too fast — which drops its traffic and kicks its live peers through SetNet.BanList. Use it to shut down application-level connection floods and abusive reconnect loops that slip past the core per-IP accept rate limiter: DdosGuard acts on established peers (via the BaseServer.PeerConnected event) and remembers the offender with a timed ban.

Added by composition — one call, no base class. It builds on SetNet.BanList internally and hands you back the same BanList so you can add manual bans or share the store.

Install

dotnet add package SetNet
dotnet add package SetNet.DdosGuard

Usage

var bans = server.UseDdosGuard(new DdosGuardOptions
{
    MaxConnectionsPerWindow = 10,   // more than 10 new connections…
    WindowSeconds           = 10,   // …from one IP within 10 seconds →
    BanSeconds              = 300,   // auto-ban that IP for 5 minutes
});

// UseDdosGuard returns the underlying BanList — manual bans, checks, shared store:
bans.Ban("203.0.113.7");
bans.Unban("203.0.113.7");
if (bans.IsBanned(someIp)) { /* ... */ }

Share auto-bans across nodes / restarts by passing an IBanStore:

var bans = server.UseDdosGuard(new DdosGuardOptions { BanSeconds = 600 }, new RedisBanStore());

UseDdosGuard() with no arguments uses the defaults below.

Options

Option Default Meaning
MaxConnectionsPerWindow 10 new connections from one IP allowed within the window before it's banned
WindowSeconds 10 length of the sliding window, in seconds
BanSeconds 300 how long (seconds) an offending IP stays auto-banned

The per-IP counter uses a monotonic clock (Stopwatch) and resets once the window elapses. When the count exceeds the threshold, the IP gets a timed ban expiring BanSeconds from now — which routes through the BanList gate to drop its frames and immediately kick its connected peers.

Notes

  • Mitigation, not a shield. This is application-level protection. It does not replace edge/network DDoS defense — a real volumetric attack must be absorbed upstream (cloud scrubbing, provider-level rate limits, a load balancer). DdosGuard stops abusive connection patterns that reach your process.
  • Needs a real remote endpoint. Detection keys on peer.RemoteEndPoint?.Address; peers without one (e.g. the in-memory transport) are ignored. Works on real TCP/UDP/WebSocket transports.
  • Shared NAT / proxy caveat. Because it bans by IP, many legitimate users behind one NAT or a reverse proxy count against the same bucket. Tune the window/threshold accordingly, and prefer authentication + account bans for targeted abuse.
  • Composes with Auth / RateLimit. The ban gate chains onto the server's existing InboundAuthorizer, so DdosGuard, SetNet.Auth, and SetNet.RateLimit stack without conflict. Best paired with TLS.

Documentation & source

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 127 7/2/2026