Merge pull request #212 from svost/bitcoin-net
authorCryptoManiac <CryptoManiac@users.noreply.github.com>
Sat, 18 Apr 2015 21:46:00 +0000 (14:46 -0700)
committerCryptoManiac <CryptoManiac@users.noreply.github.com>
Sat, 18 Apr 2015 21:46:00 +0000 (14:46 -0700)
Bitcoin net

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 83afc78..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");
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 0c166eb..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) {
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);