/*
* ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2018 Alexander Barton (alex@barton.de) and Contributors.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <assert.h>
#include <time.h>
-#ifdef DEBUG
-# include "log.h"
-#endif
+#include "log.h"
#include "conn.h"
-
+#include "conf.h"
#include "conn-func.h"
/**
/**
* Update "ping timestamp", the time of the last outgoing PING request.
*
+ * the value 0 signals a newly connected client including servers during the
+ * initial "server burst"; and 1 means that no PONG is pending for a PING.
+ *
* @param Idx Connection index.
+ * @param TimeStamp 0, 1, or time stamp.
*/
GLOBAL void
-Conn_UpdatePing(CONN_ID Idx)
+Conn_UpdatePing(CONN_ID Idx, time_t TimeStamp)
{
assert(Idx > NONE);
- My_Connections[Idx].lastping = time(NULL);
+ My_Connections[Idx].lastping = TimeStamp;
}
/*
GLOBAL time_t
Conn_GetIdle( CONN_ID Idx )
{
- /* Return Idle-Timer of a connetion */
+ /* Return Idle-Timer of a connection */
assert( Idx > NONE );
return time( NULL ) - My_Connections[Idx].lastprivmsg;
} /* Conn_GetIdle */
* is read. This function only increases the penalty, it is not possible to
* decrease the penalty time.
*
- * @param Idex Connection index.
+ * @param Idx Connection index.
* @param Seconds Seconds to add.
* @see Conn_ResetPenalty
*/
assert(Idx > NONE);
assert(Seconds >= 0);
+ /* Limit new penalty to maximum configured, when less than 10 seconds. *
+ The latter is used to limit brute force attacks, therefore we don't *
+ want to limit that! */
+ if (Conf_MaxPenaltyTime >= 0
+ && Seconds > Conf_MaxPenaltyTime
+ && Seconds < 10)
+ Seconds = Conf_MaxPenaltyTime;
+
t = time(NULL);
if (My_Connections[Idx].delaytime < t)
My_Connections[Idx].delaytime = t;
My_Connections[Idx].delaytime += Seconds;
-#ifdef DEBUG
- Log(LOG_DEBUG,
- "Add penalty time on connection %d: %ld second%s, total %ld second%s.",
+ LogDebug("Add penalty time on connection %d: %ld second%s, total %ld second%s.",
Idx, (long)Seconds, Seconds != 1 ? "s" : "",
My_Connections[Idx].delaytime - t,
My_Connections[Idx].delaytime - t != 1 ? "s" : "");
-#endif
} /* Conn_SetPenalty */
GLOBAL void
Conn_First( void )
{
CONN_ID i;
-
+
for( i = 0; i < Pool_Size; i++ )
{
if( My_Connections[i].sock != NONE ) return i;
CONN_ID i = NONE;
assert( Idx > NONE );
-
+
for( i = Idx + 1; i < Pool_Size; i++ )
{
if( My_Connections[i].sock != NONE ) return i;