diff -Naur bitcoin-0.1.0/readme.txt bitcoin-0.1.3/readme.txt --- bitcoin-0.1.0/readme.txt 2009-01-07 01:00:00.000000000 +0100 +++ bitcoin-0.1.3/readme.txt 2009-01-12 01:03:00.000000000 +0100 @@ -1,4 +1,4 @@ -BitCoin v0.01 ALPHA +BitCoin v0.1.3 ALPHA Copyright (c) 2009 Satoshi Nakamoto Distributed under the MIT/X11 software license, see the accompanying diff -Naur bitcoin-0.1.0/src/db.cpp bitcoin-0.1.3/src/db.cpp --- bitcoin-0.1.0/src/db.cpp 2009-01-07 01:00:00.000000000 +0100 +++ bitcoin-0.1.3/src/db.cpp 2009-01-11 01:02:00.000000000 +0100 @@ -454,6 +454,10 @@ foreach(const PAIRTYPE(vector, CAddress)& item, mapAddresses) item.second.print(); printf("-----\n"); + + // Fix for possible GCC bug that manifests in mapAddresses.count in irc.cpp, + // just need to call count here and it doesn't happen there, do not delete this! + mapAddresses.count(vector(18)); } return true; diff -Naur bitcoin-0.1.0/src/irc.cpp bitcoin-0.1.3/src/irc.cpp --- bitcoin-0.1.0/src/irc.cpp 2009-01-10 01:01:00.000000000 +0100 +++ bitcoin-0.1.3/src/irc.cpp 2009-01-11 01:02:00.000000000 +0100 @@ -136,14 +136,30 @@ } } +bool Wait(int nSeconds) +{ + if (fShutdown) + return false; + printf("Waiting %d seconds to reconnect to IRC\n", nSeconds); + for (int i = 0; i < nSeconds; i++) + { + if (fShutdown) + return false; + Sleep(1000); + } + return true; +} -bool fRestartIRCSeed = false; - void ThreadIRCSeed(void* parg) { - loop + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL); + int nErrorWait = 30; + int nRetryWait = 10; + + + while (!fShutdown) { struct hostent* phostent = gethostbyname("chat.freenode.net"); CAddress addrConnect(*(u_long*)phostent->h_addr_list[0], htons(6667)); @@ -152,13 +168,19 @@ if (!ConnectSocket(addrConnect, hSocket)) { printf("IRC connect failed\n"); - return; + if (Wait(nErrorWait += 60)) + continue; + else + return; } if (!RecvUntil(hSocket, "Found your hostname", "using your IP address instead", "Couldn't look up your hostname")) { closesocket(hSocket); - return; + if (Wait(nErrorWait += 60)) + continue; + else + return; } string strMyName = EncodeAddress(addrLocalHost); @@ -166,28 +188,27 @@ if (!addrLocalHost.IsRoutable()) strMyName = strprintf("x%u", GetRand(1000000000)); + Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str()); Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str()); if (!RecvUntil(hSocket, " 004 ")) { closesocket(hSocket); - return; + if (Wait(nErrorWait += 60)) + continue; + else + return; } Sleep(500); Send(hSocket, "JOIN #bitcoin\r"); Send(hSocket, "WHO #bitcoin\r"); - while (!fRestartIRCSeed) + string strLine; + while (!fShutdown && RecvLineIRC(hSocket, strLine)) { - string strLine; - if (fShutdown || !RecvLineIRC(hSocket, strLine)) - { - closesocket(hSocket); - return; - } - if (strLine.empty() || strLine[0] != ':') + if (strLine.empty() || strLine.size() > 900 || strLine[0] != ':') continue; printf("IRC %s\n", strLine.c_str()); @@ -207,7 +228,7 @@ printf("GOT WHO: [%s] ", pszName); } - if (vWords[1] == "JOIN") + if (vWords[1] == "JOIN" && vWords[0].size() > 1) { // :username!username@50000007.F000000B.90000002.IP JOIN :#channelname strcpy(pszName, vWords[0].c_str() + 1); @@ -231,10 +252,12 @@ printf("decode failed\n"); } } - } - fRestartIRCSeed = false; + } closesocket(hSocket); + + if (!Wait(nRetryWait += 10)) + return; } } diff -Naur bitcoin-0.1.0/src/main.cpp bitcoin-0.1.3/src/main.cpp --- bitcoin-0.1.0/src/main.cpp 2009-01-07 01:00:00.000000000 +0100 +++ bitcoin-0.1.3/src/main.cpp 2009-01-07 01:00:00.000000000 +0100 @@ -1734,7 +1734,7 @@ pfrom->PushMessage("getblocks", CBlockLocator(pindexBest), uint256(0)); } - printf("version addrMe = %s\n", addrMe.ToString().c_str()); + printf("version message: %s has version %d, addrMe=%s\n", pfrom->addr.ToString().c_str(), pfrom->nVersion, addrMe.ToString().c_str()); } diff -Naur bitcoin-0.1.0/src/net.cpp bitcoin-0.1.3/src/net.cpp --- bitcoin-0.1.0/src/net.cpp 2009-01-07 01:00:00.000000000 +0100 +++ bitcoin-0.1.3/src/net.cpp 2009-01-12 01:03:00.000000000 +0100 @@ -41,7 +41,7 @@ { hSocketRet = INVALID_SOCKET; - SOCKET hSocket = socket(AF_INET, SOCK_STREAM, 0); + SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (hSocket == INVALID_SOCKET) return false; @@ -89,20 +89,13 @@ } -bool GetMyExternalIP(unsigned int& ipRet) -{ - CAddress addrConnect("72.233.89.199:80"); // whatismyip.com 198-200 +bool GetMyExternalIP2(const CAddress& addrConnect, const char* pszGet, const char* pszKeyword, unsigned int& ipRet) +{ SOCKET hSocket; if (!ConnectSocket(addrConnect, hSocket)) return error("GetMyExternalIP() : connection to %s failed\n", addrConnect.ToString().c_str()); - char* pszGet = - "GET /automation/n09230945.asp HTTP/1.1\r\n" - "Host: www.whatismyip.com\r\n" - "User-Agent: Bitcoin/0.1\r\n" - "Connection: close\r\n" - "\r\n"; send(hSocket, pszGet, strlen(pszGet), 0); string strLine; @@ -110,15 +103,27 @@ { if (strLine.empty()) { - if (!RecvLine(hSocket, strLine)) + loop { - closesocket(hSocket); - return false; + if (!RecvLine(hSocket, strLine)) + { + closesocket(hSocket); + return false; + } + if (strLine.find(pszKeyword) != -1) + { + strLine = strLine.substr(strLine.find(pszKeyword) + strlen(pszKeyword)); + break; + } } closesocket(hSocket); + if (strLine.find("<")) + strLine = strLine.substr(0, strLine.find("<")); + strLine = strLine.substr(strspn(strLine.c_str(), " \t\n\r")); + strLine = wxString(strLine).Trim(); CAddress addr(strLine.c_str()); printf("GetMyExternalIP() received [%s] %s\n", strLine.c_str(), addr.ToString().c_str()); - if (addr.ip == 0) + if (addr.ip == 0 || !addr.IsRoutable()) return false; ipRet = addr.ip; return true; @@ -129,6 +134,59 @@ } +bool GetMyExternalIP(unsigned int& ipRet) +{ + CAddress addrConnect; + char* pszGet; + char* pszKeyword; + + for (int nLookup = 0; nLookup <= 1; nLookup++) + for (int nHost = 1; nHost <= 2; nHost++) + { + if (nHost == 1) + { + addrConnect = CAddress("70.86.96.218:80"); // www.ipaddressworld.com + + if (nLookup == 1) + { + struct hostent* phostent = gethostbyname("www.ipaddressworld.com"); + addrConnect = CAddress(*(u_long*)phostent->h_addr_list[0], htons(80)); + } + + pszGet = "GET /ip.php HTTP/1.1\r\n" + "Host: www.ipaddressworld.com\r\n" + "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n" + "Connection: close\r\n" + "\r\n"; + + pszKeyword = "IP:"; + } + else if (nHost == 2) + { + addrConnect = CAddress("208.78.68.70:80"); // checkip.dyndns.org + + if (nLookup == 1) + { + struct hostent* phostent = gethostbyname("checkip.dyndns.org"); + addrConnect = CAddress(*(u_long*)phostent->h_addr_list[0], htons(80)); + } + + pszGet = "GET / HTTP/1.1\r\n" + "Host: checkip.dyndns.org\r\n" + "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n" + "Connection: close\r\n" + "\r\n"; + + pszKeyword = "Address:"; + } + + if (GetMyExternalIP2(addrConnect, pszGet, pszKeyword, ipRet)) + return true; + } + + return false; +} + @@ -322,6 +380,11 @@ /// debug print printf("connected %s\n", addrConnect.ToString().c_str()); + // Set to nonblocking + u_long nOne = 1; + if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR) + printf("ConnectSocket() : ioctlsocket nonblocking setting failed, error %d\n", WSAGetLastError()); + // Add node CNode* pnode = new CNode(hSocket, addrConnect, false); if (nTimeout != 0) @@ -406,37 +469,6 @@ // CRITICAL_BLOCK(cs_vNodes) { - // Disconnect duplicate connections - map mapFirst; - foreach(CNode* pnode, vNodes) - { - if (pnode->fDisconnect) - continue; - unsigned int ip = pnode->addr.ip; - if (mapFirst.count(ip) && addrLocalHost.ip < ip) - { - // In case two nodes connect to each other at once, - // the lower ip disconnects its outbound connection - CNode* pnodeExtra = mapFirst[ip]; - - if (pnodeExtra->GetRefCount() > (pnodeExtra->fNetworkNode ? 1 : 0)) - swap(pnodeExtra, pnode); - - if (pnodeExtra->GetRefCount() <= (pnodeExtra->fNetworkNode ? 1 : 0)) - { - printf("(%d nodes) disconnecting duplicate: %s\n", vNodes.size(), pnodeExtra->addr.ToString().c_str()); - if (pnodeExtra->fNetworkNode && !pnode->fNetworkNode) - { - pnode->AddRef(); - swap(pnodeExtra->fNetworkNode, pnode->fNetworkNode); - pnodeExtra->Release(); - } - pnodeExtra->fDisconnect = true; - } - } - mapFirst[ip] = pnode; - } - // Disconnect unused nodes vector vNodesCopy = vNodes; foreach(CNode* pnode, vNodesCopy) @@ -755,10 +787,14 @@ // Once we've chosen an IP, we'll try every given port before moving on foreach(const CAddress& addrConnect, (*mi).second) { + CheckForShutdown(1); if (addrConnect.ip == addrLocalHost.ip || !addrConnect.IsIPv4() || FindNode(addrConnect.ip)) continue; + vfThreadRunning[1] = false; CNode* pnode = ConnectNode(addrConnect); + vfThreadRunning[1] = true; + CheckForShutdown(1); if (!pnode) continue; pnode->fNetworkNode = true; @@ -1000,8 +1036,19 @@ printf("StopNode()\n"); fShutdown = true; nTransactionsUpdated++; - while (count(vfThreadRunning.begin(), vfThreadRunning.end(), true)) - Sleep(10); + int64 nStart = GetTime(); + while (vfThreadRunning[0] || vfThreadRunning[2] || vfThreadRunning[3]) + { + if (GetTime() - nStart > 15) + break; + Sleep(20); + } + if (vfThreadRunning[0]) printf("ThreadSocketHandler still running\n"); + if (vfThreadRunning[1]) printf("ThreadOpenConnections still running\n"); + if (vfThreadRunning[2]) printf("ThreadMessageHandler still running\n"); + if (vfThreadRunning[3]) printf("ThreadBitcoinMiner still running\n"); + while (vfThreadRunning[2]) + Sleep(20); Sleep(50); // Sockets shutdown diff -Naur bitcoin-0.1.0/src/net.h bitcoin-0.1.3/src/net.h --- bitcoin-0.1.0/src/net.h 2009-01-07 01:00:00.000000000 +0100 +++ bitcoin-0.1.3/src/net.h 2009-01-11 01:02:00.000000000 +0100 @@ -153,7 +153,7 @@ nLastFailed = 0; } - CAddress(unsigned int ipIn, unsigned short portIn, uint64 nServicesIn=0) + CAddress(unsigned int ipIn, unsigned short portIn=DEFAULT_PORT, uint64 nServicesIn=0) { nServices = nServicesIn; memcpy(pchReserved, pchIPv4, sizeof(pchReserved)); @@ -262,7 +262,7 @@ bool IsRoutable() const { - return !(GetByte(3) == 10 || (GetByte(3) == 192 && GetByte(2) == 168)); + return !(GetByte(3) == 10 || (GetByte(3) == 192 && GetByte(2) == 168) || GetByte(3) == 127 || GetByte(3) == 0); } unsigned char GetByte(int n) const diff -Naur bitcoin-0.1.0/src/readme.txt bitcoin-0.1.3/src/readme.txt --- bitcoin-0.1.0/src/readme.txt 2009-01-07 01:00:00.000000000 +0100 +++ bitcoin-0.1.3/src/readme.txt 2009-01-12 01:03:00.000000000 +0100 @@ -1,4 +1,4 @@ -BitCoin v0.01 ALPHA +BitCoin v0.1.3 ALPHA Copyright (c) 2009 Satoshi Nakamoto Distributed under the MIT/X11 software license, see the accompanying diff -Naur bitcoin-0.1.0/src/serialize.h bitcoin-0.1.3/src/serialize.h --- bitcoin-0.1.0/src/serialize.h 2009-01-10 01:01:00.000000000 +0100 +++ bitcoin-0.1.3/src/serialize.h 2009-01-07 01:00:00.000000000 +0100 @@ -19,7 +19,7 @@ class CDataStream; class CAutoFile; -static const int VERSION = 101; +static const int VERSION = 103; diff -Naur bitcoin-0.1.0/src/ui.h bitcoin-0.1.3/src/ui.h --- bitcoin-0.1.0/src/ui.h 2009-01-07 01:00:00.000000000 +0100 +++ bitcoin-0.1.3/src/ui.h 2009-01-07 01:00:00.000000000 +0100 @@ -26,6 +26,7 @@ extern string FormatTxStatus(const CWalletTx& wtx); extern void CrossThreadCall(int nID, void* pdata); extern void MainFrameRepaint(); +extern void Shutdown(void* parg); diff -Naur bitcoin-0.1.0/src/util.cpp bitcoin-0.1.3/src/util.cpp --- bitcoin-0.1.0/src/util.cpp 2009-01-07 01:00:00.000000000 +0100 +++ bitcoin-0.1.3/src/util.cpp 2009-01-11 01:02:00.000000000 +0100 @@ -80,7 +80,13 @@ RAND_add(&hash, sizeof(hash), min(nSize/500.0, (double)sizeof(hash))); hash = 0; memset(pdata, 0, nSize); - printf("RandAddSeed() got %d bytes of performance data\n", nSize); + + time_t nTime; + time(&nTime); + struct tm* ptmTime = gmtime(&nTime); + char pszTime[200]; + strftime(pszTime, sizeof(pszTime), "%x %H:%M:%S", ptmTime); + printf("%s RandAddSeed() got %d bytes of performance data\n", pszTime, nSize); } } }