Research
Timechain
Search Donate
Sponsors
Cake Wallet, private Bitcoin and Monero walletSideShift.ai, no-signup crypto exchangeOrangeRock, non-custodial bitcoin spot and perps tradingBraiins Hashpower, buy and sell Bitcoin hashrateeCash.com
What changed

Bitcoin v0.3.19 → r202

5 files · +49 · −17 · 629e37dde · 2010-12-15 · s_nakamoto

Release commit message: get external ip from irc

Full source: v0.3.19. r202. Previous diff: v0.3.18 → v0.3.19. Next: r202 → v0.3.20.

irc.cpp (modified)

1--- v0.3.19/irc.cpp2+++ r202/irc.cpp3@@ -5,6 +5,7 @@4 #include "headers.h"5 6 int nGotIRCAddresses = 0;7+bool fGotExternalIP = false;8 9 void ThreadIRCSeed2(void* parg);10 11@@ -223,6 +224,8 @@12     }13     else14     {15+        // Hybrid IRC used by lfnet always returns IP when you userhost yourself,16+        // but in case another IRC is ever used this should work.17         printf("GetIPFromIRC() got userhost %s\n", strHost.c_str());18         if (fUseProxy)19             return false;20@@ -327,14 +330,15 @@21         }22         Sleep(500);23 24-        // Get my external IP from IRC server25+        // Get our external IP from the IRC server and re-nick before joining the channel26         CAddress addrFromIRC;27         if (GetIPFromIRC(hSocket, strMyName, addrFromIRC.ip))28         {29-            // Just using it as a backup for now30             printf("GetIPFromIRC() returned %s\n", addrFromIRC.ToStringIP().c_str());31-            if (addrFromIRC.IsRoutable() && !fUseProxy && !addrLocalHost.IsRoutable())32-            {33+            if (!fUseProxy && addrFromIRC.IsRoutable())34+            {35+                // IRC lets you to re-nick36+                fGotExternalIP = true;37                 addrLocalHost.ip = addrFromIRC.ip;38                 strMyName = EncodeAddress(addrLocalHost);39                 Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());

irc.h (modified)

1--- v0.3.19/irc.h2+++ r202/irc.h3@@ -6,4 +6,5 @@4 void ThreadIRCSeed(void* parg);5 6 extern int nGotIRCAddresses;7+extern bool fGotExternalIP;8 

main.h (modified)

1--- v0.3.19/main.h2+++ r202/main.h3@@ -1733,6 +1733,8 @@4 5 6 //7+// Alerts are for notifying old versions if they become too obsolete and8+// need to upgrade.  The message is displayed in the status bar.9 // Alert messages are broadcast as a vector of signed data.  Unserializing may10 // not read the entire buffer if the alert is for a newer version, but older11 // versions can still relay the original data.

net.cpp (modified)

1--- v0.3.19/net.cpp2+++ r202/net.cpp3@@ -163,7 +163,7 @@4     return error("GetMyExternalIP() : connection closed");5 }6 7-8+// We now get our external IP from the IRC server first and only use this as a backup9 bool GetMyExternalIP(unsigned int& ipRet)10 {11     CAddress addrConnect;12@@ -176,6 +176,10 @@13     for (int nLookup = 0; nLookup <= 1; nLookup++)14     for (int nHost = 1; nHost <= 2; nHost++)15     {16+        // We should be phasing out our use of sites like these.  If we need17+        // replacements, we should ask for volunteers to put this simple18+        // php file on their webserver that prints the client IP:19+        //  <?php echo $_SERVER["REMOTE_ADDR"]; ?>20         if (nHost == 1)21         {22             addrConnect = CAddress("91.198.22.70:80"); // checkip.dyndns.org23@@ -220,6 +224,36 @@24     }25 26     return false;27+}28+29+void ThreadGetMyExternalIP(void* parg)30+{31+    // Wait for IRC to get it first32+    if (!GetBoolArg("-noirc"))33+    {34+        for (int i = 0; i < 2 * 60; i++)35+        {36+            Sleep(1000);37+            if (fGotExternalIP || fShutdown)38+                return;39+        }40+    }41+42+    // Fallback in case IRC fails to get it43+    if (GetMyExternalIP(addrLocalHost.ip))44+    {45+        printf("GetMyExternalIP() returned %s\n", addrLocalHost.ToStringIP().c_str());46+        if (addrLocalHost.IsRoutable())47+        {48+            // If we already connected to a few before we had our IP, go back and addr them.49+            // setAddrKnown automatically filters any duplicate sends.50+            CAddress addr(addrLocalHost);51+            addr.nTime = GetAdjustedTime();52+            CRITICAL_BLOCK(cs_vNodes)53+                foreach(CNode* pnode, vNodes)54+                    pnode->PushAddress(addr);55+        }56+    }57 }58 59 60@@ -1310,8 +1344,7 @@61 #endif62     printf("addrLocalHost = %s\n", addrLocalHost.ToString().c_str());63 64-    // Get our external IP address for incoming connections65-    if (fUseProxy)66+    if (fUseProxy || mapArgs.count("-connect"))67     {68         // Proxies can't take incoming connections69         addrLocalHost.ip = CAddress("0.0.0.0").ip;70@@ -1319,15 +1352,7 @@71     }72     else73     {74-        if (addrIncoming.IsValid())75-            addrLocalHost.ip = addrIncoming.ip;76-77-        if (GetMyExternalIP(addrLocalHost.ip))78-        {79-            addrIncoming = addrLocalHost;80-            CWalletDB().WriteSetting("addrIncoming", addrIncoming);81-            printf("addrLocalHost = %s\n", addrLocalHost.ToString().c_str());82-        }83+        CreateThread(ThreadGetMyExternalIP, NULL);84     }85 86     //

serialize.h (modified)

1--- v0.3.19/serialize.h2+++ r202/serialize.h3@@ -25,7 +25,7 @@4 class CAutoFile;5 static const unsigned int MAX_SIZE = 0x02000000;6 7-static const int VERSION = 31900;8+static const int VERSION = 31901;9 static const char* pszSubVer = "";10 11 
0:000:00