What changed
Bitcoin v0.1.0 → v0.1.3
Full source: v0.1.0. v0.1.3. Next: v0.1.3 → v0.1.5.
- db.cpp modified · +4 −0
- irc.cpp modified · +44 −21
- main.cpp modified · +1 −1
- net.cpp modified · +96 −49
- net.h modified · +2 −2
- readme.txt modified · +1 −1
- release/readme.txt modified · +1 −1
- serialize.h modified · +1 −1
- ui.h modified · +1 −0
- util.cpp modified · +7 −1
db.cpp (modified)
1--- v0.1.0/db.cpp2+++ v0.1.3/db.cpp3@@ -454,6 +454,10 @@4 foreach(const PAIRTYPE(vector<unsigned char>, CAddress)& item, mapAddresses)5 item.second.print();6 printf("-----\n");7+8+ // Fix for possible GCC bug that manifests in mapAddresses.count in irc.cpp,9+ // just need to call count here and it doesn't happen there, do not delete this!10+ mapAddresses.count(vector<unsigned char>(18));11 }12 13 return true;
irc.cpp (modified)
1--- v0.1.0/irc.cpp2+++ v0.1.3/irc.cpp3@@ -136,14 +136,30 @@4 }5 }6 7-8-9-10-bool fRestartIRCSeed = false;11+bool Wait(int nSeconds)12+{13+ if (fShutdown)14+ return false;15+ printf("Waiting %d seconds to reconnect to IRC\n", nSeconds);16+ for (int i = 0; i < nSeconds; i++)17+ {18+ if (fShutdown)19+ return false;20+ Sleep(1000);21+ }22+ return true;23+}24+25+26 27 void ThreadIRCSeed(void* parg)28 {29- loop30+ SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);31+ int nErrorWait = 30;32+ int nRetryWait = 10;33+34+35+ while (!fShutdown)36 {37 struct hostent* phostent = gethostbyname("chat.freenode.net");38 CAddress addrConnect(*(u_long*)phostent->h_addr_list[0], htons(6667));39@@ -152,13 +168,19 @@40 if (!ConnectSocket(addrConnect, hSocket))41 {42 printf("IRC connect failed\n");43- return;44+ if (Wait(nErrorWait += 60))45+ continue;46+ else47+ return;48 }49 50 if (!RecvUntil(hSocket, "Found your hostname", "using your IP address instead", "Couldn't look up your hostname"))51 {52 closesocket(hSocket);53- return;54+ if (Wait(nErrorWait += 60))55+ continue;56+ else57+ return;58 }59 60 string strMyName = EncodeAddress(addrLocalHost);61@@ -166,28 +188,27 @@62 if (!addrLocalHost.IsRoutable())63 strMyName = strprintf("x%u", GetRand(1000000000));64 65+66 Send(hSocket, strprintf("NICK %s\r", strMyName.c_str()).c_str());67 Send(hSocket, strprintf("USER %s 8 * : %s\r", strMyName.c_str(), strMyName.c_str()).c_str());68 69 if (!RecvUntil(hSocket, " 004 "))70 {71 closesocket(hSocket);72- return;73+ if (Wait(nErrorWait += 60))74+ continue;75+ else76+ return;77 }78 Sleep(500);79 80 Send(hSocket, "JOIN #bitcoin\r");81 Send(hSocket, "WHO #bitcoin\r");82 83- while (!fRestartIRCSeed)84- {85- string strLine;86- if (fShutdown || !RecvLineIRC(hSocket, strLine))87- {88- closesocket(hSocket);89- return;90- }91- if (strLine.empty() || strLine[0] != ':')92+ string strLine;93+ while (!fShutdown && RecvLineIRC(hSocket, strLine))94+ {95+ if (strLine.empty() || strLine.size() > 900 || strLine[0] != ':')96 continue;97 printf("IRC %s\n", strLine.c_str());98 99@@ -207,7 +228,7 @@100 printf("GOT WHO: [%s] ", pszName);101 }102 103- if (vWords[1] == "JOIN")104+ if (vWords[1] == "JOIN" && vWords[0].size() > 1)105 {106 // :username!username@50000007.F000000B.90000002.IP JOIN :#channelname107 strcpy(pszName, vWords[0].c_str() + 1);108@@ -231,10 +252,12 @@109 printf("decode failed\n");110 }111 }112- }113-114- fRestartIRCSeed = false;115+116+ }117 closesocket(hSocket);118+119+ if (!Wait(nRetryWait += 10))120+ return;121 }122 }123
main.cpp (modified)
1--- v0.1.0/main.cpp2+++ v0.1.3/main.cpp3@@ -1734,7 +1734,7 @@4 pfrom->PushMessage("getblocks", CBlockLocator(pindexBest), uint256(0));5 }6 7- printf("version addrMe = %s\n", addrMe.ToString().c_str());8+ printf("version message: %s has version %d, addrMe=%s\n", pfrom->addr.ToString().c_str(), pfrom->nVersion, addrMe.ToString().c_str());9 }10 11
net.cpp (modified)
1--- v0.1.0/net.cpp2+++ v0.1.3/net.cpp3@@ -41,7 +41,7 @@4 {5 hSocketRet = INVALID_SOCKET;6 7- SOCKET hSocket = socket(AF_INET, SOCK_STREAM, 0);8+ SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);9 if (hSocket == INVALID_SOCKET)10 return false;11 12@@ -89,20 +89,13 @@13 }14 15 16-bool GetMyExternalIP(unsigned int& ipRet)17-{18- CAddress addrConnect("72.233.89.199:80"); // whatismyip.com 198-20019-20+21+bool GetMyExternalIP2(const CAddress& addrConnect, const char* pszGet, const char* pszKeyword, unsigned int& ipRet)22+{23 SOCKET hSocket;24 if (!ConnectSocket(addrConnect, hSocket))25 return error("GetMyExternalIP() : connection to %s failed\n", addrConnect.ToString().c_str());26 27- char* pszGet =28- "GET /automation/n09230945.asp HTTP/1.1\r\n"29- "Host: www.whatismyip.com\r\n"30- "User-Agent: Bitcoin/0.1\r\n"31- "Connection: close\r\n"32- "\r\n";33 send(hSocket, pszGet, strlen(pszGet), 0);34 35 string strLine;36@@ -110,15 +103,27 @@37 {38 if (strLine.empty())39 {40- if (!RecvLine(hSocket, strLine))41- {42- closesocket(hSocket);43- return false;44+ loop45+ {46+ if (!RecvLine(hSocket, strLine))47+ {48+ closesocket(hSocket);49+ return false;50+ }51+ if (strLine.find(pszKeyword) != -1)52+ {53+ strLine = strLine.substr(strLine.find(pszKeyword) + strlen(pszKeyword));54+ break;55+ }56 }57 closesocket(hSocket);58+ if (strLine.find("<"))59+ strLine = strLine.substr(0, strLine.find("<"));60+ strLine = strLine.substr(strspn(strLine.c_str(), " \t\n\r"));61+ strLine = wxString(strLine).Trim();62 CAddress addr(strLine.c_str());63 printf("GetMyExternalIP() received [%s] %s\n", strLine.c_str(), addr.ToString().c_str());64- if (addr.ip == 0)65+ if (addr.ip == 0 || !addr.IsRoutable())66 return false;67 ipRet = addr.ip;68 return true;69@@ -128,6 +133,59 @@70 return error("GetMyExternalIP() : connection closed\n");71 }72 73+74+bool GetMyExternalIP(unsigned int& ipRet)75+{76+ CAddress addrConnect;77+ char* pszGet;78+ char* pszKeyword;79+80+ for (int nLookup = 0; nLookup <= 1; nLookup++)81+ for (int nHost = 1; nHost <= 2; nHost++)82+ {83+ if (nHost == 1)84+ {85+ addrConnect = CAddress("70.86.96.218:80"); // www.ipaddressworld.com86+87+ if (nLookup == 1)88+ {89+ struct hostent* phostent = gethostbyname("www.ipaddressworld.com");90+ addrConnect = CAddress(*(u_long*)phostent->h_addr_list[0], htons(80));91+ }92+93+ pszGet = "GET /ip.php HTTP/1.1\r\n"94+ "Host: www.ipaddressworld.com\r\n"95+ "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n"96+ "Connection: close\r\n"97+ "\r\n";98+99+ pszKeyword = "IP:";100+ }101+ else if (nHost == 2)102+ {103+ addrConnect = CAddress("208.78.68.70:80"); // checkip.dyndns.org104+105+ if (nLookup == 1)106+ {107+ struct hostent* phostent = gethostbyname("checkip.dyndns.org");108+ addrConnect = CAddress(*(u_long*)phostent->h_addr_list[0], htons(80));109+ }110+111+ pszGet = "GET / HTTP/1.1\r\n"112+ "Host: checkip.dyndns.org\r\n"113+ "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)\r\n"114+ "Connection: close\r\n"115+ "\r\n";116+117+ pszKeyword = "Address:";118+ }119+120+ if (GetMyExternalIP2(addrConnect, pszGet, pszKeyword, ipRet))121+ return true;122+ }123+124+ return false;125+}126 127 128 129@@ -322,6 +380,11 @@130 /// debug print131 printf("connected %s\n", addrConnect.ToString().c_str());132 133+ // Set to nonblocking134+ u_long nOne = 1;135+ if (ioctlsocket(hSocket, FIONBIO, &nOne) == SOCKET_ERROR)136+ printf("ConnectSocket() : ioctlsocket nonblocking setting failed, error %d\n", WSAGetLastError());137+138 // Add node139 CNode* pnode = new CNode(hSocket, addrConnect, false);140 if (nTimeout != 0)141@@ -406,37 +469,6 @@142 //143 CRITICAL_BLOCK(cs_vNodes)144 {145- // Disconnect duplicate connections146- map<unsigned int, CNode*> mapFirst;147- foreach(CNode* pnode, vNodes)148- {149- if (pnode->fDisconnect)150- continue;151- unsigned int ip = pnode->addr.ip;152- if (mapFirst.count(ip) && addrLocalHost.ip < ip)153- {154- // In case two nodes connect to each other at once,155- // the lower ip disconnects its outbound connection156- CNode* pnodeExtra = mapFirst[ip];157-158- if (pnodeExtra->GetRefCount() > (pnodeExtra->fNetworkNode ? 1 : 0))159- swap(pnodeExtra, pnode);160-161- if (pnodeExtra->GetRefCount() <= (pnodeExtra->fNetworkNode ? 1 : 0))162- {163- printf("(%d nodes) disconnecting duplicate: %s\n", vNodes.size(), pnodeExtra->addr.ToString().c_str());164- if (pnodeExtra->fNetworkNode && !pnode->fNetworkNode)165- {166- pnode->AddRef();167- swap(pnodeExtra->fNetworkNode, pnode->fNetworkNode);168- pnodeExtra->Release();169- }170- pnodeExtra->fDisconnect = true;171- }172- }173- mapFirst[ip] = pnode;174- }175-176 // Disconnect unused nodes177 vector<CNode*> vNodesCopy = vNodes;178 foreach(CNode* pnode, vNodesCopy)179@@ -755,10 +787,14 @@180 // Once we've chosen an IP, we'll try every given port before moving on181 foreach(const CAddress& addrConnect, (*mi).second)182 {183+ CheckForShutdown(1);184 if (addrConnect.ip == addrLocalHost.ip || !addrConnect.IsIPv4() || FindNode(addrConnect.ip))185 continue;186 187+ vfThreadRunning[1] = false;188 CNode* pnode = ConnectNode(addrConnect);189+ vfThreadRunning[1] = true;190+ CheckForShutdown(1);191 if (!pnode)192 continue;193 pnode->fNetworkNode = true;194@@ -1000,8 +1036,19 @@195 printf("StopNode()\n");196 fShutdown = true;197 nTransactionsUpdated++;198- while (count(vfThreadRunning.begin(), vfThreadRunning.end(), true))199- Sleep(10);200+ int64 nStart = GetTime();201+ while (vfThreadRunning[0] || vfThreadRunning[2] || vfThreadRunning[3])202+ {203+ if (GetTime() - nStart > 15)204+ break;205+ Sleep(20);206+ }207+ if (vfThreadRunning[0]) printf("ThreadSocketHandler still running\n");208+ if (vfThreadRunning[1]) printf("ThreadOpenConnections still running\n");209+ if (vfThreadRunning[2]) printf("ThreadMessageHandler still running\n");210+ if (vfThreadRunning[3]) printf("ThreadBitcoinMiner still running\n");211+ while (vfThreadRunning[2])212+ Sleep(20);213 Sleep(50);214 215 // Sockets shutdown
net.h (modified)
1--- v0.1.0/net.h2+++ v0.1.3/net.h3@@ -153,7 +153,7 @@4 nLastFailed = 0;5 }6 7- CAddress(unsigned int ipIn, unsigned short portIn, uint64 nServicesIn=0)8+ CAddress(unsigned int ipIn, unsigned short portIn=DEFAULT_PORT, uint64 nServicesIn=0)9 {10 nServices = nServicesIn;11 memcpy(pchReserved, pchIPv4, sizeof(pchReserved));12@@ -262,7 +262,7 @@13 14 bool IsRoutable() const15 {16- return !(GetByte(3) == 10 || (GetByte(3) == 192 && GetByte(2) == 168));17+ return !(GetByte(3) == 10 || (GetByte(3) == 192 && GetByte(2) == 168) || GetByte(3) == 127 || GetByte(3) == 0);18 }19 20 unsigned char GetByte(int n) const
readme.txt (modified)
1--- v0.1.0/readme.txt2+++ v0.1.3/readme.txt3@@ -1,4 +1,4 @@4-BitCoin v0.01 ALPHA5+BitCoin v0.1.3 ALPHA6 7 Copyright (c) 2009 Satoshi Nakamoto8 Distributed under the MIT/X11 software license, see the accompanying
release/readme.txt (modified)
1--- v0.1.0/release/readme.txt2+++ v0.1.3/release/readme.txt3@@ -1,4 +1,4 @@4-BitCoin v0.01 ALPHA5+BitCoin v0.1.3 ALPHA6 7 Copyright (c) 2009 Satoshi Nakamoto8 Distributed under the MIT/X11 software license, see the accompanying
serialize.h (modified)
1--- v0.1.0/serialize.h2+++ v0.1.3/serialize.h3@@ -19,7 +19,7 @@4 class CDataStream;5 class CAutoFile;6 7-static const int VERSION = 101;8+static const int VERSION = 103;9 10 11
ui.h (modified)
1--- v0.1.0/ui.h2+++ v0.1.3/ui.h3@@ -26,6 +26,7 @@4 extern string FormatTxStatus(const CWalletTx& wtx);5 extern void CrossThreadCall(int nID, void* pdata);6 extern void MainFrameRepaint();7+extern void Shutdown(void* parg);8 9 10
util.cpp (modified)
1--- v0.1.0/util.cpp2+++ v0.1.3/util.cpp3@@ -80,7 +80,13 @@4 RAND_add(&hash, sizeof(hash), min(nSize/500.0, (double)sizeof(hash)));5 hash = 0;6 memset(pdata, 0, nSize);7- printf("RandAddSeed() got %d bytes of performance data\n", nSize);8+9+ time_t nTime;10+ time(&nTime);11+ struct tm* ptmTime = gmtime(&nTime);12+ char pszTime[200];13+ strftime(pszTime, sizeof(pszTime), "%x %H:%M:%S", ptmTime);14+ printf("%s RandAddSeed() got %d bytes of performance data\n", pszTime, nSize);15 }16 }17 }
