diff --git a/configure.ac b/configure.ac index 794c486c0..801d7be75 100644 --- a/configure.ac +++ b/configure.ac @@ -151,12 +151,6 @@ AC_ARG_ENABLE([glibc-back-compat], [use_glibc_compat=$enableval], [use_glibc_compat=no]) -AC_ARG_ENABLE([zmq], - [AS_HELP_STRING([--disable-zmq], - [disable ZMQ notifications])], - [use_zmq=$enableval], - [use_zmq=yes]) - AC_ARG_ENABLE([experimental-asm], [AS_HELP_STRING([--enable-experimental-asm], [Enable experimental assembly routines (default is no)])], @@ -673,15 +667,6 @@ if test x$use_pkgconfig = xyes; then fi fi - if test "x$use_zmq" = "xyes"; then - PKG_CHECK_MODULES([ZMQ],[libzmq >= 4], - [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])], - [AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions]) - AC_MSG_WARN([libzmq version 4.x or greater not found, disabling]) - use_zmq=no]) - else - AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions]) - fi ] ) else @@ -718,28 +703,7 @@ fi #AC_CHECK_HEADER([gmpxx.h],,AC_MSG_ERROR(libgmpxx headers missing)) #AC_CHECK_LIB([gmpxx],[main],GMPXX_LIBS=-lgmpxx, [AC_MSG_ERROR(libgmpxx missing)]) - if test "x$use_zmq" = "xyes"; then - AC_CHECK_HEADER([zmq.h], - [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])], - [AC_MSG_WARN([zmq.h not found, disabling zmq support]) - use_zmq=no - AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])]) - AC_CHECK_LIB([zmq],[zmq_ctx_shutdown],ZMQ_LIBS=-lzmq, - [AC_MSG_WARN([libzmq >= 4.0 not found, disabling zmq support]) - use_zmq=no - AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])]) - else - AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions]) - fi - if test "x$use_zmq" = "xyes"; then - dnl Assume libzmq was built for static linking - case $host in - *mingw*) - ZMQ_CFLAGS="$ZMQ_CFLAGS -DZMQ_STATIC" - ;; - esac - fi fi # These packages don't provide pkgconfig config files across all @@ -824,8 +788,6 @@ else AC_MSG_RESULT(no) fi -AM_CONDITIONAL([ENABLE_ZMQ], [test "x$use_zmq" = "xyes"]) - AC_MSG_CHECKING([whether to build test_bitcoin]) if test x$use_tests = xyes; then AC_MSG_RESULT([yes]) @@ -894,7 +856,6 @@ AC_SUBST(CRYPTO_LIBS) AC_SUBST(SSL_LIBS) AC_SUBST(EVENT_LIBS) AC_SUBST(EVENT_PTHREADS_LIBS) -AC_SUBST(ZMQ_LIBS) AC_SUBST(GMP_LIBS) AC_SUBST(GMPXX_LIBS) AC_SUBST(LIBZCASH_LIBS) @@ -944,7 +905,6 @@ esac echo echo "Options used to compile and link:" echo " with wallet = $enable_wallet" -echo " with zmq = $use_zmq" echo " with test = $use_tests" echo " debug enabled = $enable_debug" echo " werror = $enable_werror" diff --git a/contrib/debian/copyright b/contrib/debian/copyright index f2d71c287..7bf3a707c 100644 --- a/contrib/debian/copyright +++ b/contrib/debian/copyright @@ -23,19 +23,6 @@ Copyright: 1990, 2016 Oracle and/or its affiliates; 2000-2005 INRIA, France Telecom License: BDB -Files: depends/sources/zeromq-*.tar.gz -Copyright: - 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. - 2007-2014 iMatix Corporation - 2009-2011 250bpm s.r.o. - 2010-2011 Miru Limited - 2011 VMware, Inc. - 2012 Spotify AB - 2013 Ericsson AB - 2014 AppDynamics Inc. - 2015-2016 Brocade Communications Systems Inc. -License: LGPL-with-ZeroMQ-exception - Files: depends/sources/google*.tar.gz Copyright: 2008 Google Inc. License: BSD-3clause-Google @@ -1056,35 +1043,6 @@ Comment: You should have received a copy of the GNU General Public License along with this program. If not, see . -License: LGPL-with-ZeroMQ-exception - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - . - On Debian systems the GNU Lesser General Public License (LGPL) is - located in '/usr/share/common-licenses/LGPL'. - . - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -------------------------------------------------------------------------------- - SPECIAL EXCEPTION GRANTED BY COPYRIGHT HOLDERS - . - As a special exception, copyright holders give you permission to link this - library with independent modules to produce an executable, regardless of - the license terms of these independent modules, and to copy and distribute - the resulting executable under terms of your choice, provided that you also - meet, for each linked independent module, the terms and conditions of - the license of that module. An independent module is a module which is not - derived from or based on this library. If you modify this library, you must - extend this exception to your version of the library. - - Note: this exception relieves you of any obligations under sections 4 and 5 - of this license, and section 6 of the GNU General Public License. -Comment: - You should have received a copy of the GNU General Public License - along with this program. If not, see . - License: GNU-All-permissive-License Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice diff --git a/contrib/zmq/zmq_sub.py b/contrib/zmq/zmq_sub.py deleted file mode 100755 index 902fc73c5..000000000 --- a/contrib/zmq/zmq_sub.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python2 -# Copyright (c) 2014-2016 The Bitcoin Core developers -# Copyright (c) 2016-2021 The Hush developers -# Distributed under the GPLv3 software license, see the accompanying -# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -import array -import binascii -import zmq -import struct - -port = 28332 - -zmqContext = zmq.Context() -zmqSubSocket = zmqContext.socket(zmq.SUB) -zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "hashblock") -zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "hashtx") -zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "rawblock") -zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "rawtx") -zmqSubSocket.connect("tcp://127.0.0.1:%i" % port) - -try: - while True: - msg = zmqSubSocket.recv_multipart() - topic = str(msg[0]) - body = msg[1] - sequence = "Unknown"; - if len(msg[-1]) == 4: - msgSequence = struct.unpack('. @@ -29,7 +29,7 @@ Specify configuration file (default: HUSH3.conf) .HP \fB\-datadir=\fR .IP -Specify data directory +Specify data directory (this path cannot use '~') .HP \fB\-testnet\fR .IP @@ -76,11 +76,8 @@ In order to ensure you are adequately protecting your privacy when using Hush, please see . Copyright (C) 2016-2021 Duke Leto and The Hush Developers - Copyright (C) 2016-2020 jl777 and SuperNET developers - Copyright (C) 2016-2018 The Zcash developers - Copyright (C) 2009-2014 The Bitcoin Core developers This is experimental Free Software! Fuck Yeah!!!!! diff --git a/doc/man/hush-tx.1 b/doc/man/hush-tx.1 index 7b1124b70..8318b2aa2 100644 --- a/doc/man/hush-tx.1 +++ b/doc/man/hush-tx.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.13. -.TH HUSH-TX "1" "January 2022" "hush-tx v3.9.1" "User Commands" +.TH HUSH-TX "1" "September 2022" "hush-tx v3.9.1" "User Commands" .SH NAME hush-tx \- manual page for hush-tx v3.9.1 .SH DESCRIPTION -hush\-tx utility version v3.9.1\-804a4abbe\-dirty +hush\-tx utility version v3.9.1\-1799c6c9b .SS "Usage:" .TP hush\-tx [options] [commands] @@ -89,11 +89,8 @@ In order to ensure you are adequately protecting your privacy when using Hush, please see . Copyright (C) 2016-2021 Duke Leto and The Hush Developers - Copyright (C) 2016-2020 jl777 and SuperNET developers - Copyright (C) 2016-2018 The Zcash developers - Copyright (C) 2009-2014 The Bitcoin Core developers This is experimental Free Software! Fuck Yeah!!!!! diff --git a/doc/man/hushd.1 b/doc/man/hushd.1 index 539f544be..eebf51b5b 100644 --- a/doc/man/hushd.1 +++ b/doc/man/hushd.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.13. -.TH HUSHD "1" "January 2022" "hushd v3.9.1" "User Commands" +.TH HUSHD "1" "September 2022" "hushd v3.9.1" "User Commands" .SH NAME hushd \- manual page for hushd v3.9.1 .SH DESCRIPTION -Hush Daemon version v3.9.1\-804a4abbe\-dirty +Hush Daemon version v3.9.1\-1799c6c9b .PP In order to ensure you are adequately protecting your privacy when using Hush, please see . @@ -49,7 +49,7 @@ Run in the background as a daemon and accept commands .HP \fB\-datadir=\fR .IP -Specify data directory +Specify data directory (this path cannot use '~') .HP \fB\-exportdir=\fR .IP @@ -414,24 +414,6 @@ Delete all wallet transactions and only recover those parts of the blockchain through \fB\-rescan\fR on startup (1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data) .PP -ZeroMQ notification options: -.HP -\fB\-zmqpubhashblock=\fR
-.IP -Enable publish hash block in
-.HP -\fB\-zmqpubhashtx=\fR
-.IP -Enable publish hash transaction in
-.HP -\fB\-zmqpubrawblock=\fR
-.IP -Enable publish raw block in
-.HP -\fB\-zmqpubrawtx=\fR
-.IP -Enable publish raw transaction in
-.PP Debugging/Testing options: .HP \fB\-debug=\fR @@ -440,8 +422,8 @@ Output debugging information (default: 0, supplying is optional). If is not supplied or if = 1, output all debugging information. can be: addrman, alert, bench, coindb, db, deletetx, estimatefee, http, libevent, lock, mempool, net, -tls, partitioncheck, pow, proxy, prune, rand, reindex, rpc, selectcoins, -stratum, tor, zmq, zrpc, zrpcunsafe (implies zrpc). +tls, partitioncheck, pow, proxy, prune, rand, randomx, reindex, rpc, +selectcoins, stratum, tor, zrpc, zrpcunsafe (implies zrpc). .HP \fB\-experimentalfeatures\fR .IP @@ -614,7 +596,8 @@ Hush Smart Chain options: .HP \fB\-ac_algo\fR .IP -Choose PoW mining algorithm, default is Equihash (200,9) +Choose PoW mining algorithm, either 'equihash' or 'randomx'. default is +Equihash (200,9) .HP \fB\-ac_blocktime\fR .IP @@ -713,11 +696,8 @@ In order to ensure you are adequately protecting your privacy when using Hush, please see . Copyright (C) 2016-2021 Duke Leto and The Hush Developers - Copyright (C) 2016-2020 jl777 and SuperNET developers - Copyright (C) 2016-2018 The Zcash developers - Copyright (C) 2009-2014 The Bitcoin Core developers This is experimental Free Software! Fuck Yeah!!!!! diff --git a/doc/zmq.md b/doc/zmq.md deleted file mode 100644 index c5ce11ff6..000000000 --- a/doc/zmq.md +++ /dev/null @@ -1,107 +0,0 @@ -# Block and Transaction Broadcasting With ZeroMQ - -[ZeroMQ](http://zeromq.org/) is a lightweight wrapper around TCP -connections, inter-process communication, and shared-memory, -providing various message-oriented semantics such as publish/subscribe, -request/reply, and push/pull. - -The Hush daemon can be configured to act as a trusted "border -router", implementing the Hush wire protocol and relay, making -consensus decisions, maintaining the local blockchain database, -broadcasting locally generated transactions into the network, and -providing a queryable RPC interface to interact on a polled basis for -requesting blockchain related data. However, there exists only a -limited service to notify external software of events like the arrival -of new blocks or transactions. - -The ZeroMQ facility implements a notification interface through a set -of specific notifiers. Currently there are notifiers that publish -blocks and transactions. This read-only facility requires only the -connection of a corresponding ZeroMQ subscriber port in receiving -software; it is not authenticated nor is there any two-way protocol -involvement. Therefore, subscribers should validate the received data -since it may be out of date, incomplete or even invalid. - -ZeroMQ sockets are self-connecting and self-healing; that is, -connections made between two endpoints will be automatically restored -after an outage, and either end may be freely started or stopped in -any order. - -Because ZeroMQ is message oriented, subscribers receive transactions -and blocks all-at-once and do not need to implement any sort of -buffering or reassembly. - -## Prerequisites - -The ZeroMQ feature in Hush requires ZeroMQ API version 4.x or -newer, which you will need to install if you are not using the depends -system. Typically, it is packaged by distributions as something like -*libzmq5-dev*. The C++ wrapper for ZeroMQ is *not* needed. - -In order to run the example Python client scripts in contrib/ one must -also install *python-zmq*, though this is not necessary for daemon -operation. - -## Enabling - -By default, the ZeroMQ feature is automatically compiled in if the -necessary prerequisites are found. To disable, use --disable-zmq -during the *configure* step of building hushd: - - $ ./configure --disable-zmq (other options) - -To actually enable operation, one must set the appropriate options on -the commandline or in the configuration file. - -## Usage - -Currently, the following notifications are supported: - - -zmqpubhashtx=address - -zmqpubhashblock=address - -zmqpubrawblock=address - -zmqpubrawtx=address - -The socket type is PUB and the address must be a valid ZeroMQ socket -address. The same address can be used in more than one notification. - -For instance: - - $ hushd -zmqpubhashtx=tcp://127.0.0.1:28332 \ - -zmqpubrawtx=ipc:///tmp/hushd.tx.raw - -Each PUB notification has a topic and body, where the header -corresponds to the notification type. For instance, for the -notification `-zmqpubhashtx` the topic is `hashtx` (no null -terminator) and the body is the hexadecimal transaction hash (32 -bytes). - -These options can also be provided in zcash.conf. - -ZeroMQ endpoint specifiers for TCP (and others) are documented in the -[ZeroMQ API](http://api.zeromq.org/4-0:_start). - -Client side, then, the ZeroMQ subscriber socket must have the -ZMQ_SUBSCRIBE option set to one or either of these prefixes (for -instance, just `hash`); without doing so will result in no messages -arriving. Please see `contrib/zmq/zmq_sub.py` for a working example. - -## Remarks - -From the perspective of hushd, the ZeroMQ socket is write-only; PUB -sockets don't even have a read function. Thus, there is no state -introduced into hushd directly. Furthermore, no information is -broadcast that wasn't already received from the public P2P network. - -No authentication or authorization is done on connecting clients; it -is assumed that the ZeroMQ port is exposed only to trusted entities, -using other means such as firewalling. - -Note that when the block chain tip changes, a reorganisation may occur -and just the tip will be notified. It is up to the subscriber to -retrieve the chain from the last known block to the new tip. - -There are several possibilities that ZMQ notification can get lost -during transmission depending on the communication type you are -using. Hushd appends an up-counting sequence number to each -notification which allows listeners to detect lost notifications. diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 8b8169a2f..153f7b4a6 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -92,10 +92,6 @@ testScriptsExt=( 'p2p-acceptblock.py' ); -if [ "x$ENABLE_ZMQ" = "x1" ]; then - testScripts+=('zmq_test.py') -fi - extArg="-extended" passOn=${@#$extArg} diff --git a/qa/pull-tester/tests-config.sh.in b/qa/pull-tester/tests-config.sh.in index a011831b1..d48d5bbc5 100755 --- a/qa/pull-tester/tests-config.sh.in +++ b/qa/pull-tester/tests-config.sh.in @@ -11,7 +11,6 @@ EXEEXT="@EXEEXT@" @ENABLE_WALLET_TRUE@ENABLE_WALLET=1 @BUILD_BITCOIN_UTILS_TRUE@ENABLE_UTILS=1 @BUILD_BITCOIND_TRUE@ENABLE_BITCOIND=1 -@ENABLE_ZMQ_TRUE@ENABLE_ZMQ=1 @ENABLE_PROTON_TRUE@ENABLE_PROTON=1 REAL_BITCOIND="$BUILDDIR/src/hushd${EXEEXT}" diff --git a/qa/rpc-tests/zmq_test.py b/qa/rpc-tests/zmq_test.py deleted file mode 100755 index 7ca50efb4..000000000 --- a/qa/rpc-tests/zmq_test.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers -# 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 -# Test ZMQ interface - -from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, bytes_to_hex_str, start_nodes - -import zmq -import struct - -class ZMQTest(BitcoinTestFramework): - - port = 28332 - - def setup_nodes(self): - self.zmqContext = zmq.Context() - self.zmqSubSocket = self.zmqContext.socket(zmq.SUB) - self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashblock") - self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashtx") - self.zmqSubSocket.connect("tcp://127.0.0.1:%i" % self.port) - return start_nodes(4, self.options.tmpdir, extra_args=[ - ['-zmqpubhashtx=tcp://127.0.0.1:'+str(self.port), '-zmqpubhashblock=tcp://127.0.0.1:'+str(self.port)], - [], - [], - [] - ]) - - def run_test(self): - self.sync_all() - - genhashes = self.nodes[0].generate(1) - self.sync_all() - - print "listen..." - msg = self.zmqSubSocket.recv_multipart() - topic = msg[0] - body = msg[1] - msgSequence = struct.unpack(' #include #include - -#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=
", _("Enable publish hash block in
")); - strUsage += HelpMessageOpt("-zmqpubhashtx=
", _("Enable publish hash transaction in
")); - strUsage += HelpMessageOpt("-zmqpubrawblock=
", _("Enable publish raw block in
")); - strUsage += HelpMessageOpt("-zmqpubrawtx=
", _("Enable publish raw transaction in
")); -#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=", strprintf(_("Output debugging information (default: %u, supplying is optional)"), 0) + ". " + _("If is not supplied or if = 1, output all debugging information.") + " " + _(" 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 vImportFiles; diff --git a/src/zmq/zmqabstractnotifier.cpp b/src/zmq/zmqabstractnotifier.cpp deleted file mode 100644 index b2f1d0833..000000000 --- a/src/zmq/zmqabstractnotifier.cpp +++ /dev/null @@ -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; -} diff --git a/src/zmq/zmqabstractnotifier.h b/src/zmq/zmqabstractnotifier.h deleted file mode 100644 index d9d3cb0de..000000000 --- a/src/zmq/zmqabstractnotifier.h +++ /dev/null @@ -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 - 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 diff --git a/src/zmq/zmqconfig.h b/src/zmq/zmqconfig.h deleted file mode 100644 index e561b0e7b..000000000 --- a/src/zmq/zmqconfig.h +++ /dev/null @@ -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 -#include - -#if ENABLE_ZMQ -#include -#endif - -#include "primitives/block.h" -#include "primitives/transaction.h" - -void zmqError(const char *str); - -#endif // HUSH_ZMQ_ZMQCONFIG_H diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp deleted file mode 100644 index 50838c9c9..000000000 --- a/src/zmq/zmqnotificationinterface.cpp +++ /dev/null @@ -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::iterator i=notifiers.begin(); i!=notifiers.end(); ++i) - { - delete *i; - } -} - -CZMQNotificationInterface* CZMQNotificationInterface::CreateWithArguments(const std::map &args) -{ - CZMQNotificationInterface* notificationInterface = NULL; - std::map factories; - std::list notifiers; - - factories["pubhashblock"] = CZMQAbstractNotifier::Create; - factories["pubhashtx"] = CZMQAbstractNotifier::Create; - factories["pubrawblock"] = CZMQAbstractNotifier::Create; - factories["pubrawtx"] = CZMQAbstractNotifier::Create; - factories["pubcheckedblock"] = CZMQAbstractNotifier::Create; - - for (std::map::const_iterator i=factories.begin(); i!=factories.end(); ++i) - { - std::map::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::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::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::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::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::iterator i = notifiers.begin(); i!=notifiers.end(); ) - { - CZMQAbstractNotifier *notifier = *i; - if (notifier->NotifyTransaction(tx)) - { - i++; - } - else - { - notifier->Shutdown(); - i = notifiers.erase(i); - } - } -} diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h deleted file mode 100644 index 14542a983..000000000 --- a/src/zmq/zmqnotificationinterface.h +++ /dev/null @@ -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 -#include - -class CBlockIndex; -class CZMQAbstractNotifier; - -class CZMQNotificationInterface : public CValidationInterface -{ -public: - virtual ~CZMQNotificationInterface(); - - static CZMQNotificationInterface* CreateWithArguments(const std::map &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 notifiers; -}; - -#endif // HUSH_ZMQ_ZMQNOTIFICATIONINTERFACE_H diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp deleted file mode 100644 index a712bce8a..000000000 --- a/src/zmq/zmqpublishnotifier.cpp +++ /dev/null @@ -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 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::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::iterator iterator; - std::pair 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()); -} diff --git a/src/zmq/zmqpublishnotifier.h b/src/zmq/zmqpublishnotifier.h deleted file mode 100644 index d60276187..000000000 --- a/src/zmq/zmqpublishnotifier.h +++ /dev/null @@ -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