Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
idtcpserver network flood
#2
(06-20-2018, 11:43 PM)Madammar Wrote: my firewall works really fine on my ubuntu machine to block those bad ips and drop there packets

If that were true, you would not be having a problem with your TIdTCPServer app, as the flood traffic would not reach it in the first place.

(06-20-2018, 11:43 PM)Madammar Wrote: why tidtcpserver application gets unresponsive while such attack is happened ?

In what way exactly?  If the flood traffic were not reaching the TIdTCPServer, then it wouldn't be doing anything to make it become unresponsive.

(06-20-2018, 11:43 PM)Madammar Wrote: here is the full server code

I don't see anything in that code that can cause the app to become unresponsive.  However, the code can be simplified a bit:

Code:
type
 TConnection = class(TIdServerContext)
 private
   ...
 public
   HasPendingOutbound: Boolean;
   OutboundCache: TIdThreadSafeStringList;
   ...
    // sending methods
    procedure SendCommand(const Command: String);
    procedure SendCommandWithParams(const Command, Params: String);
    ...
 end;

procedure TConnection.SendCommand(const Command : String);
begin
 with OutboundCache.Lock do
 try
   Add(Command);
   HasPendingOutbound := True;
 finally
   OutboundCache.Unlock;
 end;
end;

procedure TConnection.SendCommandWithParams(const Command, Params: String);
begin
  SendCommand('1' + Command + Sep + Params);
end;

procedure Trsrvfrm.TcpServerExecute(AContext: TIdContext);
var
 Connection: TConnection;
 Command, Temp: String;
 Params: array [1 .. 200] of String;
 Cache, OutboundCmds: TStringList;
 ParamsCount, I: integer;
begin
 Connection := AContext as TConnection;

 // check for pending outbound commands...
 if Connection.HasPendingOutbound then
 begin
   OutboundCmds := TStringList.Create;
   try
     Cache := Connection.OutboundCache.Lock;
     try
       OutboundCmds.Assign(Cache);
       Cache.Clear;
       Connection.HasPendingOutbound := False;
     finally
       Connection.OutboundCache.Unlock;
     end;

     for I := 0 to OutboundCmds.Count - 1 do
       AContext.Connection.IOHandler.WriteLn(OutboundCmds.Strings[I]);
   finally
     OutboundCmds.Free;
   end;
 end;

 // check for a pending inbound command...
 if AContext.Connection.IOHandler.InputBufferIsEmpty then
 begin
   AContext.Connection.IOHandler.CheckForDataOnSource(10);
   AContext.Connection.IOHandler.CheckForDisconnect;
   if AContext.Connection.IOHandler.InputBufferIsEmpty then
     Exit;
 end;

 Command := AContext.Connection.Socket.ReadLn;

 if Command <> '' then
 begin
   //Command Type
   if Command[1] = '1' then // command with params
   begin
     Temp := Copy(Command, 2, MaxInt);
     Command := Fetch(Temp, Sep);
     ParamsCount := 0;
     while (Temp <> '') and (ParamsCount < 200) do
     begin
       Inc(ParamsCount);
       Params[ParamsCount] := Fetch(Temp, Sep);
     end;
   end;
 end;

 if Command = '' then
 begin
   AContext.Connection.Disconnect;
   Exit;
 end;

 if Command = 'Ping' then
   AContext.Connection.IOHandler.WriteLn('pong');
end;

Reply


Messages In This Thread
idtcpserver network flood - by Madammar - 06-20-2018, 11:43 PM
RE: idtcpserver network flood - by rlebeau - 06-21-2018, 06:30 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)