diff options
author | Gregory Maxwell <greg@xiph.org> | 2012-08-28 22:04:38 -0400 |
---|---|---|
committer | Gregory Maxwell <greg@xiph.org> | 2012-08-28 22:04:38 -0400 |
commit | 6a60c64c6b4c6a8095e12b515fc7e30eedfab5ab (patch) | |
tree | 43dbceb1c0c4102c8275d96a70a53af698bc704e /src/irc.cpp | |
parent | 3595b18793a94a0cdfe64b5e0cfc0260e19661fe (diff) |
Don't retry a failing IRC nickname forever.
If our IRC nick is in use (because some other node thinks it has
the same address we think we have) don't fruitlessly try to reconnect
using that name forever. After three tries, give up and use a random
nick. Either we'll learn a new local address from IRC and switch
to that, or it was right and the other guy is advertising for us.
This avoids a pessimal case where a second testnet node behind
a nat is unable to get any peers because he can't get on IRC.
Diffstat (limited to 'src/irc.cpp')
-rw-r--r-- | src/irc.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/irc.cpp b/src/irc.cpp index 9e88541c2a..6991e6ee7e 100644 --- a/src/irc.cpp +++ b/src/irc.cpp @@ -222,6 +222,7 @@ void ThreadIRCSeed2(void* parg) printf("ThreadIRCSeed started\n"); int nErrorWait = 10; int nRetryWait = 10; + int nNameRetry = 0; while (!fShutdown) { @@ -257,7 +258,8 @@ void ThreadIRCSeed2(void* parg) CService addrLocal; string strMyName; // Don't use our IP as our nick if we're not listening - if (!fNoListen && GetLocal(addrLocal, &addrIPv4)) + // 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)); @@ -273,6 +275,7 @@ void ThreadIRCSeed2(void* parg) if (nRet == 2) { printf("IRC name already in use\n"); + nNameRetry++; Wait(10); continue; } @@ -282,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 |