Merge pull request #211 from svost/bitcoin-netbase
authorCryptoManiac <CryptoManiac@users.noreply.github.com>
Sat, 18 Apr 2015 21:46:24 +0000 (14:46 -0700)
committerCryptoManiac <CryptoManiac@users.noreply.github.com>
Sat, 18 Apr 2015 21:46:24 +0000 (14:46 -0700)
Merged from bitcoin 0bd05b5

src/irc.cpp
src/main.cpp
src/makefile.linux-mingw
src/makefile.mingw
src/net.cpp
src/net.h
src/protocol.cpp
src/protocol.h
src/stun.cpp
src/util.cpp

index e5d9955..25033df 100644 (file)
@@ -192,6 +192,8 @@ void ThreadIRCSeed(void* parg)
     // Make this thread recognisable as the IRC seeding thread
     RenameThread("novacoin-ircseed");
 
+    printf("ThreadIRCSeed started\n");
+
     try
     {
         ThreadIRCSeed2(parg);
@@ -218,7 +220,8 @@ void ThreadIRCSeed2(void* parg)
     if (!GetBoolArg("-irc", true))
         return;
 
-    printf("ThreadIRCSeed started\n");
+    printf("ThreadIRCSeed trying to connect...\n");
+
     int nErrorWait = 10;
     int nRetryWait = 10;
     int nNameRetry = 0;
index 21eef1e..2f16f57 100644 (file)
@@ -2387,7 +2387,7 @@ bool CBlock::AcceptBlock()
     // Write block to history file
     if (!CheckDiskSpace(::GetSerializeSize(*this, SER_DISK, CLIENT_VERSION)))
         return error("AcceptBlock() : out of disk space");
-    unsigned int nFile = UINT_MAX;
+    unsigned int nFile = std::numeric_limits<unsigned int>::max();
     unsigned int nBlockPos = 0;
     if (!WriteToDisk(nFile, nBlockPos))
         return error("AcceptBlock() : WriteToDisk failed");
@@ -4103,3 +4103,25 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
     }
     return true;
 }
+
+
+class CMainCleanup
+{
+public:
+    CMainCleanup() {}
+    ~CMainCleanup() {
+        // block headers
+        std::map<uint256, CBlockIndex*>::iterator it1 = mapBlockIndex.begin();
+        for (; it1 != mapBlockIndex.end(); it1++)
+            delete (*it1).second;
+        mapBlockIndex.clear();
+
+        // orphan blocks
+        std::map<uint256, CBlock*>::iterator it2 = mapOrphanBlocks.begin();
+        for (; it2 != mapOrphanBlocks.end(); it2++)
+            delete (*it2).second;
+        mapOrphanBlocks.clear();
+
+        // orphan transactions
+    }
+} instance_of_cmaincleanup;
\ No newline at end of file
index e11c66d..594cc99 100644 (file)
@@ -127,16 +127,16 @@ ifeq (${USE_ASM}, 1)
 OBJS += scrypt-asm/obj/scrypt-arm.o scrypt-asm/obj/scrypt-x86.o scrypt-asm/obj/scrypt-x86_64.o scrypt-asm/obj/asm-wrapper.o
 
 scrypt-asm/obj/scrypt-x86.o: scrypt-asm/scrypt-x86.S
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 
 scrypt-asm/obj/scrypt-x86_64.o: scrypt-asm/scrypt-x86_64.S
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 
 scrypt-asm/obj/scrypt-arm.o: scrypt-asm/scrypt-arm.S
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 
 scrypt-asm/obj/asm-wrapper.o: scrypt-asm/asm-wrapper.cpp
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 else
 ifeq  (${USE_SSE2}, 1)
 # Intrinsic implementation
@@ -144,14 +144,14 @@ DEFS += -DUSE_SSE2
 OBJS += scrypt-intrin/obj/scrypt-sse2.o
 
 scrypt-intrin/obj/scrypt-sse2.o: scrypt-intrin/scrypt-sse2.cpp $(HEADERS)
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 else
 ifneq (${USE_ASM}, 1)
 # Generic implementation
 OBJS += obj/scrypt-generic.o
 
 obj/scrypt-generic.o: scrypt-generic.cpp
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 endif
 endif
 endif
index 71b7cdf..e6f1ff2 100644 (file)
@@ -116,16 +116,16 @@ ifdef USE_ASM
 OBJS += scrypt-asm/obj/scrypt-arm.o scrypt-asm/obj/scrypt-x86.o scrypt-asm/obj/scrypt-x86_64.o scrypt-asm/obj/asm-wrapper.o
 
 scrypt-asm/obj/scrypt-x86.o: scrypt-asm/scrypt-x86.S
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 
 scrypt-asm/obj/scrypt-x86_64.o: scrypt-asm/scrypt-x86_64.S
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 
 scrypt-asm/obj/scrypt-arm.o: scrypt-asm/scrypt-arm.S
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 
 scrypt-asm/obj/asm-wrapper.o: scrypt-asm/asm-wrapper.cpp
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 else
 ifdef USE_SSE2
 # Intrinsic implementation
@@ -133,13 +133,13 @@ DEFS += -DUSE_SSE2
 OBJS += scrypt-intrin/obj/scrypt-sse2.o
 
 scrypt-intrin/obj/scrypt-sse2.o: scrypt-intrin/scrypt-sse2.cpp
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 else
 # Generic implementation
 OBJS += obj/scrypt-generic.o
 
 obj/scrypt-generic.o: scrypt-generic.cpp
-       $(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
+       $(CXX) -c $(CFLAGS) -MMD -o $@ $<
 endif
 endif
 
index e1ac9a2..4eacd53 100644 (file)
@@ -307,7 +307,7 @@ extern int GetExternalIPbySTUN(uint64_t rnd, struct sockaddr_in *mapped, const c
 bool GetMyExternalIP(CNetAddr& ipRet)
 {
     struct sockaddr_in mapped;
-    uint64_t rnd = UINT64_MAX;
+    uint64_t rnd = std::numeric_limits<uint64_t>::max();
     const char *srv;
     int rc = GetExternalIPbySTUN(rnd, &mapped, &srv);
     if(rc >= 0) {
@@ -600,12 +600,12 @@ void ThreadSocketHandler(void* parg)
     printf("ThreadSocketHandler exited\n");
 }
 
+static list<CNode*> vNodesDisconnected;
+
 void ThreadSocketHandler2(void* parg)
 {
     printf("ThreadSocketHandler started\n");
-    list<CNode*> vNodesDisconnected;
     unsigned int nPrevNodeCount = 0;
-
     while (true)
     {
         //
@@ -1218,6 +1218,8 @@ void DumpAddresses()
 
 void ThreadDumpAddress2(void* parg)
 {
+    printf("ThreadDumpAddress started\n");
+
     vnThreadsRunning[THREAD_DUMPADDRESS]++;
     while (!fShutdown)
     {
@@ -1980,6 +1982,7 @@ bool StopNode()
         Sleep(20);
     Sleep(50);
     DumpAddresses();
+
     return true;
 }
 
@@ -2000,6 +2003,18 @@ public:
                 if (closesocket(hListenSocket) == SOCKET_ERROR)
                     printf("closesocket(hListenSocket) failed with error %d\n", WSAGetLastError());
 
+        // clean up some globals (to help leak detection)
+        BOOST_FOREACH(CNode *pnode, vNodes)
+            delete pnode;
+        BOOST_FOREACH(CNode *pnode, vNodesDisconnected)
+            delete pnode;
+        vNodes.clear();
+        vNodesDisconnected.clear();
+        delete semOutbound;
+        semOutbound = NULL;
+        delete pnodeLocalHost;
+        pnodeLocalHost = NULL;
+
 #ifdef WIN32
         // Shutdown Windows Sockets
         WSACleanup();
index 7306d13..d1696fc 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -5,6 +5,7 @@
 #ifndef BITCOIN_NET_H
 #define BITCOIN_NET_H
 
+#include <limits>
 #include <deque>
 #ifndef Q_MOC_RUN
 #include <boost/array.hpp>
@@ -233,7 +234,7 @@ public:
         nLastSendEmpty = GetTime();
         nTimeConnected = GetTime();
         nHeaderStart = -1;
-        nMessageStart = UINT_MAX;
+        nMessageStart = std::numeric_limits<uint32_t>::max();
         addr = addrIn;
         addrName = addrNameIn == "" ? addr.ToStringIPPort() : addrNameIn;
         nVersion = 0;
@@ -375,7 +376,7 @@ public:
             return;
         vSend.resize(nHeaderStart);
         nHeaderStart = -1;
-        nMessageStart = UINT_MAX;
+        nMessageStart = std::numeric_limits<uint32_t>::max();
         LEAVE_CRITICAL_SECTION(cs_vSend);
 
         if (fDebug)
@@ -410,7 +411,7 @@ public:
         }
 
         nHeaderStart = -1;
-        nMessageStart = UINT_MAX;
+        nMessageStart = std::numeric_limits<uint32_t>::max();
         LEAVE_CRITICAL_SECTION(cs_vSend);
     }
 
index fc112a5..5a7dd4a 100644 (file)
@@ -23,7 +23,7 @@ CMessageHeader::CMessageHeader()
     memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
     memset(pchCommand, 0, sizeof(pchCommand));
     pchCommand[1] = 1;
-    nMessageSize = UINT_MAX;
+    nMessageSize = std::numeric_limits<uint32_t>::max();
     nChecksum = 0;
 }
 
index ed8beab..75c24d8 100644 (file)
@@ -13,6 +13,7 @@
 #include "serialize.h"
 #include "netbase.h"
 #include <string>
+#include <limits>
 #include "uint256.h"
 
 extern bool fTestNet;
index c1c7d6e..1ab410e 100644 (file)
  * Of course all fields are in network format.
  */
 
-#define __STDC_LIMIT_MACROS
-
 #include <stdio.h>
-#include <stdint.h>
+#include <inttypes.h>
+#include <limits>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
@@ -339,14 +338,14 @@ static int stun_send(int s, struct sockaddr_in *dst, struct stun_header *resp)
 }
 
 /* helper function to generate a random request id */
-static uint64_t randfiller = GetRand(UINT64_MAX);
+static uint64_t randfiller = GetRand(std::numeric_limits<uint64_t>::max());
 static void stun_req_id(struct stun_header *req)
 {
     const uint64_t *S_block = (const uint64_t *)StunSrvList;
-    req->id.id[0] = GetRandInt(INT32_MAX);
-    req->id.id[1] = GetRandInt(INT32_MAX);
-    req->id.id[2] = GetRandInt(INT32_MAX);
-    req->id.id[3] = GetRandInt(INT32_MAX);
+    req->id.id[0] = GetRandInt(std::numeric_limits<int32_t>::max());
+    req->id.id[1] = GetRandInt(std::numeric_limits<int32_t>::max());
+    req->id.id[2] = GetRandInt(std::numeric_limits<int32_t>::max());
+    req->id.id[3] = GetRandInt(std::numeric_limits<int32_t>::max());
 
     req->id.id[0] |= 0x55555555;
     req->id.id[1] &= 0x55555555;
index 03f86e7..8cc62eb 100644 (file)
@@ -1271,7 +1271,7 @@ void ShrinkDebugFile()
     {
         // Restart the file with some of the end
         char pch[200000];
-        fseek(file, -sizeof(pch), SEEK_END);
+        fseek(file, (long long)-sizeof(pch), SEEK_END);
         int nBytes = fread(pch, 1, sizeof(pch), file);
         fclose(file);