CLEANUP: Convert HUB from compile-time define to runtime config
authorRemco Rijnders <remmy@serenity-irc.net>
Sat, 7 Mar 2026 17:17:36 +0000 (12:17 -0500)
committerRemco Rijnders <remmy@serenity-irc.net>
Sat, 7 Mar 2026 17:17:36 +0000 (12:17 -0500)
Hub mode is now configured via ircd.conf using the G: (general
config) line:

    G:hub

Default is leaf mode (non-hub) if not set. The setting is
re-evaluated on /rehash, so hub mode can be toggled without
recompiling or restarting the server.

Removes #ifdef HUB / #ifndef HUB from ircd.c, s_serv.c, s_debug.c,
config.h, and setup.h. Adds runtime is_hub global checked in:
- try_connections(): leaf prevents auto-connecting when already linked
- m_server(): leaf rejects incoming server links if already have one
- m_server(): hub sends GLOBOPS on new server link establishment
- m_version(): 'H' serveropts flag shown dynamically based on is_hub

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
doc/example.conf
include/config.h
include/h.h
include/setup.h [new file with mode: 0644]
src/ircd.c
src/s_conf.c
src/s_debug.c
src/s_serv.c

index 41a3ce7a1853c79495a419f661b50f95a178deed..356e1331ad9cbe9be3dd0427df84c97366746ab8 100644 (file)
@@ -260,6 +260,22 @@ H:*.mx.*:HubServer2.Serenity-IRC.Net
 #
 #
 #
+# G: OPTIONAL. General configuration options. These control runtime behavior
+# that was previously set at compile time.
+#
+# G:option
+#
+# Currently supported options:
+#   hub  - Enable hub mode. A hub server accepts multiple server connections
+#          and routes traffic between them. Without this option, the server
+#          runs as a leaf and will only maintain a single server link.
+#          This setting is re-evaluated on /rehash.
+#
+# Uncomment the following line if this server is a hub:
+#G:hub
+#
+#
+#
 # Q: OPTIONAL. Nick quarantine.  This line prevents non opers from using
 # nicks covered by the Q-line.
 #
index 70286972da2ae75a5fea0d6ac0bbfde66ad2565c..4b19c5352ca3552a51893442d68f8b9fcea7c9b4 100644 (file)
 #define MAXIMUM_LINKS 1
 
 /*
- * If your server is running as a a HUB Server then define this.
- * A HUB Server has many servers connect to it at the same as opposed
- * to a leaf which just has 1 server (typically the uplink). Define this
- * correctly for performance reasons.
+ * Hub mode is now a runtime setting via ircd.conf:
+ *   G:hub
+ * Default is leaf mode (non-hub) if not set.
  */
-/* #define     HUB */
 
 /*
  * NOTE: defining CMDLINE_CONFIG and installing ircd SUID or SGID is a MAJOR
index 7484bcb78bb376b77f05d4f49f07d091ea16b651..ee16d0f30d6dda09dd5675d3861bf38c77856f01 100644 (file)
@@ -134,6 +134,7 @@ extern      char    *inetntoa (char *);
 
 extern int     dbufalloc, dbufblocks, debuglevel, errno, h_errno;
 extern int     highest_fd, debuglevel, portnum, debugtty, maxusersperchannel;
+extern int     is_hub;
 extern int     readcalls, udpfd, resfd;
 extern aClient *add_connection (aClient *, int);
 extern int     add_listener (aConfItem *);
diff --git a/include/setup.h b/include/setup.h
new file mode 100644 (file)
index 0000000..3867d50
--- /dev/null
@@ -0,0 +1,33 @@
+#define IRCD_VERSION "Serene5.28"
+#undef HAVE_PARAM_H
+#define        HAVE_UNISTD_H
+#define        HAVE_STRING_H
+#define        HAVE_STRINGS_H
+#define        HAVE_STDLIB_H
+#define        HAVE_INDEX
+#define        HAVE_STRERROR
+#undef HAVE_STRTOKEN
+#define        HAVE_STRTOK
+#define        HAVE_INET_ADDR
+#define        HAVE_INET_NTOA
+#define        HAVE_INET_NETOF
+#define        GETTIMEOFDAY
+#undef HAVE_LRAND48
+#define        HAVE_STRCASECMP
+#define        HAVE_BZERO
+#define        HAVE_POSIX_NBLOCK
+#undef HAVE_BSD_NBLOCK
+#define        HAVE_POSIX_SIGNALS
+#undef HAVE_BSD_SIGNALS
+#undef HAVE_TIMES_2
+#define        HAVE_GETRUSAGE_2
+#define DPATH "/home/remmy/ircd"
+#define SPATH "/home/remmy/ircd/ircd"
+#define MAXCONNECTIONS 1024
+#define CRYPT_OPER_PASSWORD 1
+#define CRYPT_ILINE_PASSWORD 1
+#define CONTACT_URL "http://www.serenity-irc.net/connect.html"
+#define SERVICES_NAME "Services.Serenity-IRC.Net"
+#define KLINE_ADDRESS "remmy@serenity-irc.net"
+#define DOMAINNAME "glenmoor"
+#define ZIP_LINKS      1
index ed7cdfb813254d185e170853f653f00ca77d400a..bf61686464632043aa4622de9ad70728f64d1658 100644 (file)
@@ -79,6 +79,8 @@ time_t lastbwcheck = 0;       /* next time to do the bandwidtch check */
 int lu_noninv, lu_inv, lu_serv, lu_oper, lu_unknown, lu_channel, lu_lu,
     lu_lulocal, lu_lserv, lu_clu, lu_mlu, lu_cglobalu, lu_mglobalu;
 
+int is_hub = 0;
+
 #ifdef CLONE_CHECK
 aClone *Clones = NULL;
 char clonekillhost[100];
@@ -226,13 +228,11 @@ static time_t try_connections (time_t currenttime)
           ** and see if this server is already connected?
         */
        cptr = find_name (aconf->name, (aClient *) NULL);
-#ifndef HUB
-       /* Leaf servers should not connect to other servers, no matter 
-          what connect rules might exist when they are already connected 
+       /* Leaf servers should not connect to other servers, no matter
+          what connect rules might exist when they are already connected
           to another server.  -- Remmy */
-       if (cptr)
+       if (!is_hub && cptr)
            am_connected_leaf = TRUE;
-#endif /* HUB */
        /* zero second connect frequincy should mean "DISABLED" not 
           "connect every time we find the unconnected server in this 
           loop" dammit
index 8c227e7fce307ab86789df1d28e1b3f138dce4d2..03510fc9e22d794b640e788b324d9187811e2d93 100644 (file)
@@ -850,6 +850,7 @@ int initconf (int opt)
     int ccount = 0, ncount = 0;
     aConfItem *aconf = NULL;
 
+    is_hub = 0;
     Debug ((DEBUG_DEBUG, "initconf(): ircd.conf = %s", configfile));
     if ((fd = openconf ()) == -1) {
        return -1;
@@ -1047,7 +1048,8 @@ int initconf (int opt)
           ** is much better!  -Aeto
         */
        if ((aconf->status & CONF_CONFIG) == CONF_CONFIG) {
-
+           if (aconf->host && !mycmp (aconf->host, "hub"))
+               is_hub = 1;
            continue;
        }
        /* Check if Z:line time    -taz */
index 8989c11fe0993333c9fc49587d6b3f10efa022be..e6d33ceaafe5c003242332f93300b7e8ae9f9301 100644 (file)
@@ -32,9 +32,6 @@ char serveropts[] = {
 #ifdef DEBUGMODE
     'D',
 #endif
-#ifdef HUB
-    'H',
-#endif
 #ifdef SHOW_INVISIBLE_LUSERS
     'i',
 #endif
index 833a9835f887c97f2ddffad18070ad7da984e3d5..2f319da1e7a25e8fe04e0b61f254206fc5c3be62 100644 (file)
@@ -106,6 +106,7 @@ void s_die ();
 int m_version (aClient *cptr, aClient *sptr, int parc, char *parv[])
 {
     extern char serveropts[];
+    char opts[64];
 
     /* Make sure they stick to the local server if not registered.
      *  -Studded */
@@ -115,9 +116,15 @@ int m_version (aClient *cptr, aClient *sptr, int parc, char *parv[])
        return -1;
     }
     if (hunt_server (cptr, sptr, ":%s VERSION :%s", 1, parc, parv) ==
-       HUNTED_ISME)
+       HUNTED_ISME) {
+       /* Build options string, inserting 'H' if hub mode is active */
+       if (is_hub)
+           (void) sprintf (opts, "H%s", serveropts);
+       else
+           (void) strcpy (opts, serveropts);
        sendto_one (sptr, rpl_str (RPL_VERSION), me.name, parv[0], version,
-                   debugmode, me.name, serveropts);
+                   debugmode, me.name, opts);
+    }
     return 0;
 }
 
@@ -608,14 +615,14 @@ int m_server_estab (aClient *cptr)
     }
     memset (cptr->passwd, 0, sizeof (cptr->passwd));
 
-#ifndef        HUB
-    for (i = 0; i <= highest_fd; i++)
-       if (local[i] && IsServer (local[i])) {
-           ircstp->is_ref++;
-           sendto_one (cptr, "ERROR :I'm a leaf not a hub");
-           return exit_client (cptr, cptr, cptr, "I'm a leaf");
-       }
-#endif
+    if (!is_hub) {
+       for (i = 0; i <= highest_fd; i++)
+           if (local[i] && IsServer (local[i])) {
+               ircstp->is_ref++;
+               sendto_one (cptr, "ERROR :I'm a leaf not a hub");
+               return exit_client (cptr, cptr, cptr, "I'm a leaf");
+           }
+    }
     synchmode = 1;
 
     /* Check for bitflags here */
@@ -707,10 +714,9 @@ int m_server_estab (aClient *cptr)
        cptr->flags |= FLAGS_ULINE;
     cptr->flags |= FLAGS_TS8;
     nextping = time (NULL);
-#ifdef HUB
-    sendto_serv_butone (&me, ":%s GLOBOPS :Link with %s established.",
-                       me.name, inpath);
-#endif
+    if (is_hub)
+       sendto_serv_butone (&me, ":%s GLOBOPS :Link with %s established.",
+                           me.name, inpath);
     sendto_locfailops ("Link with %s established.", inpath);
     /* Insert here */
     (void) add_to_client_hash_table (cptr->name, cptr);