mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
zmq: accept unix domain socket address for notifier
This commit is contained in:
parent
312f54278f
commit
c87b0a0ff4
3 changed files with 30 additions and 18 deletions
37
src/init.cpp
37
src/init.cpp
|
@ -1301,30 +1301,33 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const std::string port_option : {
|
for (const auto &port_option : std::vector<std::pair<std::string, bool>>{
|
||||||
"-i2psam",
|
// arg name UNIX socket support
|
||||||
"-onion",
|
{"-i2psam", false},
|
||||||
"-proxy",
|
{"-onion", true},
|
||||||
"-rpcbind",
|
{"-proxy", true},
|
||||||
"-torcontrol",
|
{"-rpcbind", false},
|
||||||
"-whitebind",
|
{"-torcontrol", false},
|
||||||
"-zmqpubhashblock",
|
{"-whitebind", false},
|
||||||
"-zmqpubhashtx",
|
{"-zmqpubhashblock", true},
|
||||||
"-zmqpubrawblock",
|
{"-zmqpubhashtx", true},
|
||||||
"-zmqpubrawtx",
|
{"-zmqpubrawblock", true},
|
||||||
"-zmqpubsequence",
|
{"-zmqpubrawtx", true},
|
||||||
|
{"-zmqpubsequence", true}
|
||||||
}) {
|
}) {
|
||||||
for (const std::string& socket_addr : args.GetArgs(port_option)) {
|
const std::string arg{port_option.first};
|
||||||
|
const bool unix{port_option.second};
|
||||||
|
for (const std::string& socket_addr : args.GetArgs(arg)) {
|
||||||
std::string host_out;
|
std::string host_out;
|
||||||
uint16_t port_out{0};
|
uint16_t port_out{0};
|
||||||
if (!SplitHostPort(socket_addr, port_out, host_out)) {
|
if (!SplitHostPort(socket_addr, port_out, host_out)) {
|
||||||
#if HAVE_SOCKADDR_UN
|
#if HAVE_SOCKADDR_UN
|
||||||
// Allow unix domain sockets for -proxy and -onion e.g. unix:/some/file/path
|
// Allow unix domain sockets for some options e.g. unix:/some/file/path
|
||||||
if ((port_option != "-proxy" && port_option != "-onion") || socket_addr.find(ADDR_PREFIX_UNIX) != 0) {
|
if (!unix || socket_addr.find(ADDR_PREFIX_UNIX) != 0) {
|
||||||
return InitError(InvalidPortErrMsg(port_option, socket_addr));
|
return InitError(InvalidPortErrMsg(arg, socket_addr));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
return InitError(InvalidPortErrMsg(port_option, socket_addr));
|
return InitError(InvalidPortErrMsg(arg, socket_addr));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <kernel/chain.h>
|
#include <kernel/chain.h>
|
||||||
#include <kernel/mempool_entry.h>
|
#include <kernel/mempool_entry.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
|
#include <netbase.h>
|
||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
|
@ -57,7 +58,12 @@ std::unique_ptr<CZMQNotificationInterface> CZMQNotificationInterface::Create(std
|
||||||
{
|
{
|
||||||
std::string arg("-zmq" + entry.first);
|
std::string arg("-zmq" + entry.first);
|
||||||
const auto& factory = entry.second;
|
const auto& factory = entry.second;
|
||||||
for (const std::string& address : gArgs.GetArgs(arg)) {
|
for (std::string& address : gArgs.GetArgs(arg)) {
|
||||||
|
// libzmq uses prefix "ipc://" for UNIX domain sockets
|
||||||
|
if (address.substr(0, ADDR_PREFIX_UNIX.length()) == ADDR_PREFIX_UNIX) {
|
||||||
|
address.replace(0, ADDR_PREFIX_UNIX.length(), ADDR_PREFIX_IPC);
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<CZMQAbstractNotifier> notifier = factory();
|
std::unique_ptr<CZMQAbstractNotifier> notifier = factory();
|
||||||
notifier->SetType(entry.first);
|
notifier->SetType(entry.first);
|
||||||
notifier->SetAddress(address);
|
notifier->SetAddress(address);
|
||||||
|
|
|
@ -9,4 +9,7 @@
|
||||||
|
|
||||||
void zmqError(const std::string& str);
|
void zmqError(const std::string& str);
|
||||||
|
|
||||||
|
/** Prefix for unix domain socket addresses (which are local filesystem paths) */
|
||||||
|
const std::string ADDR_PREFIX_IPC = "ipc://"; // used by libzmq, example "ipc:///root/path/to/file"
|
||||||
|
|
||||||
#endif // BITCOIN_ZMQ_ZMQUTIL_H
|
#endif // BITCOIN_ZMQ_ZMQUTIL_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue