diff options
-rw-r--r-- | data/example.conf | 8 | ||||
-rw-r--r-- | include/modules.h | 6 | ||||
-rw-r--r-- | src/main.c | 18 | ||||
-rw-r--r-- | src/modules/ssl/m_ssl.cpp | 18 |
4 files changed, 30 insertions, 20 deletions
diff --git a/data/example.conf b/data/example.conf index 17672bd6e..aa7d9ab8b 100644 --- a/data/example.conf +++ b/data/example.conf @@ -91,10 +91,16 @@ uplink host = "localhost" /* - * Enable if Services should connect using IPv6 + * Enable if Services should connect using IPv6. */ ipv6 = no + /* + * Enable if Services should connect using SSL. + * You must have m_ssl loaded for this to work. + */ + ssl = no + /* * The port to connect to. * The IRCd *MUST* be configured to listen on this port, and to accept diff --git a/include/modules.h b/include/modules.h index 3f5de12da..174fb6e04 100644 --- a/include/modules.h +++ b/include/modules.h @@ -577,10 +577,12 @@ class CoreExport Module */ virtual void OnChanExpire(const char *chname) { } - /** Called before anope connects to its uplink + /** Called before Anope connects to its uplink + * @param u The uplink we're going to connect to + * @param Number What number the uplink is * @return Other than EVENT_CONTINUE to stop attempting to connect */ - virtual EventReturn OnPreServerConnect() { return EVENT_CONTINUE; } + virtual EventReturn OnPreServerConnect(Uplink *u, int Number) { return EVENT_CONTINUE; } /** Called when Anope connects to its uplink */ diff --git a/src/main.c b/src/main.c index 4c91fcde2..68423e4ec 100644 --- a/src/main.c +++ b/src/main.c @@ -389,19 +389,21 @@ std::string GetFullProgDir(char *argv0) static bool Connect() { - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreServerConnect, OnPreServerConnect()); - if (MOD_RESULT != EVENT_CONTINUE) - { - return (MOD_RESULT == EVENT_ALLOW ? true : false); - } - /* Connect to the remote server */ int servernum = 1; for (std::list<Uplink *>::iterator curr_uplink = Config.Uplinks.begin(); curr_uplink != Config.Uplinks.end(); ++curr_uplink, ++servernum) { uplink_server = *curr_uplink; + EventReturn MOD_RESULT; + FOREACH_RESULT(I_OnPreServerConnect, OnPreServerConnect(*curr_uplink, servernum)); + if (MOD_RESULT != EVENT_CONTINUE) + { + if (MOD_RESULT == EVENT_STOP) + break; + return true; + } + try { new UplinkSocket(uplink_server->host, uplink_server->port, Config.LocalHost ? Config.LocalHost : "", uplink_server->ipv6); @@ -416,6 +418,8 @@ static bool Connect() return true; } + uplink_server = NULL; + return false; } diff --git a/src/modules/ssl/m_ssl.cpp b/src/modules/ssl/m_ssl.cpp index 075352551..be3e5da1f 100644 --- a/src/modules/ssl/m_ssl.cpp +++ b/src/modules/ssl/m_ssl.cpp @@ -122,28 +122,26 @@ class SSLModule : public Module SSL_CTX_free(ctx); } - EventReturn OnPreServerConnect() + EventReturn OnPreServerConnect(Uplink *u, int Number) { - int servernum = 1; - for (std::list<Uplink *>::iterator curr_uplink = Config.Uplinks.begin(); curr_uplink != Config.Uplinks.end(); ++curr_uplink, ++servernum) - { - uplink_server = *curr_uplink; + ConfigReader config; + if (config.ReadFlag("uplink", "ssl", "no", Number - 1)) + { try { - new SSLSocket(uplink_server->host, uplink_server->port, Config.LocalHost ? Config.LocalHost : "", uplink_server->ipv6); + new SSLSocket(u->host, u->port, Config.LocalHost ? Config.LocalHost : "", u->ipv6); + Alog() << "Connected to Server " << Number << " (" << u->host << ":" << u->port << ")"; } catch (SocketException& ex) { - Alog() << "Unable to connect to server" << servernum << " (" << uplink_server->host << ":" << uplink_server->port << "), " << ex.GetReason(); - continue; + Alog() << "Unable to connect with SSL to server" << Number << " (" << u->host << ":" << u->port << "), " << ex.GetReason(); } - Alog() << "Connected to Server " << servernum << " (" << uplink_server->host << ":" << uplink_server->port << ")"; return EVENT_ALLOW; } - return EVENT_STOP; + return EVENT_CONTINUE; } }; |