From 050ed833add7bdb5465cb3d4b6cd548a2c93502a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Remco=20R=C4=B3nders?= Date: Sat, 7 Mar 2026 12:17:36 -0500 Subject: [PATCH] CLEANUP: Convert HUB from compile-time define to runtime config 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 --- doc/example.conf | 16 ++++++++++++++++ include/config.h | 8 +++----- include/h.h | 1 + include/setup.h | 33 +++++++++++++++++++++++++++++++++ src/ircd.c | 10 +++++----- src/s_conf.c | 4 +++- src/s_debug.c | 3 --- src/s_serv.c | 34 ++++++++++++++++++++-------------- 8 files changed, 81 insertions(+), 28 deletions(-) create mode 100644 include/setup.h diff --git a/doc/example.conf b/doc/example.conf index 41a3ce7..356e133 100644 --- a/doc/example.conf +++ b/doc/example.conf @@ -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. # diff --git a/include/config.h b/include/config.h index 7028697..4b19c53 100644 --- a/include/config.h +++ b/include/config.h @@ -285,12 +285,10 @@ #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 diff --git a/include/h.h b/include/h.h index 7484bcb..ee16d0f 100644 --- a/include/h.h +++ b/include/h.h @@ -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 index 0000000..3867d50 --- /dev/null +++ b/include/setup.h @@ -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 diff --git a/src/ircd.c b/src/ircd.c index ed7cdfb..bf61686 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -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 diff --git a/src/s_conf.c b/src/s_conf.c index 8c227e7..03510fc 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -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 */ diff --git a/src/s_debug.c b/src/s_debug.c index 8989c11..e6d33ce 100644 --- a/src/s_debug.c +++ b/src/s_debug.c @@ -32,9 +32,6 @@ char serveropts[] = { #ifdef DEBUGMODE 'D', #endif -#ifdef HUB - 'H', -#endif #ifdef SHOW_INVISIBLE_LUSERS 'i', #endif diff --git a/src/s_serv.c b/src/s_serv.c index 833a983..2f319da 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -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); -- 2.30.2