simplify AddAddress,
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Thu, 28 Jan 2010 00:31:00 +0000 (00:31 +0000)
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Thu, 28 Jan 2010 00:31:00 +0000 (00:31 +0000)
readcompactsize limit,
fixed a 64-bit compile error in serialize.h,
change status "# blocks" to "# confirmations" and widen the column.

db.cpp
irc.cpp
main.cpp
net.cpp
net.h
serialize.h
ui.cpp
uibase.h
uiproject.fbp
util.cpp
util.h

diff --git a/db.cpp b/db.cpp
index c33f71e..77f8e1e 100644 (file)
--- a/db.cpp
+++ b/db.cpp
@@ -134,8 +134,6 @@ void CDB::Close()
 \r
     CRITICAL_BLOCK(cs_db)\r
         --mapFileUseCount[strFile];\r
-\r
-    RandAddSeed();\r
 }\r
 \r
 void CloseDb(const string& strFile)\r
@@ -456,7 +454,7 @@ bool CAddrDB::LoadAddresses()
                     CAddress addr(psz, NODE_NETWORK);\r
                     addr.nTime = 0; // so it won't relay unless successfully connected\r
                     if (addr.IsValid())\r
-                        AddAddress(*this, addr);\r
+                        AddAddress(addr);\r
                 }\r
             }\r
             catch (...) { }\r
diff --git a/irc.cpp b/irc.cpp
index 8e85108..f38db6b 100644 (file)
--- a/irc.cpp
+++ b/irc.cpp
@@ -265,8 +265,7 @@ void ThreadIRCSeed(void* parg)
                 if (DecodeAddress(pszName, addr))\r
                 {\r
                     addr.nTime = GetAdjustedTime() - 51 * 60;\r
-                    CAddrDB addrdb;\r
-                    if (AddAddress(addrdb, addr))\r
+                    if (AddAddress(addr))\r
                         printf("IRC got new address\n");\r
                     nGotIRCAddresses++;\r
                 }\r
index 4cc91cb..416c616 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1734,6 +1734,11 @@ bool ProcessMessages(CNode* pfrom)
                 // Allow exceptions from underlength message on vRecv\r
                 printf("ProcessMessage(%s, %d bytes) : Exception '%s' caught, normally caused by a message being shorter than its stated length\n", strCommand.c_str(), nMessageSize, e.what());\r
             }\r
+            else if (strstr(e.what(), ": size too large"))\r
+            {\r
+                // Allow exceptions from overlong size\r
+                printf("ProcessMessage(%s, %d bytes) : Exception '%s' caught\n", strCommand.c_str(), nMessageSize, e.what());\r
+            }\r
             else\r
             {\r
                 PrintException(&e, "ProcessMessage()");\r
@@ -1840,7 +1845,6 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
             return error("message addr size() = %d", vAddr.size());\r
 \r
         // Store the new addresses\r
-        CAddrDB addrdb;\r
         foreach(CAddress& addr, vAddr)\r
         {\r
             if (fShutdown)\r
@@ -1848,7 +1852,7 @@ bool ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
             addr.nTime = GetAdjustedTime() - 2 * 60 * 60;\r
             if (pfrom->fGetAddr)\r
                 addr.nTime -= 5 * 24 * 60 * 60;\r
-            AddAddress(addrdb, addr, false);\r
+            AddAddress(addr, false);\r
             pfrom->AddAddressKnown(addr);\r
             if (!pfrom->fGetAddr && addr.IsRoutable())\r
             {\r
diff --git a/net.cpp b/net.cpp
index 168651c..38d05de 100644 (file)
--- a/net.cpp
+++ b/net.cpp
@@ -223,7 +223,7 @@ bool GetMyExternalIP(unsigned int& ipRet)
 \r
 \r
 \r
-bool AddAddress(CAddrDB& addrdb, CAddress addr, bool fCurrentlyOnline)\r
+bool AddAddress(CAddress addr, bool fCurrentlyOnline)\r
 {\r
     if (!addr.IsRoutable())\r
         return false;\r
@@ -239,7 +239,7 @@ bool AddAddress(CAddrDB& addrdb, CAddress addr, bool fCurrentlyOnline)
             // New address\r
             printf("AddAddress(%s)\n", addr.ToStringLog().c_str());\r
             mapAddresses.insert(make_pair(addr.GetKey(), addr));\r
-            addrdb.WriteAddress(addr);\r
+            CAddrDB().WriteAddress(addr);\r
             return true;\r
         }\r
         else\r
@@ -260,7 +260,7 @@ bool AddAddress(CAddrDB& addrdb, CAddress addr, bool fCurrentlyOnline)
                 fUpdated = true;\r
             }\r
             if (fUpdated)\r
-                addrdb.WriteAddress(addrFound);\r
+                CAddrDB().WriteAddress(addrFound);\r
         }\r
     }\r
     return false;\r
@@ -881,11 +881,11 @@ void ThreadOpenConnections2(void* parg)
         vnThreadsRunning[1]--;\r
         Sleep(500);\r
         const int nMaxConnections = 15;\r
-        while (vNodes.size() >= nMaxConnections || vNodes.size() >= mapAddresses.size())\r
+        while (vNodes.size() >= nMaxConnections)\r
         {\r
+            Sleep(2000);\r
             if (fShutdown)\r
                 return;\r
-            Sleep(2000);\r
         }\r
         vnThreadsRunning[1]++;\r
         if (fShutdown)\r
diff --git a/net.h b/net.h
index 90af3b4..ba4607a 100644 (file)
--- a/net.h
+++ b/net.h
@@ -23,7 +23,7 @@ enum
 \r
 bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet);\r
 bool GetMyExternalIP(unsigned int& ipRet);\r
-bool AddAddress(CAddrDB& addrdb, CAddress addr, bool fCurrentlyOnline=true);\r
+bool AddAddress(CAddress addr, bool fCurrentlyOnline=true);\r
 void AddressCurrentlyConnected(const CAddress& addr);\r
 CNode* FindNode(unsigned int ip);\r
 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0);\r
@@ -627,7 +627,7 @@ public:
         // We're using mapAskFor as a priority queue,\r
         // the key is the earliest time the request can be sent\r
         int64& nRequestTime = mapAlreadyAskedFor[inv];\r
-        printf("askfor %s  %"PRI64d"\n", inv.ToString().c_str(), nRequestTime);\r
+        printf("askfor %s   %"PRI64d"\n", inv.ToString().c_str(), nRequestTime);\r
 \r
         // Make sure not to reuse time indexes to keep things in the same order\r
         int64 nNow = (GetTime() - 1) * 1000000;\r
index ce4aff3..263a226 100644 (file)
@@ -20,7 +20,7 @@ class CDataStream;
 class CAutoFile;\r
 \r
 static const int VERSION = 200;\r
-static const char* pszSubVer = " rc2";\r
+static const char* pszSubVer = " test1";\r
 \r
 \r
 \r
@@ -194,28 +194,32 @@ uint64 ReadCompactSize(Stream& is)
 {\r
     unsigned char chSize;\r
     READDATA(is, chSize);\r
+    uint64 nSizeRet = 0;\r
     if (chSize < UCHAR_MAX-2)\r
     {\r
-        return chSize;\r
+        nSizeRet = chSize;\r
     }\r
     else if (chSize == UCHAR_MAX-2)\r
     {\r
         unsigned short nSize;\r
         READDATA(is, nSize);\r
-        return nSize;\r
+        nSizeRet = nSize;\r
     }\r
     else if (chSize == UCHAR_MAX-1)\r
     {\r
         unsigned int nSize;\r
         READDATA(is, nSize);\r
-        return nSize;\r
+        nSizeRet = nSize;\r
     }\r
     else\r
     {\r
         uint64 nSize;\r
         READDATA(is, nSize);\r
-        return nSize;\r
+        nSizeRet = nSize;\r
     }\r
+    if (nSizeRet > (uint64)INT_MAX)\r
+        throw std::ios_base::failure("ReadCompactSize() : size too large");\r
+    return nSizeRet;\r
 }\r
 \r
 \r
@@ -460,7 +464,7 @@ void Unserialize_impl(Stream& is, std::vector<T, A>& v, int nType, int nVersion,
     unsigned int i = 0;\r
     while (i < nSize)\r
     {\r
-        unsigned int blk = min(nSize - i, 1 + 4999999 / sizeof(T));\r
+        unsigned int blk = min(nSize - i, (unsigned int)(1 + 4999999 / sizeof(T)));\r
         v.resize(i + blk);\r
         is.read((char*)&v[i], blk * sizeof(T));\r
         i += blk;\r
diff --git a/ui.cpp b/ui.cpp
index 67895c1..994cc7e 100644 (file)
--- a/ui.cpp
+++ b/ui.cpp
@@ -349,7 +349,7 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
         nDateWidth += 12;\r
     m_listCtrl->InsertColumn(0, "",             wxLIST_FORMAT_LEFT,  dResize * 0);\r
     m_listCtrl->InsertColumn(1, "",             wxLIST_FORMAT_LEFT,  dResize * 0);\r
-    m_listCtrl->InsertColumn(2, "Status",       wxLIST_FORMAT_LEFT,  dResize * 90);\r
+    m_listCtrl->InsertColumn(2, "Status",       wxLIST_FORMAT_LEFT,  dResize * 110);\r
     m_listCtrl->InsertColumn(3, "Date",         wxLIST_FORMAT_LEFT,  dResize * nDateWidth);\r
     m_listCtrl->InsertColumn(4, "Description",  wxLIST_FORMAT_LEFT,  dResize * 409 - nDateWidth);\r
     m_listCtrl->InsertColumn(5, "Debit",        wxLIST_FORMAT_RIGHT, dResize * 79);\r
@@ -579,7 +579,7 @@ string FormatTxStatus(const CWalletTx& wtx)
         else if (nDepth < 6)\r
             return strprintf("%d/unconfirmed", nDepth);\r
         else\r
-            return strprintf("%d blocks", nDepth);\r
+            return strprintf("%d confirmations", nDepth);\r
     }\r
 }\r
 \r
@@ -3706,13 +3706,12 @@ bool CMyApp::OnInit2()
 \r
     if (mapArgs.count("-addnode"))\r
     {\r
-        CAddrDB addrdb;\r
         foreach(string strAddr, mapMultiArgs["-addnode"])\r
         {\r
             CAddress addr(strAddr, NODE_NETWORK);\r
             addr.nTime = 0; // so it won't relay unless successfully connected\r
             if (addr.IsValid())\r
-                AddAddress(addrdb, addr);\r
+                AddAddress(addr);\r
         }\r
     }\r
 \r
@@ -3934,3 +3933,13 @@ void SetStartOnSystemStartup(bool fAutoStart)
 bool GetStartOnSystemStartup() { return false; }\r
 void SetStartOnSystemStartup(bool fAutoStart) { }\r
 #endif\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
index e0c1521..7620a24 100644 (file)
--- a/uibase.h
+++ b/uibase.h
@@ -158,7 +158,7 @@ class CMainFrameBase : public wxFrame
                wxListCtrl* m_listCtrlOrdersSent;\r
                wxListCtrl* m_listCtrlProductsSent;\r
                wxListCtrl* m_listCtrlOrdersReceived;\r
-               CMainFrameBase( wxWindow* parent, wxWindowID id = wxID_MAINFRAME, const wxString& title = wxT("Bitcoin"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 705,484 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxTAB_TRAVERSAL );\r
+               CMainFrameBase( wxWindow* parent, wxWindowID id = wxID_MAINFRAME, const wxString& title = wxT("Bitcoin"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 725,484 ), long style = wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxTAB_TRAVERSAL );\r
                ~CMainFrameBase();\r
        \r
 };\r
index 58a99bd..34fde78 100644 (file)
@@ -32,7 +32,7 @@
             <property name="minimum_size"></property>\r
             <property name="name">CMainFrameBase</property>\r
             <property name="pos"></property>\r
-            <property name="size">705,484</property>\r
+            <property name="size">725,484</property>\r
             <property name="style">wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER</property>\r
             <property name="subclass"></property>\r
             <property name="title">Bitcoin</property>\r
             <event name="OnSetFocus"></event>\r
             <event name="OnSize"></event>\r
             <event name="OnUpdateUI"></event>\r
-            <object class="wxBoxSizer" expanded="1">\r
+            <object class="wxBoxSizer" expanded="0">\r
                 <property name="minimum_size"></property>\r
                 <property name="name">bSizer55</property>\r
                 <property name="orient">wxVERTICAL</property>\r
index f5f2797..4292246 100644 (file)
--- a/util.cpp
+++ b/util.cpp
@@ -8,8 +8,8 @@
 map<string, string> mapArgs;\r
 map<string, vector<string> > mapMultiArgs;\r
 bool fDebug = false;\r
-bool fPrintToDebugger = false;\r
 bool fPrintToConsole = false;\r
+bool fPrintToDebugger = false;\r
 char pszSetDataDir[MAX_PATH] = "";\r
 bool fShutdown = false;\r
 \r
@@ -75,6 +75,8 @@ void RandAddSeed()
 \r
 void RandAddSeedPerfmon()\r
 {\r
+    RandAddSeed();\r
+\r
     // This can take up to 2 seconds, so only do it every 10 minutes\r
     static int64 nLastPerfmon;\r
     if (GetTime() < nLastPerfmon + 10 * 60)\r
@@ -129,6 +131,79 @@ uint64 GetRand(uint64 nMax)
 \r
 \r
 \r
+inline int OutputDebugStringF(const char* pszFormat, ...)\r
+{\r
+    int ret = 0;\r
+    if (fPrintToConsole || wxTheApp == NULL)\r
+    {\r
+        // print to console\r
+        va_list arg_ptr;\r
+        va_start(arg_ptr, pszFormat);\r
+        ret = vprintf(pszFormat, arg_ptr);\r
+        va_end(arg_ptr);\r
+    }\r
+    else\r
+    {\r
+        // print to debug.log\r
+        char pszFile[MAX_PATH+100];\r
+        GetDataDir(pszFile);\r
+        strlcat(pszFile, "/debug.log", sizeof(pszFile));\r
+        FILE* fileout = fopen(pszFile, "a");\r
+        if (fileout)\r
+        {\r
+            //// Debug print useful for profiling\r
+            //fprintf(fileout, " %"PRI64d" ", wxGetLocalTimeMillis().GetValue());\r
+            va_list arg_ptr;\r
+            va_start(arg_ptr, pszFormat);\r
+            ret = vfprintf(fileout, pszFormat, arg_ptr);\r
+            va_end(arg_ptr);\r
+            fclose(fileout);\r
+        }\r
+    }\r
+\r
+#ifdef __WXMSW__\r
+    if (fPrintToDebugger)\r
+    {\r
+        // accumulate a line at a time\r
+        static CCriticalSection cs_OutputDebugStringF;\r
+        CRITICAL_BLOCK(cs_OutputDebugStringF)\r
+        {\r
+            static char pszBuffer[50000];\r
+            static char* pend;\r
+            if (pend == NULL)\r
+                pend = pszBuffer;\r
+            va_list arg_ptr;\r
+            va_start(arg_ptr, pszFormat);\r
+            int limit = END(pszBuffer) - pend - 2;\r
+            int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr);\r
+            va_end(arg_ptr);\r
+            if (ret < 0 || ret >= limit)\r
+            {\r
+                pend = END(pszBuffer) - 2;\r
+                *pend++ = '\n';\r
+            }\r
+            else\r
+                pend += ret;\r
+            *pend = '\0';\r
+            char* p1 = pszBuffer;\r
+            char* p2;\r
+            while (p2 = strchr(p1, '\n'))\r
+            {\r
+                p2++;\r
+                char c = *p2;\r
+                *p2 = '\0';\r
+                OutputDebugString(p1);\r
+                *p2 = c;\r
+                p1 = p2;\r
+            }\r
+            if (p1 != pszBuffer)\r
+                memmove(pszBuffer, p1, pend - p1 + 1);\r
+            pend -= (p1 - pszBuffer);\r
+        }\r
+    }\r
+#endif\r
+    return ret;\r
+}\r
 \r
 \r
 // Safer snprintf\r
diff --git a/util.h b/util.h
index b9c3658..d20648b 100644 (file)
--- a/util.h
+++ b/util.h
@@ -112,13 +112,14 @@ inline int myclosesocket(SOCKET& hSocket)
 extern map<string, string> mapArgs;\r
 extern map<string, vector<string> > mapMultiArgs;\r
 extern bool fDebug;\r
-extern bool fPrintToDebugger;\r
 extern bool fPrintToConsole;\r
+extern bool fPrintToDebugger;\r
 extern char pszSetDataDir[MAX_PATH];\r
 extern bool fShutdown;\r
 \r
 void RandAddSeed();\r
 void RandAddSeedPerfmon();\r
+int OutputDebugStringF(const char* pszFormat, ...);\r
 int my_snprintf(char* buffer, size_t limit, const char* format, ...);\r
 string strprintf(const char* format, ...);\r
 bool error(const char* format, ...);\r
@@ -219,92 +220,6 @@ public:
 \r
 \r
 \r
-inline int OutputDebugStringF(const char* pszFormat, ...)\r
-{\r
-    int ret = 0;\r
-#ifdef __WXDEBUG__\r
-    if (!fPrintToConsole)\r
-    {\r
-        // print to debug.log\r
-        char pszFile[MAX_PATH+100];\r
-        GetDataDir(pszFile);\r
-        strlcat(pszFile, "/debug.log", sizeof(pszFile));\r
-        FILE* fileout = fopen(pszFile, "a");\r
-        if (fileout)\r
-        {\r
-            //// Debug print useful for profiling\r
-            //fprintf(fileout, " %"PRI64d" ", wxGetLocalTimeMillis().GetValue());\r
-            va_list arg_ptr;\r
-            va_start(arg_ptr, pszFormat);\r
-            ret = vfprintf(fileout, pszFormat, arg_ptr);\r
-            va_end(arg_ptr);\r
-            fclose(fileout);\r
-        }\r
-    }\r
-\r
-#ifdef __WXMSW__\r
-    if (fPrintToDebugger)\r
-    {\r
-        // accumulate a line at a time\r
-        static CCriticalSection cs_OutputDebugStringF;\r
-        CRITICAL_BLOCK(cs_OutputDebugStringF)\r
-        {\r
-            static char pszBuffer[50000];\r
-            static char* pend;\r
-            if (pend == NULL)\r
-                pend = pszBuffer;\r
-            va_list arg_ptr;\r
-            va_start(arg_ptr, pszFormat);\r
-            int limit = END(pszBuffer) - pend - 2;\r
-            int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr);\r
-            va_end(arg_ptr);\r
-            if (ret < 0 || ret >= limit)\r
-            {\r
-                pend = END(pszBuffer) - 2;\r
-                *pend++ = '\n';\r
-            }\r
-            else\r
-                pend += ret;\r
-            *pend = '\0';\r
-            char* p1 = pszBuffer;\r
-            char* p2;\r
-            while (p2 = strchr(p1, '\n'))\r
-            {\r
-                p2++;\r
-                char c = *p2;\r
-                *p2 = '\0';\r
-                OutputDebugString(p1);\r
-                *p2 = c;\r
-                p1 = p2;\r
-            }\r
-            if (p1 != pszBuffer)\r
-                memmove(pszBuffer, p1, pend - p1 + 1);\r
-            pend -= (p1 - pszBuffer);\r
-        }\r
-    }\r
-#endif\r
-#endif\r
-\r
-    if (fPrintToConsole)\r
-    {\r
-        // print to console\r
-        va_list arg_ptr;\r
-        va_start(arg_ptr, pszFormat);\r
-        ret = vprintf(pszFormat, arg_ptr);\r
-        va_end(arg_ptr);\r
-    }\r
-    return ret;\r
-}\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
 inline string i64tostr(int64 n)\r
 {\r
     return strprintf("%"PRI64d, n);\r
@@ -415,11 +330,19 @@ inline string DateTimeStrFormat(const char* pszFormat, int64 nTime)
 \r
 \r
 \r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
 inline void heapchk()\r
 {\r
 #ifdef __WXMSW__\r
-    if (_heapchk() != _HEAPOK)\r
-        DebugBreak();\r
+    /// for debugging\r
+    //if (_heapchk() != _HEAPOK)\r
+    //    DebugBreak();\r
 #endif\r
 }\r
 \r