diff options
author | Jeff Garzik <jgarzik@exmulti.com> | 2012-08-29 11:02:21 -0700 |
---|---|---|
committer | Jeff Garzik <jgarzik@exmulti.com> | 2012-08-29 11:02:21 -0700 |
commit | 4445434a2d749a7a354788317c09ea3d318a2372 (patch) | |
tree | b9865ebdc9a88f297d31be4bf11a2f49c7a5d65f /src | |
parent | 74d36d44f2584056e2fb7c0b82dc0507e2f0c5e1 (diff) | |
parent | 6a60c64c6b4c6a8095e12b515fc7e30eedfab5ab (diff) |
Merge pull request #1745 from gmaxwell/irc_fixes
Misc IRC fixes.
Diffstat (limited to 'src')
-rw-r--r-- | src/irc.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/irc.cpp b/src/irc.cpp index 50c6a5b4db..6991e6ee7e 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -207,16 +207,22 @@ void ThreadIRCSeed(void* parg) void ThreadIRCSeed2(void* parg) { - /* Don't advertise on IRC if we don't allow incoming connections */ - if (mapArgs.count("-connect") || fNoListen) + // Don't connect to IRC if we won't use IPv4 connections. + if (IsLimited(NET_IPV4)) return; + // ... or if we won't make outbound connections and won't accept inbound ones. + if (mapArgs.count("-connect") && fNoListen) + return; + + // ... or if IRC is not enabled. if (!GetBoolArg("-irc", false)) return; printf("ThreadIRCSeed started\n"); int nErrorWait = 10; int nRetryWait = 10; + int nNameRetry = 0; while (!fShutdown) { @@ -251,7 +257,9 @@ void ThreadIRCSeed2(void* parg) CNetAddr addrIPv4("1.2.3.4"); // arbitrary IPv4 address to make GetLocal prefer IPv4 addresses CService addrLocal; string strMyName; - if (GetLocal(addrLocal, &addrIPv4)) + // Don't use our IP as our nick if we're not listening + // or if it keeps failing because the nick is already in use. + if (!fNoListen && GetLocal(addrLocal, &addrIPv4) && nNameRetry<3) strMyName = EncodeAddress(GetLocalAddress(&addrConnect)); if (strMyName == "") strMyName = strprintf("x%u", GetRand(1000000000)); @@ -267,6 +275,7 @@ void ThreadIRCSeed2(void* parg) if (nRet == 2) { printf("IRC name already in use\n"); + nNameRetry++; Wait(10); continue; } @@ -276,6 +285,7 @@ void ThreadIRCSeed2(void* parg) else return; } + nNameRetry = 0; Sleep(500); // Get our external IP from the IRC server and re-nick before joining the channel @@ -283,7 +293,8 @@ void ThreadIRCSeed2(void* parg) if (GetIPFromIRC(hSocket, strMyName, addrFromIRC)) { printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToString().c_str()); - if (addrFromIRC.IsRoutable()) + // Don't use our IP as our nick if we're not listening + if (!fNoListen && addrFromIRC.IsRoutable()) { // IRC lets you to re-nick AddLocal(addrFromIRC, LOCAL_IRC); @@ -291,7 +302,7 @@ void ThreadIRCSeed2(void* parg) Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); } } - + if (fTestNet) { Send(hSocket, "JOIN #bitcoinTEST3\r"); Send(hSocket, "WHO #bitcoinTEST3\r"); |