8 #include <chainparams.h> 60 int rc = zmq_msg_init_size(&
msg, size);
63 zmqError(
"Unable to initialize ZMQ msg");
68 void *buf = zmq_msg_data(&
msg);
69 memcpy(buf, data, size);
71 data = va_arg(
args,
const void*);
73 rc = zmq_msg_send(&
msg, sock, data ? ZMQ_SNDMORE : 0);
87 size = va_arg(
args,
size_t);
95 const std::string tcp_prefix =
"tcp://";
96 const size_t tcp_index = zmq_address.rfind(tcp_prefix);
97 const size_t colon_index = zmq_address.rfind(
':');
98 if (tcp_index == 0 && colon_index != std::string::npos) {
99 const std::string
ip = zmq_address.substr(tcp_prefix.length(), colon_index - tcp_prefix.length());
100 const std::optional<CNetAddr> addr{
LookupHost(
ip,
false)};
101 if (addr.has_value() && addr.value().IsIPv6())
return true;
115 psocket = zmq_socket(pcontext, ZMQ_PUB);
118 zmqError(
"Failed to create socket");
127 zmqError(
"Failed to set outbound message high water mark");
132 const int so_keepalive_option {1};
133 rc = zmq_setsockopt(
psocket, ZMQ_TCP_KEEPALIVE, &so_keepalive_option,
sizeof(so_keepalive_option));
135 zmqError(
"Failed to set SO_KEEPALIVE");
142 rc = zmq_setsockopt(
psocket, ZMQ_IPV6, &enable_ipv6,
sizeof(enable_ipv6));
181 typedef std::multimap<std::string, CZMQAbstractPublishNotifier*>::iterator iterator;
184 for (iterator it = iterpair.first; it != iterpair.second; ++it)
186 if (it->second==
this)
197 zmq_setsockopt(
psocket, ZMQ_LINGER, &linger,
sizeof(linger));
209 unsigned char msgseq[
sizeof(uint32_t)];
226 for (
unsigned int i = 0; i < 32; i++) {
227 data[31 - i] = hash.
begin()[i];
237 for (
unsigned int i = 0; i < 32; i++) {
238 data[31 - i] = hash.
begin()[i];
250 zmqError(
"Can't read block from disk");
272 unsigned char data[
sizeof(hash) +
sizeof(label) +
sizeof(uint64_t)];
273 for (
unsigned int i = 0; i <
sizeof(hash); ++i) {
274 data[
sizeof(hash) - 1 - i] = hash.
begin()[i];
276 data[
sizeof(hash)] = label;
static const char * MSG_HASHBLOCK
bool NotifyTransaction(const CTransaction &transaction) override
uint32_t nSequence
upcounting per message sequence number
#define LogPrint(category,...)
bool NotifyBlockDisconnect(const CBlockIndex *pindex) override
bool SendZmqMessage(const char *command, const void *data, size_t size)
static std::multimap< std::string, CZMQAbstractPublishNotifier * > mapPublishNotifiers
static bool SendSequenceMsg(CZMQAbstractPublishNotifier ¬ifier, uint256 hash, char label, std::optional< uint64_t > sequence={})
static const char * MSG_HASHTX
bool NotifyTransaction(const CTransaction &transaction) override
Transaction validation functions.
constexpr unsigned char * begin()
bool NotifyBlock(const CBlockIndex *pindex) override
uint256 GetBlockHash() const
const std::function< bool(CBlock &, const CBlockIndex &)> m_get_block_by_index
std::vector< CNetAddr > LookupHost(const std::string &name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
Resolve a host string to its corresponding network addresses.
const uint256 & GetHash() const
bool NotifyBlock(const CBlockIndex *pindex) override
static void WriteLE32(unsigned char *ptr, uint32_t x)
static int zmq_send_multipart(void *sock, const void *data, size_t size,...)
static CService ip(uint32_t i)
static bool IsZMQAddressIPV6(const std::string &zmq_address)
void zmqError(const std::string &str)
bool NotifyTransactionAcceptance(const CTransaction &transaction, uint64_t mempool_sequence) override
static const char * MSG_RAWTX
static const char * MSG_RAWBLOCK
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
int RPCSerializationFlags()
static const int PROTOCOL_VERSION
network protocol versioning
bool NotifyTransactionRemoval(const CTransaction &transaction, uint64_t mempool_sequence) override
std::string GetHex() const
int outbound_message_high_water_mark
bool NotifyBlockConnect(const CBlockIndex *pindex) override
static void WriteLE64(unsigned char *ptr, uint64_t x)
The basic transaction that is broadcasted on the network and contained in blocks. ...
static const char * MSG_SEQUENCE
bool Initialize(void *pcontext) override