From 22f9b069035c9ba0416a62714db167eea5ba762f Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Mon, 24 Sep 2012 13:53:44 -0400 Subject: [PATCH] Send 'mempool' P2P command at the start of each P2P session to query remote node mempool contents. --- src/init.cpp | 5 ++++- src/main.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index dc425da644..df3a0f1fd5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -25,6 +25,7 @@ using namespace boost; CWallet* pwalletMain; CClientUIInterface uiInterface; +int64 nTimeNodeStart; ////////////////////////////////////////////////////////////////////////////// // @@ -469,8 +470,10 @@ bool AppInit2() printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("Bitcoin version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str()); printf("Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION)); + + nTimeNodeStart = GetTime(); if (!fLogTimestamps) - printf("Startup time: %s\n", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str()); + printf("Startup time: %s\n", DateTimeStrFormat("%x %H:%M:%S", nTimeNodeStart).c_str()); printf("Default data directory %s\n", GetDefaultDataDir().string().c_str()); printf("Used data directory %s\n", GetDataDir().string().c_str()); std::ostringstream strErrors; diff --git a/src/main.cpp b/src/main.cpp index fbaf05dfc7..d1f84a12e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2404,6 +2404,14 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv) +static bool NodeRecentlyStarted() +{ + extern int64 nTimeNodeStart; + int64 timediff = GetTime() - nTimeNodeStart; + + return (timediff < (2 * 60 * 60)); +} + // The message start string is designed to be unlikely to occur in normal data. // The characters are rarely used upper ASCII, not valid as UTF-8, and produce @@ -2510,6 +2518,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv) } } + // Trigger download of remote node's memory pool + if (!IsInitialBlockDownload() && !pfrom->fInbound && + !pfrom->fClient && NodeRecentlyStarted() && + pfrom->nVersion >= MEMPOOL_GD_VERSION) + pfrom->PushMessage("mempool"); + // Ask the first connected node for block updates static int nAskedForBlocks = 0; if (!pfrom->fClient && !pfrom->fOneShot &&