]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Remove check that very rarely equates to true
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 8176b833225291660f86fefd68b625b4aac8294a..a2b4e0d92e2c1e7ea67917c9a3d06196c5787752 100644 (file)
@@ -45,9 +45,6 @@
 #include <fstream>
 #include <vector>
 #include <deque>
-#ifdef THREADED_DNS
-#include <pthread.h>
-#endif
 #include "users.h"
 #include "ctables.h"
 #include "globals.h"
 #include "commands.h"
 #include "xline.h"
 #include "inspstring.h"
-#include "dnsqueue.h"
 #include "helperfuncs.h"
 #include "hashcomp.h"
 #include "socketengine.h"
+#include "inspircd_se_config.h"
 #include "userprocess.h"
 #include "socket.h"
 #include "typedefs.h"
@@ -70,9 +67,6 @@
 
 InspIRCd* ServerInstance;
 
-int WHOWAS_STALE = 48; // default WHOWAS Entries last 2 days before they go 'stale'
-int WHOWAS_MAX = 100;  // default 100 people maximum in the WHOWAS list
-
 extern ModuleList modules;
 extern FactoryList factory;
 
@@ -81,29 +75,23 @@ std::vector<userrec*> local_users;
 
 extern int MODCOUNT;
 extern char LOG_FILE[MAXBUF];
-int openSockfd[MAX_DESCRIPTORS];
-int yield_depth;
+
 int iterations = 0;
 
 insp_sockaddr client, server;
-
 socklen_t length;
 
 extern InspSocket* socket_ref[MAX_DESCRIPTORS];
-
 time_t TIME = time(NULL), OLDTIME = time(NULL);
 
 // This table references users by file descriptor.
 // its an array to make it VERY fast, as all lookups are referenced
 // by an integer, meaning there is no need for a scan/search operation.
 userrec* fd_ref_table[MAX_DESCRIPTORS];
-
 Server* MyServer = new Server;
 ServerConfig *Config = new ServerConfig;
-
 user_hash clientlist;
 chan_hash chanlist;
-
 servernamelist servernames;
 char lowermap[255];
 
@@ -302,13 +290,14 @@ InspIRCd::InspIRCd(int argc, char** argv)
 
        OpenLog(argv, argc);
        this->stats = new serverstats();
+       this->Parser = new CommandParser();
        Config->ClearStack();
        Config->Read(true,NULL);
        CheckRoot();
        this->ModeGrok = new ModeParser();
-       this->Parser = new CommandParser();
        AddServerName(Config->ServerName);
        CheckDie();
+       InitializeDisabledCommands(Config->DisabledCommands, this);
        stats->BoundPortCount = BindPorts(true);
 
        for(int t = 0; t < 255; t++)
@@ -330,7 +319,9 @@ InspIRCd::InspIRCd(int argc, char** argv)
        /* Because of limitations in kqueue on freebsd, we must fork BEFORE we
         * initialize the socket engine.
         */
-       SE = new SocketEngine();
+       SocketEngineFactory* SEF = new SocketEngineFactory();
+       SE = SEF->Create();
+       delete SEF;
 
        /* We must load the modules AFTER initializing the socket engine, now */
 
@@ -340,11 +331,7 @@ InspIRCd::InspIRCd(int argc, char** argv)
 std::string InspIRCd::GetVersionString()
 {
        char versiondata[MAXBUF];
-#ifdef THREADED_DNS
-       char dnsengine[] = "multithread";
-#else
-       char dnsengine[] = "singlethread";
-#endif
+       char dnsengine[] = "singlethread-object";
        if (*Config->CustomVersion)
        {
                snprintf(versiondata,MAXBUF,"%s %s :%s",VERSION,Config->ServerName,Config->CustomVersion);
@@ -361,7 +348,7 @@ char* InspIRCd::ModuleError()
        return MODERR;
 }
 
-void InspIRCd::erase_factory(int j)
+void InspIRCd::EraseFactory(int j)
 {
        int v = 0;
        for (std::vector<ircd_module*>::iterator t = factory.begin(); t != factory.end(); t++)
@@ -376,7 +363,7 @@ void InspIRCd::erase_factory(int j)
        }
 }
 
-void InspIRCd::erase_module(int j)
+void InspIRCd::EraseModule(int j)
 {
        int v1 = 0;
        for (std::vector<Module*>::iterator m = modules.begin(); m!= modules.end(); m++)
@@ -537,9 +524,9 @@ bool InspIRCd::UnloadModule(const char* filename)
 
                        // found the module
                        log(DEBUG,"Deleting module...");
-                       erase_module(j);
+                       this->EraseModule(j);
                        log(DEBUG,"Erasing module entry...");
-                       erase_factory(j);
+                       this->EraseFactory(j);
                        log(DEBUG,"Removing dependent commands...");
                        Parser->RemoveCommands(filename);
                        log(DEFAULT,"Module %s unloaded",filename);
@@ -694,11 +681,6 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
        insp_sockaddr sock_us;     // our port number
        socklen_t uslen;         // length of our port number
 
-       if (yield_depth > 100)
-               return;
-
-       yield_depth++;
-
        /* time() seems to be a pretty expensive syscall, so avoid calling it too much.
         * Once per loop iteration is pleanty.
         */
@@ -731,7 +713,6 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
                }
                TickMissedTimers(TIME);
                expire_run = true;
-               yield_depth--;
                return;
        }   
        else if ((TIME % 5) == 1)
@@ -772,10 +753,7 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
         * servers... so its nice and easy, just one call.
         */
        if (!(numberactive = SE->Wait(activefds)))
-       {
-               yield_depth--;
                return;
-       }
 
        /**
         * Now process each of the fd's. For users, we have a fast
@@ -838,22 +816,16 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
                        break;
 
                        case X_ESTAB_DNS:
-                               /* When we are using single-threaded dns,
-                                * the sockets for dns end up in our mainloop.
-                                * When we are using multi-threaded dns,
-                                * each thread has its own basic poll() loop
-                                * within it, making them 'fire and forget'
-                                * and independent of the mainloop.
+                               /* Handles instances of the Resolver class,
+                                * a simple class extended by modules and the core for
+                                * nonblocking resolving of addresses.
                                 */
-#ifndef THREADED_DNS
-                               log(DEBUG,"Type: X_ESTAB_DNS: fd=%d",activefds[activefd]);
-                               dns_poll(activefds[activefd]);
-#endif
+                               this->Res->MarshallReads(activefds[activefd]);
                        break;
 
                        case X_LISTEN:
 
-                               log(DEBUG,"Type: X_LISTEN_MODULE: fd=%d",activefds[activefd]);
+                               log(DEBUG,"Type: X_LISTEN: fd=%d",activefds[activefd]);
 
                                /* It's a listener */
                                uslen = sizeof(sock_us);
@@ -862,7 +834,11 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
        
                                if ((incomingSockfd > -1) && (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen)))
                                {
+#ifdef IPV6
+                                       in_port = ntohs(sock_us.sin6_port);
+#else
                                        in_port = ntohs(sock_us.sin_port);
+#endif
                                        log(DEBUG,"Accepted socket %d",incomingSockfd);
                                        /* Years and years ago, we used to resolve here
                                         * using gethostbyaddr(). That is sucky and we
@@ -873,7 +849,11 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
                                        {
                                                try
                                                {
-                                                       Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, inet_ntoa(client.sin_addr), in_port);
+#ifdef IPV6
+                                                       Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin6_addr), in_port);
+#else
+                                                       Config->GetIOHook(in_port)->OnRawSocketAccept(incomingSockfd, insp_ntoa(client.sin_addr), in_port);
+#endif
                                                }
                                                catch (ModuleException& modexcept)
                                                {
@@ -881,12 +861,18 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
                                                }
                                        }
                                        stats->statsAccept++;
+#ifdef IPV6
+                                       log(DEBUG,"Add ipv6 client");
+                                       AddClient(incomingSockfd, in_port, false, client.sin6_addr);
+#else
+                                       log(DEBUG,"Add ipv4 client");
                                        AddClient(incomingSockfd, in_port, false, client.sin_addr);
-                                       log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)in_port,(unsigned long)incomingSockfd);
+#endif
+                                       log(DEBUG,"Adding client on port %d fd=%d",in_port,incomingSockfd);
                                }
                                else
                                {
-                                       log(DEBUG,"Accept failed on fd %lu: %s",(unsigned long)incomingSockfd,strerror(errno));
+                                       log(DEBUG,"Accept failed on fd %d: %s",incomingSockfd,strerror(errno));
                                        shutdown(incomingSockfd,2);
                                        close(incomingSockfd);
                                        stats->statsRefused++;
@@ -904,13 +890,14 @@ void InspIRCd::DoOneIteration(bool process_module_sockets)
                        break;
                }
        }
-       yield_depth--;
 }
 
 int InspIRCd::Run()
 {
        /* Until THIS point, ServerInstance == NULL */
        
+       this->Res = new DNS();
+
        LoadAllModules(this);
 
        /* Just in case no modules were loaded - fix for bug #101 */
@@ -928,14 +915,13 @@ int InspIRCd::Run()
        /* Add the listening sockets used for client inbound connections
         * to the socket engine
         */
-       for (int count = 0; count < stats->BoundPortCount; count++)
-               SE->AddFd(openSockfd[count],true,X_LISTEN);
+       for (unsigned long count = 0; count < stats->BoundPortCount; count++)
+               SE->AddFd(Config->openSockfd[count],true,X_LISTEN);
 
        this->WritePID(Config->PID);
 
        /* main loop, this never returns */
        expire_run = false;
-       yield_depth = 0;
        iterations = 0;
 
        while (true)
@@ -954,6 +940,14 @@ int InspIRCd::Run()
 
 int main(int argc, char** argv)
 {
+       /* This is a MatchCIDR() test suite -
+       printf("Should be 0: %d\n",MatchCIDR("127.0.0.1","1.2.3.4/8"));
+       printf("Should be 1: %d\n",MatchCIDR("127.0.0.1","127.0.0.0/8"));
+       printf("Should be 1: %d\n",MatchCIDR("127.0.0.1","127.0.0.0/18"));
+       printf("Should be 0: %d\n",MatchCIDR("3ffe::0","2fc9::0/16"));
+       printf("Should be 1: %d\n",MatchCIDR("3ffe:1:3::0", "3ffe:1::0/32"));
+       exit(0); */
+
        try
        {
                ServerInstance = new InspIRCd(argc, argv);