Mercurial > hg > bitcoin
changeset 40:a9c603c15a88 draft
simplify AddAddress,
readcompactsize limit,
fixed a 64-bit compile error in serialize.h,
change status "# blocks" to "# confirmations" and widen the column.
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@53 1a98c847-1fd6-4fd8-948a-caf3550aa51b
author | s_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b> |
---|---|
date | Thu, 28 Jan 2010 00:31:00 +0000 |
parents | 047586b05aa4 |
children | a31678d75491 |
files | db.cpp irc.cpp main.cpp net.cpp net.h serialize.h ui.cpp uibase.h uiproject.fbp util.cpp util.h |
diffstat | 11 files changed, 129 insertions(+), 117 deletions(-) [+] |
line wrap: on
line diff
--- a/db.cpp +++ b/db.cpp @@ -134,8 +134,6 @@ CRITICAL_BLOCK(cs_db) --mapFileUseCount[strFile]; - - RandAddSeed(); } void CloseDb(const string& strFile) @@ -456,7 +454,7 @@ CAddress addr(psz, NODE_NETWORK); addr.nTime = 0; // so it won't relay unless successfully connected if (addr.IsValid()) - AddAddress(*this, addr); + AddAddress(addr); } } catch (...) { }
--- a/irc.cpp +++ b/irc.cpp @@ -265,8 +265,7 @@ if (DecodeAddress(pszName, addr)) { addr.nTime = GetAdjustedTime() - 51 * 60; - CAddrDB addrdb; - if (AddAddress(addrdb, addr)) + if (AddAddress(addr)) printf("IRC got new address\n"); nGotIRCAddresses++; }
--- a/main.cpp +++ b/main.cpp @@ -1734,6 +1734,11 @@ // Allow exceptions from underlength message on vRecv 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()); } + else if (strstr(e.what(), ": size too large")) + { + // Allow exceptions from overlong size + printf("ProcessMessage(%s, %d bytes) : Exception '%s' caught\n", strCommand.c_str(), nMessageSize, e.what()); + } else { PrintException(&e, "ProcessMessage()"); @@ -1840,7 +1845,6 @@ return error("message addr size() = %d", vAddr.size()); // Store the new addresses - CAddrDB addrdb; foreach(CAddress& addr, vAddr) { if (fShutdown) @@ -1848,7 +1852,7 @@ addr.nTime = GetAdjustedTime() - 2 * 60 * 60; if (pfrom->fGetAddr) addr.nTime -= 5 * 24 * 60 * 60; - AddAddress(addrdb, addr, false); + AddAddress(addr, false); pfrom->AddAddressKnown(addr); if (!pfrom->fGetAddr && addr.IsRoutable()) {
--- a/net.cpp +++ b/net.cpp @@ -223,7 +223,7 @@ -bool AddAddress(CAddrDB& addrdb, CAddress addr, bool fCurrentlyOnline) +bool AddAddress(CAddress addr, bool fCurrentlyOnline) { if (!addr.IsRoutable()) return false; @@ -239,7 +239,7 @@ // New address printf("AddAddress(%s)\n", addr.ToStringLog().c_str()); mapAddresses.insert(make_pair(addr.GetKey(), addr)); - addrdb.WriteAddress(addr); + CAddrDB().WriteAddress(addr); return true; } else @@ -260,7 +260,7 @@ fUpdated = true; } if (fUpdated) - addrdb.WriteAddress(addrFound); + CAddrDB().WriteAddress(addrFound); } } return false; @@ -881,11 +881,11 @@ vnThreadsRunning[1]--; Sleep(500); const int nMaxConnections = 15; - while (vNodes.size() >= nMaxConnections || vNodes.size() >= mapAddresses.size()) + while (vNodes.size() >= nMaxConnections) { + Sleep(2000); if (fShutdown) return; - Sleep(2000); } vnThreadsRunning[1]++; if (fShutdown)
--- a/net.h +++ b/net.h @@ -23,7 +23,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet); bool GetMyExternalIP(unsigned int& ipRet); -bool AddAddress(CAddrDB& addrdb, CAddress addr, bool fCurrentlyOnline=true); +bool AddAddress(CAddress addr, bool fCurrentlyOnline=true); void AddressCurrentlyConnected(const CAddress& addr); CNode* FindNode(unsigned int ip); CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0); @@ -627,7 +627,7 @@ // We're using mapAskFor as a priority queue, // the key is the earliest time the request can be sent int64& nRequestTime = mapAlreadyAskedFor[inv]; - printf("askfor %s %"PRI64d"\n", inv.ToString().c_str(), nRequestTime); + printf("askfor %s %"PRI64d"\n", inv.ToString().c_str(), nRequestTime); // Make sure not to reuse time indexes to keep things in the same order int64 nNow = (GetTime() - 1) * 1000000;
--- a/serialize.h +++ b/serialize.h @@ -20,7 +20,7 @@ class CAutoFile; static const int VERSION = 200; -static const char* pszSubVer = " rc2"; +static const char* pszSubVer = " test1"; @@ -194,28 +194,32 @@ { unsigned char chSize; READDATA(is, chSize); + uint64 nSizeRet = 0; if (chSize < UCHAR_MAX-2) { - return chSize; + nSizeRet = chSize; } else if (chSize == UCHAR_MAX-2) { unsigned short nSize; READDATA(is, nSize); - return nSize; + nSizeRet = nSize; } else if (chSize == UCHAR_MAX-1) { unsigned int nSize; READDATA(is, nSize); - return nSize; + nSizeRet = nSize; } else { uint64 nSize; READDATA(is, nSize); - return nSize; + nSizeRet = nSize; } + if (nSizeRet > (uint64)INT_MAX) + throw std::ios_base::failure("ReadCompactSize() : size too large"); + return nSizeRet; } @@ -460,7 +464,7 @@ unsigned int i = 0; while (i < nSize) { - unsigned int blk = min(nSize - i, 1 + 4999999 / sizeof(T)); + unsigned int blk = min(nSize - i, (unsigned int)(1 + 4999999 / sizeof(T))); v.resize(i + blk); is.read((char*)&v[i], blk * sizeof(T)); i += blk;
--- a/ui.cpp +++ b/ui.cpp @@ -349,7 +349,7 @@ nDateWidth += 12; m_listCtrl->InsertColumn(0, "", wxLIST_FORMAT_LEFT, dResize * 0); m_listCtrl->InsertColumn(1, "", wxLIST_FORMAT_LEFT, dResize * 0); - m_listCtrl->InsertColumn(2, "Status", wxLIST_FORMAT_LEFT, dResize * 90); + m_listCtrl->InsertColumn(2, "Status", wxLIST_FORMAT_LEFT, dResize * 110); m_listCtrl->InsertColumn(3, "Date", wxLIST_FORMAT_LEFT, dResize * nDateWidth); m_listCtrl->InsertColumn(4, "Description", wxLIST_FORMAT_LEFT, dResize * 409 - nDateWidth); m_listCtrl->InsertColumn(5, "Debit", wxLIST_FORMAT_RIGHT, dResize * 79); @@ -579,7 +579,7 @@ else if (nDepth < 6) return strprintf("%d/unconfirmed", nDepth); else - return strprintf("%d blocks", nDepth); + return strprintf("%d confirmations", nDepth); } } @@ -3706,13 +3706,12 @@ if (mapArgs.count("-addnode")) { - CAddrDB addrdb; foreach(string strAddr, mapMultiArgs["-addnode"]) { CAddress addr(strAddr, NODE_NETWORK); addr.nTime = 0; // so it won't relay unless successfully connected if (addr.IsValid()) - AddAddress(addrdb, addr); + AddAddress(addr); } } @@ -3934,3 +3933,13 @@ bool GetStartOnSystemStartup() { return false; } void SetStartOnSystemStartup(bool fAutoStart) { } #endif + + + + + + + + + +
--- a/uibase.h +++ b/uibase.h @@ -158,7 +158,7 @@ wxListCtrl* m_listCtrlOrdersSent; wxListCtrl* m_listCtrlProductsSent; wxListCtrl* m_listCtrlOrdersReceived; - 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 ); + 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 ); ~CMainFrameBase(); };
--- a/uiproject.fbp +++ b/uiproject.fbp @@ -32,7 +32,7 @@ <property name="minimum_size"></property> <property name="name">CMainFrameBase</property> <property name="pos"></property> - <property name="size">705,484</property> + <property name="size">725,484</property> <property name="style">wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER</property> <property name="subclass"></property> <property name="title">Bitcoin</property> @@ -1737,7 +1737,7 @@ <event name="OnSetFocus"></event> <event name="OnSize"></event> <event name="OnUpdateUI"></event> - <object class="wxBoxSizer" expanded="1"> + <object class="wxBoxSizer" expanded="0"> <property name="minimum_size"></property> <property name="name">bSizer55</property> <property name="orient">wxVERTICAL</property>
--- a/util.cpp +++ b/util.cpp @@ -8,8 +8,8 @@ map<string, string> mapArgs; map<string, vector<string> > mapMultiArgs; bool fDebug = false; +bool fPrintToConsole = false; bool fPrintToDebugger = false; -bool fPrintToConsole = false; char pszSetDataDir[MAX_PATH] = ""; bool fShutdown = false; @@ -75,6 +75,8 @@ void RandAddSeedPerfmon() { + RandAddSeed(); + // This can take up to 2 seconds, so only do it every 10 minutes static int64 nLastPerfmon; if (GetTime() < nLastPerfmon + 10 * 60) @@ -129,6 +131,79 @@ +inline int OutputDebugStringF(const char* pszFormat, ...) +{ + int ret = 0; + if (fPrintToConsole || wxTheApp == NULL) + { + // print to console + va_list arg_ptr; + va_start(arg_ptr, pszFormat); + ret = vprintf(pszFormat, arg_ptr); + va_end(arg_ptr); + } + else + { + // print to debug.log + char pszFile[MAX_PATH+100]; + GetDataDir(pszFile); + strlcat(pszFile, "/debug.log", sizeof(pszFile)); + FILE* fileout = fopen(pszFile, "a"); + if (fileout) + { + //// Debug print useful for profiling + //fprintf(fileout, " %"PRI64d" ", wxGetLocalTimeMillis().GetValue()); + va_list arg_ptr; + va_start(arg_ptr, pszFormat); + ret = vfprintf(fileout, pszFormat, arg_ptr); + va_end(arg_ptr); + fclose(fileout); + } + } + +#ifdef __WXMSW__ + if (fPrintToDebugger) + { + // accumulate a line at a time + static CCriticalSection cs_OutputDebugStringF; + CRITICAL_BLOCK(cs_OutputDebugStringF) + { + static char pszBuffer[50000]; + static char* pend; + if (pend == NULL) + pend = pszBuffer; + va_list arg_ptr; + va_start(arg_ptr, pszFormat); + int limit = END(pszBuffer) - pend - 2; + int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr); + va_end(arg_ptr); + if (ret < 0 || ret >= limit) + { + pend = END(pszBuffer) - 2; + *pend++ = '\n'; + } + else + pend += ret; + *pend = '\0'; + char* p1 = pszBuffer; + char* p2; + while (p2 = strchr(p1, '\n')) + { + p2++; + char c = *p2; + *p2 = '\0'; + OutputDebugString(p1); + *p2 = c; + p1 = p2; + } + if (p1 != pszBuffer) + memmove(pszBuffer, p1, pend - p1 + 1); + pend -= (p1 - pszBuffer); + } + } +#endif + return ret; +} // Safer snprintf
--- a/util.h +++ b/util.h @@ -112,13 +112,14 @@ extern map<string, string> mapArgs; extern map<string, vector<string> > mapMultiArgs; extern bool fDebug; +extern bool fPrintToConsole; extern bool fPrintToDebugger; -extern bool fPrintToConsole; extern char pszSetDataDir[MAX_PATH]; extern bool fShutdown; void RandAddSeed(); void RandAddSeedPerfmon(); +int OutputDebugStringF(const char* pszFormat, ...); int my_snprintf(char* buffer, size_t limit, const char* format, ...); string strprintf(const char* format, ...); bool error(const char* format, ...); @@ -219,92 +220,6 @@ -inline int OutputDebugStringF(const char* pszFormat, ...) -{ - int ret = 0; -#ifdef __WXDEBUG__ - if (!fPrintToConsole) - { - // print to debug.log - char pszFile[MAX_PATH+100]; - GetDataDir(pszFile); - strlcat(pszFile, "/debug.log", sizeof(pszFile)); - FILE* fileout = fopen(pszFile, "a"); - if (fileout) - { - //// Debug print useful for profiling - //fprintf(fileout, " %"PRI64d" ", wxGetLocalTimeMillis().GetValue()); - va_list arg_ptr; - va_start(arg_ptr, pszFormat); - ret = vfprintf(fileout, pszFormat, arg_ptr); - va_end(arg_ptr); - fclose(fileout); - } - } - -#ifdef __WXMSW__ - if (fPrintToDebugger) - { - // accumulate a line at a time - static CCriticalSection cs_OutputDebugStringF; - CRITICAL_BLOCK(cs_OutputDebugStringF) - { - static char pszBuffer[50000]; - static char* pend; - if (pend == NULL) - pend = pszBuffer; - va_list arg_ptr; - va_start(arg_ptr, pszFormat); - int limit = END(pszBuffer) - pend - 2; - int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr); - va_end(arg_ptr); - if (ret < 0 || ret >= limit) - { - pend = END(pszBuffer) - 2; - *pend++ = '\n'; - } - else - pend += ret; - *pend = '\0'; - char* p1 = pszBuffer; - char* p2; - while (p2 = strchr(p1, '\n')) - { - p2++; - char c = *p2; - *p2 = '\0'; - OutputDebugString(p1); - *p2 = c; - p1 = p2; - } - if (p1 != pszBuffer) - memmove(pszBuffer, p1, pend - p1 + 1); - pend -= (p1 - pszBuffer); - } - } -#endif -#endif - - if (fPrintToConsole) - { - // print to console - va_list arg_ptr; - va_start(arg_ptr, pszFormat); - ret = vprintf(pszFormat, arg_ptr); - va_end(arg_ptr); - } - return ret; -} - - - - - - - - - - inline string i64tostr(int64 n) { return strprintf("%"PRI64d, n); @@ -415,11 +330,19 @@ + + + + + + + inline void heapchk() { #ifdef __WXMSW__ - if (_heapchk() != _HEAPOK) - DebugBreak(); + /// for debugging + //if (_heapchk() != _HEAPOK) + // DebugBreak(); #endif }