Skip to content

Commit 7c4fb9d

Browse files
committed
ZMQ set & unset subscription filter methods
1 parent a147fb3 commit 7c4fb9d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

include/bitcoin/protocol/zmq/socket.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ class BCP_API socket
115115
/// Configure the socket to connect through the specified socks5 proxy.
116116
bool set_socks_proxy(const config::authority& socks_proxy);
117117

118-
/////// Configure subscriber socket to apply the message filter.
119-
////bool set_subscription(const data_chunk& filter);
118+
/// Configure subscriber socket to apply the message filter.
119+
bool set_subscription(const data_chunk& filter);
120120

121-
/////// Configure subscriber socket to remove the message filter.
122-
////bool set_unsubscription(const data_chunk& filter);
121+
/// Configure subscriber socket to remove the message filter.
122+
bool set_unsubscription(const data_chunk& filter);
123123

124124
/// Send a message on this socket.
125125
code send(message& packet);
@@ -133,6 +133,7 @@ class BCP_API socket
133133
bool set32(int32_t option, int32_t value);
134134
bool set64(int32_t option, int64_t value);
135135
bool set(int32_t option, const std::string& value);
136+
bool set(int32_t option, const data_chunk& value);
136137

137138
private:
138139
void* self_;

src/zmq/socket.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
namespace libbitcoin {
3434
namespace protocol {
3535
namespace zmq {
36-
36+
3737
static const auto subscribe_all = "";
3838
static constexpr int32_t zmq_true = 1;
3939
static constexpr int32_t zmq_false = 0;
@@ -42,7 +42,7 @@ static constexpr int32_t reconnect_interval = 100;
4242
static const bc::protocol::settings default_settings;
4343

4444
// Linger
45-
// The default value of -1 specifies an infinite linger period. Pending
45+
// The default value of -1 specifies an infinite linger period. Pending
4646
// messages shall not be discarded after a call to zmq_close(); attempting to
4747
// terminate the socket's context with zmq_term() shall block until all pending
4848
// messages have been sent to a peer. The value 0 specifies no linger period.
@@ -241,6 +241,13 @@ bool socket::set(int32_t option, const std::string& value)
241241
return zmq_setsockopt(self_, option, buffer, value.size()) != zmq_fail;
242242
}
243243

244+
// private
245+
bool socket::set(int32_t option, const data_chunk& value)
246+
{
247+
return zmq_setsockopt(self_, option, value.data(), value.size())
248+
!= zmq_fail;
249+
}
250+
244251
// For NULL security, ZAP calls are only made for non-empty domain.
245252
// For PLAIN/CURVE, calls are always made if ZAP handler is present.
246253
bool socket::set_authentication_domain(const std::string& domain)
@@ -288,6 +295,16 @@ bool socket::set_socks_proxy(const config::authority& socks_proxy)
288295
return socks_proxy && set(ZMQ_SOCKS_PROXY, socks_proxy.to_string());
289296
}
290297

298+
bool socket::set_subscription(const data_chunk& filter)
299+
{
300+
return set(ZMQ_SUBSCRIBE, filter);
301+
}
302+
303+
bool socket::set_unsubscription(const data_chunk& filter)
304+
{
305+
return set(ZMQ_UNSUBSCRIBE, filter);
306+
}
307+
291308
code socket::send(message& packet)
292309
{
293310
return packet.send(*this);

0 commit comments

Comments
 (0)