summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base.cpp2
-rw-r--r--src/channels.cpp1
-rw-r--r--src/connection.cpp3
-rw-r--r--src/dns.cpp6
-rw-r--r--src/dnsqueue.cpp2
-rw-r--r--src/inspircd.cpp82
-rw-r--r--src/inspircd_io.cpp1
-rw-r--r--src/inspircd_util.cpp2
-rw-r--r--src/message.cpp2
-rw-r--r--src/mode.cpp3
-rw-r--r--src/modules.cpp2
-rw-r--r--src/servers.cpp10
-rw-r--r--src/users.cpp2
-rw-r--r--src/xline.cpp23
14 files changed, 84 insertions, 57 deletions
diff --git a/src/base.cpp b/src/base.cpp
index 511c8152d..3dadb24eb 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -22,6 +22,8 @@
#include "inspircd.h"
#include "modules.h"
+extern time_t TIME;
+
bool Extensible::Extend(std::string key, char* p)
{
// only add an item if it doesnt already exist
diff --git a/src/channels.cpp b/src/channels.cpp
index 379339c47..05bc7fa0d 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -104,6 +104,7 @@ extern serverrec* me[32];
extern FILE *log_file;
+extern time_t TIME;
using namespace std;
diff --git a/src/connection.cpp b/src/connection.cpp
index 475e9ade5..4226a9d2f 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -35,7 +35,7 @@ extern std::vector<ircd_module*> factory;
extern int MODCOUNT;
-
+extern time_t TIME;
connection::connection()
{
@@ -469,7 +469,6 @@ bool connection::RecvPacket(std::deque<std::string> &messages, char* host)
long connection::GenKey()
{
- srand(time(NULL));
return (random()*time(NULL));
}
diff --git a/src/dns.cpp b/src/dns.cpp
index c3d7cd786..30d05e2a3 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -95,6 +95,8 @@ struct s_header { /* DNS query header */
unsigned char payload[512]; /* DNS question, populated by dns_build_query_payload() */
};
+extern time_t TIME;
+
void *dns_align(void *inp) {
char *p = (char*)inp;
int offby = ((char *)p - (char *)0) % DNS_ALIGN;
@@ -161,7 +163,7 @@ void DNS::dns_init() { /* on first call only: populates servers4 struct with up
i4 = 0;
initdone = 1;
- srand((unsigned int) time(NULL));
+ srand((unsigned int) TIME);
memset(servers4,'\0',sizeof(in_addr) * DNS_MAX);
f = fopen(DNS_CONFIG_FBCK,"r");
if (f == NULL)
@@ -191,7 +193,7 @@ void DNS::dns_init_2(const char* dnsserver) { /* populates servers4 struct with
i4 = 0;
initdone = 1;
- srand((unsigned int) time(NULL));
+ srand((unsigned int) TIME);
memset(servers4,'\0',sizeof(in_addr) * DNS_MAX);
if (dns_aton4_s(dnsserver,&addr4) != NULL)
memcpy(&servers4[i4++],&addr4,sizeof(in_addr));
diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp
index ddc6993f0..7886cf09f 100644
--- a/src/dnsqueue.cpp
+++ b/src/dnsqueue.cpp
@@ -164,6 +164,8 @@ extern ClassVector Classes;
extern char DNSServer[MAXBUF];
long max_fd_alloc = 0;
+extern time_t TIME;
+
class Lookup {
private:
DNS* resolver;
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 8faf6a052..bd2828ec9 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -102,6 +102,8 @@ extern int MODCOUNT;
int openSockfd[MAXSOCKS];
bool nofork = false;
+time_t TIME = time(NULL);
+
namespace nspace
{
#ifdef GCC34
@@ -1369,7 +1371,7 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
strlcpy(chanlist[cname]->name, cname,CHANMAX);
chanlist[cname]->topiclock = 1;
chanlist[cname]->noexternal = 1;
- chanlist[cname]->created = time(NULL);
+ chanlist[cname]->created = TIME;
strcpy(chanlist[cname]->topic, "");
strncpy(chanlist[cname]->setby, user->nick,NICKMAX);
chanlist[cname]->topicset = 0;
@@ -2144,7 +2146,7 @@ void AddWhoWas(userrec* u)
for (user_hash::iterator i = whowas.begin(); i != whowas.end(); i++)
{
// 3600 seconds in an hour ;)
- if ((i->second->signon)<(time(NULL)-(WHOWAS_STALE*3600)))
+ if ((i->second->signon)<(TIME-(WHOWAS_STALE*3600)))
{
if (i->second) delete i->second;
i->second = a;
@@ -2204,34 +2206,27 @@ void AddClient(int socket, char* host, int port, bool iscached, char* ip)
strncpy(clientlist[tempnick]->server, ServerName,256);
strncpy(clientlist[tempnick]->ident, "unknown",9);
clientlist[tempnick]->registered = 0;
- clientlist[tempnick]->signon = time(NULL)+dns_timeout;
- clientlist[tempnick]->nping = time(NULL)+240+dns_timeout;
+ clientlist[tempnick]->signon = TIME+dns_timeout;
+ clientlist[tempnick]->nping = TIME+240+dns_timeout;
clientlist[tempnick]->lastping = 1;
clientlist[tempnick]->port = port;
strncpy(clientlist[tempnick]->ip,ip,32);
// set the registration timeout for this user
unsigned long class_regtimeout = 90;
- for (ClassVector::iterator i = Classes.begin(); i != Classes.end(); i++)
- {
- if (match(clientlist[tempnick]->host,i->host) && (i->type == CC_ALLOW))
- {
- class_regtimeout = (unsigned long)i->registration_timeout;
- break;
- }
- }
-
int class_flood = 0;
+
for (ClassVector::iterator i = Classes.begin(); i != Classes.end(); i++)
{
if (match(clientlist[tempnick]->host,i->host) && (i->type == CC_ALLOW))
{
+ class_regtimeout = (unsigned long)i->registration_timeout;
class_flood = i->flood;
break;
}
}
- clientlist[tempnick]->timeout = time(NULL)+class_regtimeout;
+ clientlist[tempnick]->timeout = TIME+class_regtimeout;
clientlist[tempnick]->flood = class_flood;
for (int i = 0; i < MAXCHANS; i++)
@@ -2244,13 +2239,16 @@ void AddClient(int socket, char* host, int port, bool iscached, char* ip)
kill_link(clientlist[tempnick],"No more connections allowed in this class");
- char* r = matches_zline(ip);
char* e = matches_exception(ip);
- if ((r) && (!e))
+ if (!e)
{
- char reason[MAXBUF];
- snprintf(reason,MAXBUF,"Z-Lined: %s",r);
- kill_link(clientlist[tempnick],reason);
+ char* r = matches_zline(ip);
+ if (r)
+ {
+ char reason[MAXBUF];
+ snprintf(reason,MAXBUF,"Z-Lined: %s",r);
+ kill_link(clientlist[tempnick],reason);
+ }
}
}
@@ -2365,7 +2363,7 @@ void ShowRULES(userrec *user)
void FullConnectUser(userrec* user)
{
user->registered = 7;
- user->idle_lastmsg = time(NULL);
+ user->idle_lastmsg = TIME;
log(DEBUG,"ConnectUser: %s",user->nick);
if (strcmp(Passwd(user),"") && (!user->haspassed))
@@ -2834,7 +2832,7 @@ void process_command(userrec *user, char* cmd)
log(DEBUG,"Processing command");
/* activity resets the ping pending timer */
- user->nping = time(NULL) + 120;
+ user->nping = TIME + 120;
if ((items) < cmdlist[i].min_params)
{
log(DEBUG,"process_command: not enough parameters: %s %s",user->nick,command);
@@ -3038,7 +3036,7 @@ void DoSync(serverrec* serv, char* tcp_host)
// send start of sync marker: Y <timestamp>
// at this point the ircd receiving it starts broadcasting this netburst to all ircds
// except the ones its receiving it from.
- snprintf(data,MAXBUF,"Y %d",time(NULL));
+ snprintf(data,MAXBUF,"Y %d",TIME);
serv->SendPacket(data,tcp_host);
// send users and channels
for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
@@ -3111,7 +3109,7 @@ void DoSync(serverrec* serv, char* tcp_host)
}
}
- snprintf(data,MAXBUF,"F %d",time(NULL));
+ snprintf(data,MAXBUF,"F %d",TIME);
serv->SendPacket(data,tcp_host);
log(DEBUG,"Sent sync");
// ircd sends its serverlist after the end of sync here
@@ -3416,17 +3414,18 @@ int InspIRCd(void)
fd_set serverfds;
timeval tvs;
- tvs.tv_usec = 10000L;
+ tvs.tv_usec = 7000L;
tvs.tv_sec = 0;
tv.tv_sec = 0;
- tv.tv_usec = 10000L;
+ tv.tv_usec = 7000L;
char data[10240];
timeval tval;
fd_set sfd;
- tval.tv_usec = 10000L;
+ tval.tv_usec = 7000L;
tval.tv_sec = 0;
int total_in_this_set = 0;
int v = 0;
+ bool expire_run = false;
/* main loop, this never returns */
for (;;)
@@ -3436,23 +3435,22 @@ int InspIRCd(void)
#endif
// poll dns queue
dns_poll();
-
FD_ZERO(&sfd);
+ // we only read time() once per iteration rather than tons of times!
+ TIME = time(NULL);
+
user_hash::iterator count2 = clientlist.begin();
// *FIX* Instead of closing sockets in kill_link when they receive the ERROR :blah line, we should queue
// them in a list, then reap the list every second or so.
- if ((reap_counter % 50) == 0)
+ if (((TIME % 5) == 0) && (!expire_run))
{
- // These functions eat cpu, and should not be done so often!
-
- // update the status of klines, etc
- expire_lines();
-#ifdef _POSIX_PRIORITY_SCHEDULING
- sched_yield();
-#endif
+ expire_lines();
+ expire_run = true;
}
+ if ((TIME % 5) == 1)
+ expire_run = false;
if (reap_counter>300)
{
if (fd_reap.size() > 0)
@@ -3480,7 +3478,7 @@ int InspIRCd(void)
// serverFds timevals went here
- tvs.tv_usec = 10000L;
+ tvs.tv_usec = 7000L;
int servresult = select(32767, &serverfds, NULL, NULL, &tvs);
if (servresult > 0)
{
@@ -3568,13 +3566,13 @@ int InspIRCd(void)
// registration timeout -- didnt send USER/NICK/HOST in the time specified in
// their connection class.
- if ((time(NULL) > count2->second->timeout) && (count2->second->registered != 7))
+ if ((TIME > count2->second->timeout) && (count2->second->registered != 7))
{
log(DEBUG,"InspIRCd: registration timeout: %s",count2->second->nick);
kill_link(count2->second,"Registration timeout");
goto label;
}
- if ((time(NULL) > count2->second->signon) && (count2->second->registered == 3))
+ if ((TIME > count2->second->signon) && (count2->second->registered == 3))
{
count2->second->dns_done = true;
FullConnectUser(count2->second);
@@ -3585,7 +3583,7 @@ int InspIRCd(void)
FullConnectUser(count2->second);
goto label;
}
- if (((time(NULL)) > count2->second->nping) && (isnick(count2->second->nick)) && (count2->second->registered == 7))
+ if ((TIME > count2->second->nping) && (isnick(count2->second->nick)) && (count2->second->registered == 7))
{
if ((!count2->second->lastping) && (count2->second->registered == 7))
{
@@ -3596,7 +3594,7 @@ int InspIRCd(void)
Write(count2->second->fd,"PING :%s",ServerName);
log(DEBUG,"InspIRCd: pinging: %s",count2->second->nick);
count2->second->lastping = 0;
- count2->second->nping = time(NULL)+120;
+ count2->second->nping = TIME+120;
}
}
count2++;
@@ -3612,7 +3610,7 @@ int InspIRCd(void)
// tvals defined here
- tval.tv_usec = 10000L;
+ tval.tv_usec = 7000L;
selectResult2 = select(65535, &sfd, NULL, NULL, &tval);
// now loop through all of the items in this pool if any are waiting
@@ -3730,7 +3728,7 @@ int InspIRCd(void)
FD_SET (openSockfd[count], &selectFds);
}
- tv.tv_usec = 10000L;
+ tv.tv_usec = 7000L;
selectResult = select(MAXSOCKS, &selectFds, NULL, NULL, &tv);
/* select is reporting a waiting socket. Poll them all to find out which */
diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp
index 4d61d4105..4cb245d9a 100644
--- a/src/inspircd_io.cpp
+++ b/src/inspircd_io.cpp
@@ -32,6 +32,7 @@ using namespace std;
extern FILE *log_file;
extern int boundPortCount;
extern int openSockfd[MAXSOCKS];
+extern time_t TIME;
void WriteOpers(char* text, ...);
diff --git a/src/inspircd_util.cpp b/src/inspircd_util.cpp
index fd1cc5249..f90c4867e 100644
--- a/src/inspircd_util.cpp
+++ b/src/inspircd_util.cpp
@@ -18,6 +18,8 @@
#include "inspircd_io.h"
#include "inspircd_util.h"
#include "inspstring.h"
+
+extern time_t TIME;
char *SafeStrncpy (char *dest, const char *src, size_t size)
{
diff --git a/src/message.cpp b/src/message.cpp
index 6c09096d2..2239916c0 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -56,6 +56,8 @@ extern int MODCOUNT;
extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
+extern time_t TIME;
+
/* return 0 or 1 depending if users u and u2 share one or more common channels
* (used by QUIT, NICK etc which arent channel specific notices) */
diff --git a/src/mode.cpp b/src/mode.cpp
index 12c6b2b92..e38b3946a 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -79,6 +79,7 @@ extern bool AllowHalfop;
extern bool AllowProtect;
extern bool AllowFounder;
+extern time_t TIME;
char* give_ops(userrec *user,char *dest,chanrec *chan,int status)
{
@@ -484,7 +485,7 @@ char* add_ban(userrec *user,char *dest,chanrec *chan,int status)
}
}
- b.set_time = time(NULL);
+ b.set_time = TIME;
strncpy(b.data,dest,MAXBUF);
strncpy(b.set_by,user->nick,NICKMAX);
chan->bans.push_back(b);
diff --git a/src/modules.cpp b/src/modules.cpp
index a575c3fde..ec1d20560 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -65,6 +65,8 @@ extern int MODCOUNT;
extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
+extern time_t TIME;
+
extern int LogLevel;
extern char ServerName[MAXBUF];
extern char Network[MAXBUF];
diff --git a/src/servers.cpp b/src/servers.cpp
index 1ea20a5c2..889709977 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -21,14 +21,16 @@
#include <map>
#include "inspstring.h"
+extern time_t TIME;
+
serverrec::serverrec()
{
strlcpy(name,"",256);
pingtime = 0;
- lastping = time(NULL);
+ lastping = TIME;
usercount_i = usercount = opercount = version = 0;
hops_away = 1;
- signon = time(NULL);
+ signon = TIME;
jupiter = false;
fd = 0;
sync_soon = false;
@@ -43,11 +45,11 @@ serverrec::~serverrec()
serverrec::serverrec(char* n, long ver, bool jupe)
{
strlcpy(name,n,256);
- lastping = time(NULL);
+ lastping = TIME;
usercount_i = usercount = opercount = 0;
version = ver;
hops_away = 1;
- signon = time(NULL);
+ signon = TIME;
jupiter = jupe;
fd = 0;
sync_soon = false;
diff --git a/src/users.cpp b/src/users.cpp
index 9f82a04d6..a32b94cf7 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -23,6 +23,8 @@
extern std::stringstream config_f;
+extern time_t TIME;
+
userrec::userrec()
{
// the PROPER way to do it, AVOID bzero at *ALL* costs
diff --git a/src/xline.cpp b/src/xline.cpp
index ce6257a66..443d28087 100644
--- a/src/xline.cpp
+++ b/src/xline.cpp
@@ -181,6 +181,7 @@ extern file_cache MOTD;
extern file_cache RULES;
extern address_cache IP;
+extern time_t TIME;
std::vector<KLine> klines;
std::vector<GLine> glines;
@@ -243,7 +244,7 @@ void add_gline(long duration, char* source, char* reason, char* hostmask)
strlcpy(item.reason,reason,MAXBUF);
strlcpy(item.source,source,MAXBUF);
item.n_matches = 0;
- item.set_time = time(NULL);
+ item.set_time = TIME;
glines.push_back(item);
}
@@ -258,7 +259,7 @@ void add_eline(long duration, char* source, char* reason, char* hostmask)
strlcpy(item.reason,reason,MAXBUF);
strlcpy(item.source,source,MAXBUF);
item.n_matches = 0;
- item.set_time = time(NULL);
+ item.set_time = TIME;
elines.push_back(item);
}
@@ -274,7 +275,7 @@ void add_qline(long duration, char* source, char* reason, char* nickname)
strlcpy(item.source,source,MAXBUF);
item.n_matches = 0;
item.is_global = false;
- item.set_time = time(NULL);
+ item.set_time = TIME;
qlines.push_back(item);
}
@@ -290,7 +291,7 @@ void add_zline(long duration, char* source, char* reason, char* ipaddr)
strlcpy(item.source,source,MAXBUF);
item.n_matches = 0;
item.is_global = false;
- item.set_time = time(NULL);
+ item.set_time = TIME;
zlines.push_back(item);
}
@@ -305,7 +306,7 @@ void add_kline(long duration, char* source, char* reason, char* hostmask)
strlcpy(item.reason,reason,MAXBUF);
strlcpy(item.source,source,MAXBUF);
item.n_matches = 0;
- item.set_time = time(NULL);
+ item.set_time = TIME;
klines.push_back(item);
}
@@ -444,6 +445,8 @@ bool del_kline(char* hostmask)
char* matches_qline(const char* nick)
{
+ if (qlines.empty())
+ return NULL;
for (std::vector<QLine>::iterator i = qlines.begin(); i != qlines.end(); i++)
{
if (match(nick,i->nick))
@@ -458,6 +461,8 @@ char* matches_qline(const char* nick)
char* matches_gline(const char* host)
{
+ if (glines.empty())
+ return NULL;
for (std::vector<GLine>::iterator i = glines.begin(); i != glines.end(); i++)
{
if (match(host,i->hostmask))
@@ -470,6 +475,8 @@ char* matches_gline(const char* host)
char* matches_exception(const char* host)
{
+ if (elines.empty())
+ return NULL;
char host2[MAXBUF];
snprintf(host2,MAXBUF,"*@%s",host);
for (std::vector<ELine>::iterator i = elines.begin(); i != elines.end(); i++)
@@ -526,6 +533,8 @@ void zline_set_creation_time(char* ip, time_t create_time)
char* matches_zline(const char* ipaddr)
{
+ if (zlines.empty())
+ return NULL;
for (std::vector<ZLine>::iterator i = zlines.begin(); i != zlines.end(); i++)
{
if (match(ipaddr,i->ipaddr))
@@ -540,6 +549,8 @@ char* matches_zline(const char* ipaddr)
char* matches_kline(const char* host)
{
+ if (klines.empty())
+ return NULL;
for (std::vector<KLine>::iterator i = klines.begin(); i != klines.end(); i++)
{
if (match(host,i->hostmask))
@@ -555,7 +566,7 @@ char* matches_kline(const char* host)
void expire_lines()
{
bool go_again = true;
- time_t current = time(NULL);
+ time_t current = TIME;
// because we mess up an iterator when we remove from the vector, we must bail from
// the loop early if we delete an item, therefore this outer while loop is required.