mirror of
https://github.com/rejetto/hfs2.git
synced 2025-12-19 10:03:56 +01:00
smarter DoS-preventing grace period
This commit is contained in:
parent
1fc5894204
commit
782702c192
12
main.pas
12
main.pas
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
Copyright (C) 2002-2014 Massimo Melina (www.rejetto.com)
|
Copyright (C) 2002-2014 Massimo Melina (www.rejetto.com)
|
||||||
|
|
||||||
This file is part of HFS ~ HTTP File Server.
|
This file is part of HFS ~ HTTP File Server.
|
||||||
@ -3607,15 +3607,19 @@ var
|
|||||||
|
|
||||||
const ip2availability: Tdictionary<string,Tdatetime> = NIL;
|
const ip2availability: Tdictionary<string,Tdatetime> = NIL;
|
||||||
const folderConcurrents: integer = 0;
|
const folderConcurrents: integer = 0;
|
||||||
|
const MAX_CONCURRENTS = 3;
|
||||||
|
|
||||||
procedure updateAvailability();
|
procedure updateAvailability();
|
||||||
var
|
var
|
||||||
pair: Tpair<string,Tdatetime>;
|
pair: Tpair<string,Tdatetime>;
|
||||||
t: Tdatetime;
|
t: Tdatetime;
|
||||||
begin
|
begin
|
||||||
dec(folderConcurrents);
|
|
||||||
t:=now();
|
t:=now();
|
||||||
ip2availability[cd.address]:=t+1/SECONDS;
|
if folderConcurrents = MAX_CONCURRENTS then // serving multiple addresses at max capacity, let's give a grace period for others
|
||||||
|
ip2availability[cd.address]:=t + 1/SECONDS
|
||||||
|
else
|
||||||
|
ip2availability.Remove(cd.address);
|
||||||
|
dec(folderConcurrents);
|
||||||
// purge leftovers
|
// purge leftovers
|
||||||
for pair in ip2availability do
|
for pair in ip2availability do
|
||||||
if pair.Value < t then
|
if pair.Value < t then
|
||||||
@ -3631,7 +3635,7 @@ const folderConcurrents: integer = 0;
|
|||||||
exit(FALSE);
|
exit(FALSE);
|
||||||
except
|
except
|
||||||
end;
|
end;
|
||||||
if folderConcurrents >= 3 then // max number of concurrent folder loading, others are postponed
|
if folderConcurrents >= MAX_CONCURRENTS then // max number of concurrent folder loading, others are postponed
|
||||||
exit(FALSE);
|
exit(FALSE);
|
||||||
inc(folderConcurrents);
|
inc(folderConcurrents);
|
||||||
ip2availability.AddOrSetValue(cd.address, now()+1);
|
ip2availability.AddOrSetValue(cd.address, now()+1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user