Remove zeromq support
This commit is contained in:
@@ -55,9 +55,6 @@ LIBZCASH=libzcash.a
|
||||
LIBHUSH=libhush.a
|
||||
LIBRANDOMX=RandomX/build/librandomx.a
|
||||
|
||||
if ENABLE_ZMQ
|
||||
LIBBITCOIN_ZMQ=libbitcoin_zmq.a
|
||||
endif
|
||||
if BUILD_BITCOIN_LIBS
|
||||
LIBZCASH_CONSENSUS=libzcashconsensus.la
|
||||
endif
|
||||
@@ -88,9 +85,6 @@ if ENABLE_WALLET
|
||||
BITCOIN_INCLUDES += $(BDB_CPPFLAGS)
|
||||
EXTRA_LIBRARIES += $(LIBBITCOIN_WALLET)
|
||||
endif
|
||||
if ENABLE_ZMQ
|
||||
EXTRA_LIBRARIES += $(LIBBITCOIN_ZMQ)
|
||||
endif
|
||||
|
||||
lib_LTLIBRARIES = $(LIBZCASH_CONSENSUS)
|
||||
|
||||
@@ -239,11 +233,7 @@ BITCOIN_CORE_H = \
|
||||
wallet/rpchushwallet.h \
|
||||
wallet/wallet.h \
|
||||
wallet/wallet_ismine.h \
|
||||
wallet/walletdb.h \
|
||||
zmq/zmqabstractnotifier.h \
|
||||
zmq/zmqconfig.h\
|
||||
zmq/zmqnotificationinterface.h \
|
||||
zmq/zmqpublishnotifier.h
|
||||
wallet/walletdb.h
|
||||
|
||||
LIBHUSH_H = \
|
||||
hush/utiltls.h
|
||||
@@ -327,15 +317,6 @@ libbitcoin_server_a_SOURCES = \
|
||||
$(LIBZCASH_H) \
|
||||
$(LIBHUSH_H)
|
||||
|
||||
if ENABLE_ZMQ
|
||||
libbitcoin_zmq_a_CPPFLAGS = $(BITCOIN_INCLUDES) $(ZMQ_CFLAGS)
|
||||
libbitcoin_zmq_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
libbitcoin_zmq_a_SOURCES = \
|
||||
zmq/zmqabstractnotifier.cpp \
|
||||
zmq/zmqnotificationinterface.cpp \
|
||||
zmq/zmqpublishnotifier.cpp
|
||||
endif
|
||||
|
||||
# wallet: hushd, but only linked when wallet enabled
|
||||
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
@@ -497,7 +478,6 @@ hushd_LDADD = \
|
||||
$(LIBBITCOIN_COMMON) \
|
||||
$(LIBUNIVALUE) \
|
||||
$(LIBBITCOIN_UTIL) \
|
||||
$(LIBBITCOIN_ZMQ) \
|
||||
$(LIBBITCOIN_CRYPTO) \
|
||||
$(LIBZCASH) \
|
||||
$(LIBHUSH) \
|
||||
@@ -518,7 +498,6 @@ hushd_LDADD += \
|
||||
$(CRYPTO_LIBS) \
|
||||
$(EVENT_PTHREADS_LIBS) \
|
||||
$(EVENT_LIBS) \
|
||||
$(ZMQ_LIBS) \
|
||||
$(LIBBITCOIN_CRYPTO) \
|
||||
$(LIBZCASH_LIBS)
|
||||
|
||||
|
||||
@@ -54,9 +54,6 @@ hush_gtest_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
|
||||
hush_gtest_LDADD = -lgtest -lgmock $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \
|
||||
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1)
|
||||
if ENABLE_ZMQ
|
||||
zcash_gtest_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
|
||||
endif
|
||||
if ENABLE_WALLET
|
||||
hush_gtest_LDADD += $(LIBBITCOIN_WALLET)
|
||||
endif
|
||||
|
||||
@@ -125,10 +125,6 @@ test_test_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_test_bitcoin_LDADD += $(LIBZCASH_CONSENSUS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(LIBZCASH) $(LIBZCASH_LIBS)
|
||||
test_test_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
|
||||
|
||||
if ENABLE_ZMQ
|
||||
test_test_bitcoin_LDADD += $(ZMQ_LIBS)
|
||||
endif
|
||||
|
||||
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)
|
||||
|
||||
$(BITCOIN_TESTS): $(GENERATED_TEST_FILES)
|
||||
|
||||
35
src/init.cpp
35
src/init.cpp
@@ -80,11 +80,6 @@
|
||||
#include <wolfssl/options.h>
|
||||
#include <wolfssl/ssl.h>
|
||||
#include <thread>
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
#include "zmq/zmqnotificationinterface.h"
|
||||
#endif
|
||||
|
||||
#include "librustzcash.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -103,10 +98,6 @@ CWallet* pwalletMain = NULL;
|
||||
#endif
|
||||
bool fFeeEstimatesInitialized = false;
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
static CZMQNotificationInterface* pzmqNotificationInterface = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
// Win32 LevelDB doesn't use file descriptors, and the ones used for
|
||||
// accessing block files don't count towards the fd_set size limit
|
||||
@@ -269,14 +260,6 @@ void Shutdown()
|
||||
pwalletMain->Flush(true);
|
||||
#endif
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
if (pzmqNotificationInterface) {
|
||||
UnregisterValidationInterface(pzmqNotificationInterface);
|
||||
delete pzmqNotificationInterface;
|
||||
pzmqNotificationInterface = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
try {
|
||||
boost::filesystem::remove(GetPidFile());
|
||||
@@ -491,14 +474,6 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
" " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)"));
|
||||
#endif
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
strUsage += HelpMessageGroup(_("ZeroMQ notification options:"));
|
||||
strUsage += HelpMessageOpt("-zmqpubhashblock=<address>", _("Enable publish hash block in <address>"));
|
||||
strUsage += HelpMessageOpt("-zmqpubhashtx=<address>", _("Enable publish hash transaction in <address>"));
|
||||
strUsage += HelpMessageOpt("-zmqpubrawblock=<address>", _("Enable publish raw block in <address>"));
|
||||
strUsage += HelpMessageOpt("-zmqpubrawtx=<address>", _("Enable publish raw transaction in <address>"));
|
||||
#endif
|
||||
|
||||
strUsage += HelpMessageGroup(_("Debugging/Testing options:"));
|
||||
if (showDebug)
|
||||
{
|
||||
@@ -512,7 +487,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||
strUsage += HelpMessageOpt("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", 0));
|
||||
strUsage += HelpMessageOpt("-nuparams=hexBranchId:activationHeight", "Use given activation height for specified network upgrade (regtest-only)");
|
||||
}
|
||||
string debugCategories = "addrman, alert, bench, coindb, db, deletetx, estimatefee, http, libevent, lock, mempool, net, tls, partitioncheck, pow, proxy, prune, rand, randomx, reindex, rpc, selectcoins, stratum, tor, zmq, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these
|
||||
string debugCategories = "addrman, alert, bench, coindb, db, deletetx, estimatefee, http, libevent, lock, mempool, net, tls, partitioncheck, pow, proxy, prune, rand, randomx, reindex, rpc, selectcoins, stratum, tor, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these
|
||||
strUsage += HelpMessageOpt("-debug=<category>", strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + ". " +
|
||||
_("If <category> is not supplied or if <category> = 1, output all debugging information.") + " " + _("<category> can be:") + " " + debugCategories + ".");
|
||||
strUsage += HelpMessageOpt("-experimentalfeatures", _("Enable use of experimental features"));
|
||||
@@ -1728,14 +1703,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
return InitError(strprintf(_("Cannot find trusted certificates directory: '%s'"), pathTLSTrustredDir.string()));
|
||||
}
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
pzmqNotificationInterface = CZMQNotificationInterface::CreateWithArguments(mapArgs);
|
||||
|
||||
if (pzmqNotificationInterface) {
|
||||
RegisterValidationInterface(pzmqNotificationInterface);
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( HUSH_NSPV_SUPERLITE )
|
||||
{
|
||||
std::vector<boost::filesystem::path> vImportFiles;
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright (c) 2015 The Bitcoin Core developers
|
||||
// Distributed under the GPLv3 software license, see the accompanying
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
|
||||
#include "zmqabstractnotifier.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
CZMQAbstractNotifier::~CZMQAbstractNotifier()
|
||||
{
|
||||
assert(!psocket);
|
||||
}
|
||||
|
||||
bool CZMQAbstractNotifier::NotifyBlock(const CBlockIndex * /*CBlockIndex*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CZMQAbstractNotifier::NotifyBlock(const CBlock &)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CZMQAbstractNotifier::NotifyTransaction(const CTransaction &/*transaction*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
// Copyright (c) 2015 The Bitcoin Core developers
|
||||
// Distributed under the GPLv3 software license, see the accompanying
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
|
||||
#ifndef HUSH_ZMQ_ZMQABSTRACTNOTIFIER_H
|
||||
#define HUSH_ZMQ_ZMQABSTRACTNOTIFIER_H
|
||||
|
||||
#include "zmqconfig.h"
|
||||
|
||||
class CBlockIndex;
|
||||
class CZMQAbstractNotifier;
|
||||
|
||||
typedef CZMQAbstractNotifier* (*CZMQNotifierFactory)();
|
||||
|
||||
class CZMQAbstractNotifier
|
||||
{
|
||||
public:
|
||||
CZMQAbstractNotifier() : psocket(0) { }
|
||||
virtual ~CZMQAbstractNotifier();
|
||||
|
||||
template <typename T>
|
||||
static CZMQAbstractNotifier* Create()
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
|
||||
std::string GetType() const { return type; }
|
||||
void SetType(const std::string &t) { type = t; }
|
||||
std::string GetAddress() const { return address; }
|
||||
void SetAddress(const std::string &a) { address = a; }
|
||||
|
||||
virtual bool Initialize(void *pcontext) = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
|
||||
virtual bool NotifyBlock(const CBlockIndex *pindex);
|
||||
virtual bool NotifyBlock(const CBlock& pblock);
|
||||
virtual bool NotifyTransaction(const CTransaction &transaction);
|
||||
|
||||
protected:
|
||||
void *psocket;
|
||||
std::string type;
|
||||
std::string address;
|
||||
};
|
||||
|
||||
#endif // HUSH_ZMQ_ZMQABSTRACTNOTIFIER_H
|
||||
@@ -1,24 +0,0 @@
|
||||
// Copyright (c) 2015 The Bitcoin Core developers
|
||||
// Distributed under the GPLv3 software license, see the accompanying
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
|
||||
#ifndef HUSH_ZMQ_ZMQCONFIG_H
|
||||
#define HUSH_ZMQ_ZMQCONFIG_H
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include "config/bitcoin-config.h"
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
|
||||
#if ENABLE_ZMQ
|
||||
#include <zmq.h>
|
||||
#endif
|
||||
|
||||
#include "primitives/block.h"
|
||||
#include "primitives/transaction.h"
|
||||
|
||||
void zmqError(const char *str);
|
||||
|
||||
#endif // HUSH_ZMQ_ZMQCONFIG_H
|
||||
@@ -1,181 +0,0 @@
|
||||
// Copyright (c) 2015 The Bitcoin Core developers
|
||||
// Distributed under the GPLv3 software license, see the accompanying
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
|
||||
#include "zmqnotificationinterface.h"
|
||||
#include "zmqpublishnotifier.h"
|
||||
|
||||
#include "version.h"
|
||||
#include "main.h"
|
||||
#include "streams.h"
|
||||
#include "util.h"
|
||||
|
||||
void zmqError(const char *str)
|
||||
{
|
||||
LogPrint("zmq", "zmq: Error: %s, errno=%s\n", str, zmq_strerror(errno));
|
||||
}
|
||||
|
||||
CZMQNotificationInterface::CZMQNotificationInterface() : pcontext(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CZMQNotificationInterface::~CZMQNotificationInterface()
|
||||
{
|
||||
Shutdown();
|
||||
|
||||
for (std::list<CZMQAbstractNotifier*>::iterator i=notifiers.begin(); i!=notifiers.end(); ++i)
|
||||
{
|
||||
delete *i;
|
||||
}
|
||||
}
|
||||
|
||||
CZMQNotificationInterface* CZMQNotificationInterface::CreateWithArguments(const std::map<std::string, std::string> &args)
|
||||
{
|
||||
CZMQNotificationInterface* notificationInterface = NULL;
|
||||
std::map<std::string, CZMQNotifierFactory> factories;
|
||||
std::list<CZMQAbstractNotifier*> notifiers;
|
||||
|
||||
factories["pubhashblock"] = CZMQAbstractNotifier::Create<CZMQPublishHashBlockNotifier>;
|
||||
factories["pubhashtx"] = CZMQAbstractNotifier::Create<CZMQPublishHashTransactionNotifier>;
|
||||
factories["pubrawblock"] = CZMQAbstractNotifier::Create<CZMQPublishRawBlockNotifier>;
|
||||
factories["pubrawtx"] = CZMQAbstractNotifier::Create<CZMQPublishRawTransactionNotifier>;
|
||||
factories["pubcheckedblock"] = CZMQAbstractNotifier::Create<CZMQPublishCheckedBlockNotifier>;
|
||||
|
||||
for (std::map<std::string, CZMQNotifierFactory>::const_iterator i=factories.begin(); i!=factories.end(); ++i)
|
||||
{
|
||||
std::map<std::string, std::string>::const_iterator j = args.find("-zmq" + i->first);
|
||||
if (j!=args.end())
|
||||
{
|
||||
CZMQNotifierFactory factory = i->second;
|
||||
std::string address = j->second;
|
||||
CZMQAbstractNotifier *notifier = factory();
|
||||
notifier->SetType(i->first);
|
||||
notifier->SetAddress(address);
|
||||
notifiers.push_back(notifier);
|
||||
}
|
||||
}
|
||||
|
||||
if (!notifiers.empty())
|
||||
{
|
||||
notificationInterface = new CZMQNotificationInterface();
|
||||
notificationInterface->notifiers = notifiers;
|
||||
|
||||
if (!notificationInterface->Initialize())
|
||||
{
|
||||
delete notificationInterface;
|
||||
notificationInterface = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return notificationInterface;
|
||||
}
|
||||
|
||||
// Called at startup to conditionally set up ZMQ socket(s)
|
||||
bool CZMQNotificationInterface::Initialize()
|
||||
{
|
||||
LogPrint("zmq", "zmq: Initialize notification interface\n");
|
||||
assert(!pcontext);
|
||||
|
||||
pcontext = zmq_init(1);
|
||||
|
||||
if (!pcontext)
|
||||
{
|
||||
zmqError("Unable to initialize context");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::list<CZMQAbstractNotifier*>::iterator i=notifiers.begin();
|
||||
for (; i!=notifiers.end(); ++i)
|
||||
{
|
||||
CZMQAbstractNotifier *notifier = *i;
|
||||
if (notifier->Initialize(pcontext))
|
||||
{
|
||||
LogPrint("zmq", " Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress());
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint("zmq", " Notifier %s failed (address = %s)\n", notifier->GetType(), notifier->GetAddress());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i!=notifiers.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Called during shutdown sequence
|
||||
void CZMQNotificationInterface::Shutdown()
|
||||
{
|
||||
LogPrint("zmq", "zmq: Shutdown notification interface\n");
|
||||
if (pcontext)
|
||||
{
|
||||
for (std::list<CZMQAbstractNotifier*>::iterator i=notifiers.begin(); i!=notifiers.end(); ++i)
|
||||
{
|
||||
CZMQAbstractNotifier *notifier = *i;
|
||||
LogPrint("zmq", " Shutdown notifier %s at %s\n", notifier->GetType(), notifier->GetAddress());
|
||||
notifier->Shutdown();
|
||||
}
|
||||
zmq_ctx_destroy(pcontext);
|
||||
|
||||
pcontext = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CZMQNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindex)
|
||||
{
|
||||
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
|
||||
{
|
||||
CZMQAbstractNotifier *notifier = *i;
|
||||
if (notifier->NotifyBlock(pindex))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifier->Shutdown();
|
||||
i = notifiers.erase(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CZMQNotificationInterface::BlockChecked(const CBlock& block, const CValidationState& state)
|
||||
{
|
||||
if (state.IsInvalid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
|
||||
{
|
||||
CZMQAbstractNotifier *notifier = *i;
|
||||
if (notifier->NotifyBlock(block))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifier->Shutdown();
|
||||
i = notifiers.erase(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CZMQNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock)
|
||||
{
|
||||
for (std::list<CZMQAbstractNotifier*>::iterator i = notifiers.begin(); i!=notifiers.end(); )
|
||||
{
|
||||
CZMQAbstractNotifier *notifier = *i;
|
||||
if (notifier->NotifyTransaction(tx))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
notifier->Shutdown();
|
||||
i = notifiers.erase(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// Copyright (c) 2015 The Bitcoin Core developers
|
||||
// Distributed under the GPLv3 software license, see the accompanying
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
|
||||
#ifndef HUSH_ZMQ_ZMQNOTIFICATIONINTERFACE_H
|
||||
#define HUSH_ZMQ_ZMQNOTIFICATIONINTERFACE_H
|
||||
|
||||
#include "validationinterface.h"
|
||||
#include "consensus/validation.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class CBlockIndex;
|
||||
class CZMQAbstractNotifier;
|
||||
|
||||
class CZMQNotificationInterface : public CValidationInterface
|
||||
{
|
||||
public:
|
||||
virtual ~CZMQNotificationInterface();
|
||||
|
||||
static CZMQNotificationInterface* CreateWithArguments(const std::map<std::string, std::string> &args);
|
||||
|
||||
protected:
|
||||
bool Initialize();
|
||||
void Shutdown();
|
||||
|
||||
// CValidationInterface
|
||||
void SyncTransaction(const CTransaction &tx, const CBlock *pblock);
|
||||
void UpdatedBlockTip(const CBlockIndex *pindex);
|
||||
void BlockChecked(const CBlock& block, const CValidationState& state);
|
||||
|
||||
private:
|
||||
CZMQNotificationInterface();
|
||||
|
||||
void *pcontext;
|
||||
std::list<CZMQAbstractNotifier*> notifiers;
|
||||
};
|
||||
|
||||
#endif // HUSH_ZMQ_ZMQNOTIFICATIONINTERFACE_H
|
||||
@@ -1,203 +0,0 @@
|
||||
// Copyright (c) 2015 The Bitcoin Core developers
|
||||
// Distributed under the GPLv3 software license, see the accompanying
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
|
||||
#include "zmqpublishnotifier.h"
|
||||
#include "main.h"
|
||||
#include "util.h"
|
||||
|
||||
static std::multimap<std::string, CZMQAbstractPublishNotifier*> mapPublishNotifiers;
|
||||
|
||||
static const char *MSG_HASHBLOCK = "hashblock";
|
||||
static const char *MSG_HASHTX = "hashtx";
|
||||
static const char *MSG_RAWBLOCK = "rawblock";
|
||||
static const char *MSG_RAWTX = "rawtx";
|
||||
static const char *MSG_CHECKEDBLOCK = "checkedblock";
|
||||
|
||||
// Internal function to send multipart message
|
||||
static int zmq_send_multipart(void *sock, const void* data, size_t size, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, size);
|
||||
|
||||
while (1)
|
||||
{
|
||||
zmq_msg_t msg;
|
||||
|
||||
int rc = zmq_msg_init_size(&msg, size);
|
||||
if (rc != 0)
|
||||
{
|
||||
zmqError("Unable to initialize ZMQ msg");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *buf = zmq_msg_data(&msg);
|
||||
memcpy(buf, data, size);
|
||||
|
||||
data = va_arg(args, const void*);
|
||||
|
||||
rc = zmq_msg_send(&msg, sock, data ? ZMQ_SNDMORE : 0);
|
||||
if (rc == -1)
|
||||
{
|
||||
zmqError("Unable to send ZMQ msg");
|
||||
zmq_msg_close(&msg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
zmq_msg_close(&msg);
|
||||
|
||||
if (!data)
|
||||
break;
|
||||
|
||||
size = va_arg(args, size_t);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool CZMQAbstractPublishNotifier::Initialize(void *pcontext)
|
||||
{
|
||||
assert(!psocket);
|
||||
|
||||
// check if address is being used by other publish notifier
|
||||
std::multimap<std::string, CZMQAbstractPublishNotifier*>::iterator i = mapPublishNotifiers.find(address);
|
||||
|
||||
if (i==mapPublishNotifiers.end())
|
||||
{
|
||||
psocket = zmq_socket(pcontext, ZMQ_PUB);
|
||||
if (!psocket)
|
||||
{
|
||||
zmqError("Failed to create socket");
|
||||
return false;
|
||||
}
|
||||
|
||||
int rc = zmq_bind(psocket, address.c_str());
|
||||
if (rc!=0)
|
||||
{
|
||||
zmqError("Failed to bind address");
|
||||
zmq_close(psocket);
|
||||
return false;
|
||||
}
|
||||
|
||||
// register this notifier for the address, so it can be reused for other publish notifier
|
||||
mapPublishNotifiers.insert(std::make_pair(address, this));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint("zmq", "zmq: Reusing socket for address %s\n", address);
|
||||
|
||||
psocket = i->second->psocket;
|
||||
mapPublishNotifiers.insert(std::make_pair(address, this));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void CZMQAbstractPublishNotifier::Shutdown()
|
||||
{
|
||||
assert(psocket);
|
||||
|
||||
int count = mapPublishNotifiers.count(address);
|
||||
|
||||
// remove this notifier from the list of publishers using this address
|
||||
typedef std::multimap<std::string, CZMQAbstractPublishNotifier*>::iterator iterator;
|
||||
std::pair<iterator, iterator> iterpair = mapPublishNotifiers.equal_range(address);
|
||||
|
||||
for (iterator it = iterpair.first; it != iterpair.second; ++it)
|
||||
{
|
||||
if (it->second==this)
|
||||
{
|
||||
mapPublishNotifiers.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
LogPrint("zmq", "Close socket at address %s\n", address);
|
||||
int linger = 0;
|
||||
zmq_setsockopt(psocket, ZMQ_LINGER, &linger, sizeof(linger));
|
||||
zmq_close(psocket);
|
||||
}
|
||||
|
||||
psocket = 0;
|
||||
}
|
||||
|
||||
bool CZMQAbstractPublishNotifier::SendMessage(const char *command, const void* data, size_t size)
|
||||
{
|
||||
assert(psocket);
|
||||
|
||||
/* send three parts, command & data & a LE 4byte sequence number */
|
||||
unsigned char msgseq[sizeof(uint32_t)];
|
||||
WriteLE32(&msgseq[0], nSequence);
|
||||
int rc = zmq_send_multipart(psocket, command, strlen(command), data, size, msgseq, (size_t)sizeof(uint32_t), (void*)0);
|
||||
if (rc == -1)
|
||||
return false;
|
||||
|
||||
/* increment memory only sequence number after sending */
|
||||
nSequence++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CZMQPublishHashBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
|
||||
{
|
||||
uint256 hash = pindex->GetBlockHash();
|
||||
LogPrint("zmq", "zmq: Publish hashblock %s\n", hash.GetHex());
|
||||
char data[32];
|
||||
for (unsigned int i = 0; i < 32; i++)
|
||||
data[31 - i] = hash.begin()[i];
|
||||
return SendMessage(MSG_HASHBLOCK, data, 32);
|
||||
}
|
||||
|
||||
bool CZMQPublishHashTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
|
||||
{
|
||||
uint256 hash = transaction.GetHash();
|
||||
LogPrint("zmq", "zmq: Publish hashtx %s\n", hash.GetHex());
|
||||
char data[32];
|
||||
for (unsigned int i = 0; i < 32; i++)
|
||||
data[31 - i] = hash.begin()[i];
|
||||
return SendMessage(MSG_HASHTX, data, 32);
|
||||
}
|
||||
|
||||
bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
|
||||
{
|
||||
LogPrint("zmq", "zmq: Publish rawblock %s\n", pindex->GetBlockHash().GetHex());
|
||||
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
{
|
||||
LOCK(cs_main);
|
||||
CBlock block;
|
||||
if(!ReadBlockFromDisk(block, pindex,1))
|
||||
{
|
||||
zmqError("Can't read block from disk");
|
||||
return false;
|
||||
}
|
||||
|
||||
ss << block;
|
||||
}
|
||||
|
||||
return SendMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size());
|
||||
}
|
||||
|
||||
bool CZMQPublishCheckedBlockNotifier::NotifyBlock(const CBlock& block)
|
||||
{
|
||||
LogPrint("zmq", "zmq: Publish checkedblock %s\n", block.GetHash().GetHex());
|
||||
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
{
|
||||
LOCK(cs_main);
|
||||
ss << block;
|
||||
}
|
||||
|
||||
return SendMessage(MSG_CHECKEDBLOCK, &(*ss.begin()), ss.size());
|
||||
}
|
||||
|
||||
bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &transaction)
|
||||
{
|
||||
uint256 hash = transaction.GetHash();
|
||||
LogPrint("zmq", "zmq: Publish rawtx %s\n", hash.GetHex());
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << transaction;
|
||||
return SendMessage(MSG_RAWTX, &(*ss.begin()), ss.size());
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
// Copyright (c) 2015 The Bitcoin Core developers
|
||||
// Distributed under the GPLv3 software license, see the accompanying
|
||||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
||||
|
||||
#ifndef HUSH_ZMQ_ZMQPUBLISHNOTIFIER_H
|
||||
#define HUSH_ZMQ_ZMQPUBLISHNOTIFIER_H
|
||||
|
||||
#include "zmqabstractnotifier.h"
|
||||
|
||||
class CBlockIndex;
|
||||
|
||||
class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier
|
||||
{
|
||||
private:
|
||||
uint32_t nSequence; //! upcounting per message sequence number
|
||||
|
||||
public:
|
||||
|
||||
/* send zmq multipart message
|
||||
parts:
|
||||
* command
|
||||
* data
|
||||
* message sequence number
|
||||
*/
|
||||
bool SendMessage(const char *command, const void* data, size_t size);
|
||||
|
||||
bool Initialize(void *pcontext);
|
||||
void Shutdown();
|
||||
};
|
||||
|
||||
class CZMQPublishHashBlockNotifier : public CZMQAbstractPublishNotifier
|
||||
{
|
||||
public:
|
||||
bool NotifyBlock(const CBlockIndex *pindex);
|
||||
};
|
||||
|
||||
class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier
|
||||
{
|
||||
public:
|
||||
bool NotifyTransaction(const CTransaction &transaction);
|
||||
};
|
||||
|
||||
class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier
|
||||
{
|
||||
public:
|
||||
bool NotifyBlock(const CBlockIndex *pindex);
|
||||
};
|
||||
|
||||
class CZMQPublishRawTransactionNotifier : public CZMQAbstractPublishNotifier
|
||||
{
|
||||
public:
|
||||
bool NotifyTransaction(const CTransaction &transaction);
|
||||
};
|
||||
|
||||
class CZMQPublishCheckedBlockNotifier : public CZMQAbstractPublishNotifier
|
||||
{
|
||||
public:
|
||||
bool NotifyBlock(const CBlock &block);
|
||||
};
|
||||
|
||||
#endif // HUSH_ZMQ_ZMQPUBLISHNOTIFIER_H
|
||||
Reference in New Issue
Block a user