// by an integer, meaning there is no need for a scan/search operation.
userrec* fd_ref_table[65536];
+int statsAccept = 0, statsRefused = 0, statsUnknown = 0, statsCollisions = 0, statsDns = 0, statsDnsGood = 0, statsDnsBad = 0, statsConnects = 0, statsSent= 0, statsRecv = 0;
+
serverrec* me[32];
FILE *log_file;
std::vector<userrec*> all_opers;
+static char already_sent[65536];
+
void AddOper(userrec* user)
{
log(DEBUG,"Oper added to optimization list");
if (sock != -1)
{
int MOD_RESULT = 0;
- FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes > 514 ? 514 : bytes));
+ FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes > 512 ? 512 : bytes));
if (!MOD_RESULT)
- write(sock,tb,bytes > 514 ? 514 : bytes);
+ write(sock,tb,bytes > 512 ? 512 : bytes);
if (fd_ref_table[sock])
{
- fd_ref_table[sock]->bytes_out += (bytes > 514 ? 514 : bytes);
+ fd_ref_table[sock]->bytes_out += (bytes > 512 ? 512 : bytes);
fd_ref_table[sock]->cmds_out++;
}
+ statsSent += (bytes > 512 ? 512 : bytes);
}
}
if (sock != -1)
{
int MOD_RESULT = 0;
- FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes > 514 ? 514 : bytes));
+ FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes > 512 ? 512 : bytes));
if (!MOD_RESULT)
- write(sock,tb,bytes > 514 ? 514 : bytes);
+ write(sock,tb,bytes > 512 ? 512 : bytes);
if (fd_ref_table[sock])
{
- fd_ref_table[sock]->bytes_out += (bytes > 514 ? 514 : bytes);
+ fd_ref_table[sock]->bytes_out += (bytes > 512 ? 512 : bytes);
fd_ref_table[sock]->cmds_out++;
}
+ statsSent += (bytes > 512 ? 512 : bytes);
}
}
if (sock != -1)
{
int MOD_RESULT = 0;
- FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes > 514 ? 514 : bytes));
+ FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes > 512 ? 512 : bytes));
if (!MOD_RESULT)
- write(sock,tb,bytes > 514 ? 514 : bytes);
+ write(sock,tb,bytes > 512 ? 512 : bytes);
if (fd_ref_table[sock])
{
- fd_ref_table[sock]->bytes_out += (bytes > 514 ? 514 : bytes);
+ fd_ref_table[sock]->bytes_out += (bytes > 512 ? 512 : bytes);
fd_ref_table[sock]->cmds_out++;
}
+ statsSent += (bytes > 512 ? 512 : bytes);
}
}
va_end(argsPtr);
// FIX: Stops a message going to the same person more than once
- std::vector<int> already_sent;
+ bzero(&already_sent,65536);
+
+ bool sent_to_at_least_one = false;
for (int i = 0; i < MAXCHANS; i++)
{
{
char* o = (*ulist)[j];
userrec* otheruser = (userrec*)o;
- bool do_send = true;
- for (int t = 0; t < already_sent.size(); t++)
+ if (!already_sent[otheruser->fd])
{
- if (already_sent[t] == otheruser->fd)
- {
- do_send = false;
- break;
- }
- }
- if (do_send)
- {
- already_sent.push_back(otheruser->fd);
+ already_sent[otheruser->fd] = 1;
WriteFrom(otheruser->fd,u,"%s",textbuffer);
+ sent_to_at_least_one = true;
}
}
}
}
// if the user was not in any channels, no users will receive the text. Make sure the user
// receives their OWN message for WriteCommon
- if (!already_sent.size())
+ if (!sent_to_at_least_one)
{
WriteFrom(u->fd,u,"%s",textbuffer);
}
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
va_end(argsPtr);
- std::vector<int> already_sent;
+ bzero(&already_sent,65536);
for (int i = 0; i < MAXCHANS; i++)
{
userrec* otheruser = (userrec*)o;
if (u != otheruser)
{
- bool do_send = true;
- for (int t = 0; t < already_sent.size(); t++)
- {
- if (already_sent[t] == otheruser->fd)
- {
- do_send = false;
- break;
- }
- }
- if (do_send)
+ if (!already_sent[otheruser->fd])
{
- already_sent.push_back(otheruser->fd);
+ already_sent[otheruser->fd] = 1;
WriteFrom(otheruser->fd,u,"%s",textbuffer);
}
}
iter = clientlist.find(tempnick);
- if (iter != clientlist.end()) return;
+ // fix by brain.
+ // as these nicknames are 'RFC impossible', we can be sure nobody is going to be
+ // using one as a registered connection. As theyre per fd, we can also safely assume
+ // that we wont have collisions. Therefore, if the nick exists in the list, its only
+ // used by a dead socket, erase the iterator so that the new client may reclaim it.
+ // this was probably the cause of 'server ignores me when i hammer it with reconnects'
+ // issue in earlier alphas/betas
+ if (iter != clientlist.end())
+ {
+ clientlist.erase(iter);
+ }
/*
* It is OK to access the value here this way since we know
}
if (clientlist.size() == MAXCLIENTS)
+ {
kill_link(clientlist[tempnick],"No more connections allowed in this class");
+ return;
+ }
+
+ // this is done as a safety check to keep the file descriptors within range of fd_ref_table.
+ // its a pretty big but for the moment valid assumption:
+ // file descriptors are handed out starting at 0, and are recycled as theyre freed.
+ // therefore if there is ever an fd over 65535, 65536 clients must be connected to the
+ // irc server at once (or the irc server otherwise initiating this many connections, files etc)
+ // which for the time being is a physical impossibility (even the largest networks dont have more
+ // than about 10,000 users on ONE server!)
+ if (socket > 65535)
+ {
+ kill_link(clientlist[tempnick],"Server is full");
+ return;
+ }
char* e = matches_exception(ip);
char reason[MAXBUF];
snprintf(reason,MAXBUF,"Z-Lined: %s",r);
kill_link(clientlist[tempnick],reason);
+ return;
}
}
fd_ref_table[socket] = clientlist[tempnick];
WholeMOTD = WholeMOTD + std::string(":") + std::string(ServerName) + std::string(" 376 ") + std::string(user->nick) + std::string(" :End of message of the day.\r\n");
// only one write operation
send(user->fd,WholeMOTD.c_str(),WholeMOTD.length(),0);
-
+ statsSent += WholeMOTD.length();
}
void ShowRULES(userrec *user)
/* shows the message of the day, and any other on-logon stuff */
void FullConnectUser(userrec* user)
{
+ statsConnects++;
user->registered = 7;
user->idle_lastmsg = TIME;
log(DEBUG,"ConnectUser: %s",user->nick);
FOREACH_RESULT(OnUserPreNick(user,newnick));
if (MOD_RESULT) {
+ statsCollisions++;
kill_link(user,"Nickname collision");
return;
}
if (matches_qline(newnick))
{
+ statsCollisions++;
kill_link(user,"Nickname collision");
return;
}
{
if (strchr("@!\"$%^&*(){}[]_=+;:'#~,<>/?\\|`",command[x]))
{
+ statsUnknown++;
WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command);
return;
}
}
if ((!cmd_found) && (user))
{
+ statsUnknown++;
WriteServ(user->fd,"421 %s %s :Unknown command",user->nick,command);
}
}
if ((curr) && (curr->fd != 0))
{
+#ifdef _POSIX_PRIORITY_SCHEDULING
+ sched_yield();
+#endif
// assemble up to 64 sockets into an fd_set
// to implement a pooling mechanism.
//
{
log(DEBUG,"signon exceed, registered=3, and modules ready, OK");
curr->dns_done = true;
+ statsDnsBad++;
FullConnectUser(curr);
goto label;
}
}
else result = result2;
log(DEBUG,"Read result: %d",result);
-
if (result)
{
+ statsRecv += result;
// perform a check on the raw buffer as an array (not a string!) to remove
// characters 0 and 7 which are illegal in the RFC - replace them with spaces.
// hopefully this should stop even more people whining about "Unknown command: *"
process_buffer(sanitized,current);
// look for the user's record in case it's changed... if theyve quit,
// we cant do anything more with their buffer, so bail.
+ // there used to be an ugly, slow loop here. Now we have a reference
+ // table, life is much easier (and FASTER)
if (!fd_ref_table[currfd])
goto label;
{
WriteOpers("*** WARNING: Accept failed on port %lu (%s)",(unsigned long)ports[count],target);
log(DEBUG,"InspIRCd: accept failed: %lu",(unsigned long)ports[count]);
+ statsRefused++;
}
else
{
FOREACH_MOD OnRawSocketAccept(incomingSockfd, resolved, ports[count]);
+ statsAccept++;
AddClient(incomingSockfd, resolved, ports[count], false, inet_ntoa (client.sin_addr));
log(DEBUG,"InspIRCd: adding client on port %lu fd=%lu",(unsigned long)ports[count],(unsigned long)incomingSockfd);
}
if (0) {};
#ifdef _POSIX_PRIORITY_SCHEDULING
sched_yield();
+ sched_yield();
#endif
}
/* not reached */