1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/lib/nodes/zeromq.cpp

666 lines
15 KiB
C++
Raw Permalink Normal View History

/** Node type: ZeroMQ
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2020-01-20 17:17:00 +01:00
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#include <cstring>
#include <zmq.h>
2017-06-29 21:10:33 +02:00
#if ZMQ_VERSION_MAJOR < 4 || (ZMQ_VERSION_MAJOR == 4 && ZMQ_VERSION_MINOR <= 1)
#include <zmq_utils.h>
#endif
2017-12-09 02:19:28 +08:00
#include <villas/node.h>
2021-06-21 16:11:42 -04:00
#include <villas/nodes/zeromq.hpp>
2021-05-10 00:12:30 +02:00
#include <villas/super_node.hpp>
#include <villas/utils.hpp>
2017-12-09 02:19:28 +08:00
#include <villas/queue.h>
#include <villas/exceptions.hpp>
using namespace villas;
2021-05-10 00:12:30 +02:00
using namespace villas::node;
2019-06-04 16:55:38 +02:00
using namespace villas::utils;
static void *context;
2017-05-23 09:20:57 +02:00
/** Read one event off the monitor socket; return value and address
* by reference, if not null, and event number by value.
*
* @returnval -1 In case of error. */
static int get_monitor_event(void *monitor, int *value, char **address)
{
/* First frame in message contains event number and value */
zmq_msg_t msg;
zmq_msg_init (&msg);
if (zmq_msg_recv (&msg, monitor, 0) == -1)
return -1; /* Interruped, presumably. */
2017-05-23 11:13:41 +02:00
assert(zmq_msg_more (&msg));
2017-05-23 09:20:57 +02:00
2017-05-23 11:13:41 +02:00
uint8_t *data = (uint8_t *) zmq_msg_data(&msg);
2017-05-23 09:20:57 +02:00
uint16_t event = *(uint16_t *) (data);
if (value)
*value = *(uint32_t *) (data + 2);
/* Second frame in message contains event address */
2017-05-23 11:13:41 +02:00
zmq_msg_init(&msg);
if (zmq_msg_recv(&msg, monitor, 0) == -1)
2017-05-23 09:20:57 +02:00
return -1; /* Interruped, presumably. */
2017-05-23 11:13:41 +02:00
assert(!zmq_msg_more(&msg));
2017-05-23 09:20:57 +02:00
if (address) {
2017-05-23 11:13:41 +02:00
uint8_t *data = (uint8_t *) zmq_msg_data(&msg);
size_t size = zmq_msg_size(&msg);
*address = (char *) malloc(size + 1);
memcpy(*address, data, size);
2017-05-23 09:20:57 +02:00
*address [size] = 0;
}
return event;
}
2020-08-25 21:00:52 +02:00
int zeromq_reverse(struct vnode *n)
{
2017-10-18 15:39:53 +02:00
struct zeromq *z = (struct zeromq *) n->_vd;
2017-07-24 19:33:35 +02:00
if (vlist_length(&z->out.endpoints) != 1 ||
vlist_length(&z->in.endpoints) != 1)
2017-05-23 09:33:28 +02:00
return -1;
2017-07-24 19:33:35 +02:00
char *subscriber = (char *) vlist_first(&z->in.endpoints);
char *publisher = (char *) vlist_first(&z->out.endpoints);
2017-07-24 19:33:35 +02:00
vlist_set(&z->in.endpoints, 0, publisher);
2019-01-07 10:28:55 +01:00
vlist_set(&z->out.endpoints, 0, subscriber);
return 0;
}
2020-08-25 21:00:52 +02:00
int zeromq_init(struct vnode *n)
{
int ret;
struct zeromq *z = (struct zeromq *) n->_vd;
z->out.bind = 1;
z->in.bind = 0;
z->curve.enabled = false;
z->ipv6 = 0;
z->in.pending = 0;
z->out.pending = 0;
ret = vlist_init(&z->in.endpoints);
if (ret)
return ret;
ret = vlist_init(&z->out.endpoints);
if (ret)
return ret;
return 0;
}
int zeromq_parse_endpoints(json_t *json_ep, struct vlist *epl)
{
json_t *json_val;
size_t i;
const char *ep;
switch (json_typeof(json_ep)) {
case JSON_ARRAY:
json_array_foreach(json_ep, i, json_val) {
ep = json_string_value(json_val);
if (!ep)
2021-02-16 14:15:14 +01:00
throw ConfigError(json_val, "node-config-node-publish", "All 'publish' settings must be strings");
vlist_push(epl, strdup(ep));
}
break;
case JSON_STRING:
ep = json_string_value(json_ep);
vlist_push(epl, strdup(ep));
break;
default:
return -1;
}
return 0;
}
2021-02-16 14:15:14 +01:00
int zeromq_parse(struct vnode *n, json_t *json)
{
2017-10-18 15:39:53 +02:00
struct zeromq *z = (struct zeromq *) n->_vd;
2017-07-24 19:33:35 +02:00
int ret;
2019-04-22 23:45:38 +02:00
const char *type = nullptr;
const char *in_filter = nullptr;
const char *out_filter = nullptr;
2017-07-24 19:33:35 +02:00
2021-05-10 00:12:30 +02:00
json_error_t err;
json_t *json_in_ep = nullptr;
json_t *json_out_ep = nullptr;
2019-04-22 23:45:38 +02:00
json_t *json_curve = nullptr;
2021-05-10 00:12:30 +02:00
json_t *json_format = nullptr;
2017-07-24 19:33:35 +02:00
2021-05-10 00:12:30 +02:00
ret = json_unpack_ex(json, &err, 0, "{ s?: { s?: o, s?: s, s?: b }, s?: { s?: o, s?: s, s?: b }, s?: o, s?: s, s?: b, s?: o }",
"in",
"subscribe", &json_in_ep,
"filter", &in_filter,
"bind", &z->in.bind,
"out",
"publish", &json_out_ep,
"filter", &out_filter,
"bind", &z->out.bind,
2017-10-16 08:08:35 +02:00
"curve", &json_curve,
"pattern", &type,
"ipv6", &z->ipv6,
2021-05-10 00:12:30 +02:00
"format", &json_format
);
if (ret)
2021-02-16 14:15:14 +01:00
throw ConfigError(json, err, "node-config-node-zeromq");
2019-04-22 23:45:38 +02:00
z->in.filter = in_filter ? strdup(in_filter) : nullptr;
z->out.filter = out_filter ? strdup(out_filter) : nullptr;
2021-05-10 00:12:30 +02:00
/* Format */
z->formatter = json_format
? FormatFactory::make(json_format)
: FormatFactory::make("villas.binary");
if (!z->formatter)
throw ConfigError(json_format, "node-config-node-zeromq-format", "Invalid format configuration");
2017-07-24 19:33:35 +02:00
if (json_out_ep) {
ret = zeromq_parse_endpoints(json_out_ep, &z->out.endpoints);
if (ret)
throw ConfigError(json_out_ep, "node-config-node-zeromq-publish", "Failed to parse list of publish endpoints");
}
if (json_in_ep) {
ret = zeromq_parse_endpoints(json_in_ep, &z->in.endpoints);
if (ret)
throw ConfigError(json_out_ep, "node-config-node-zeromq-subscribe", "Failed to parse list of subscribe endpoints");
}
2017-07-24 19:33:35 +02:00
2017-10-16 08:08:35 +02:00
if (json_curve) {
const char *public_key, *secret_key;
2017-07-24 19:33:35 +02:00
z->curve.enabled = true;
2017-10-16 08:08:35 +02:00
ret = json_unpack_ex(json_curve, &err, 0, "{ s: s, s: s, s?: b }",
"public_key", &public_key,
"secret_key", &secret_key,
"enabled", &z->curve.enabled
);
if (ret)
2021-02-16 14:15:14 +01:00
throw ConfigError(json_curve, err, "node-config-node-zeromq-curve", "Failed to parse setting 'curve'");
if (strlen(secret_key) != 40)
2021-02-16 14:15:14 +01:00
throw ConfigError(json_curve, err, "node-config-node-zeromq-curve", "Setting 'curve.secret_key' must be a Z85 encoded CurveZMQ key");
if (strlen(public_key) != 40)
2021-02-16 14:15:14 +01:00
throw ConfigError(json_curve, err, "node-config-node-zeromq-curve", "Setting 'curve.public_key' must be a Z85 encoded CurveZMQ key");
2018-04-04 08:53:00 +02:00
memcpy(z->curve.server.public_key, public_key, 41);
memcpy(z->curve.server.secret_key, secret_key, 41);
}
2017-07-24 19:33:35 +02:00
/** @todo We should fix this. Its mostly done. */
if (z->curve.enabled)
2021-02-16 14:15:14 +01:00
throw ConfigError(json_curve, "node-config-zeromq-curve", "CurveZMQ support is currently broken");
2017-07-24 19:33:35 +02:00
if (type) {
if (!strcmp(type, "pubsub"))
2019-06-23 16:13:23 +02:00
z->pattern = zeromq::Pattern::PUBSUB;
2017-06-15 13:59:09 +02:00
#ifdef ZMQ_BUILD_DISH
else if (!strcmp(type, "radiodish"))
2019-06-23 16:13:23 +02:00
z->pattern = zeromq::Pattern::RADIODISH;
2017-06-15 13:59:09 +02:00
#endif
else
2021-02-16 14:15:14 +01:00
throw ConfigError(json, "node-config-node-zeromq-type", "Invalid type for ZeroMQ node: {}", node_name_short(n));
}
2017-07-24 19:33:35 +02:00
return 0;
}
2020-08-25 21:00:52 +02:00
char * zeromq_print(struct vnode *n)
{
2017-10-18 15:39:53 +02:00
struct zeromq *z = (struct zeromq *) n->_vd;
2019-04-22 23:45:38 +02:00
char *buf = nullptr;
const char *pattern = nullptr;
switch (z->pattern) {
2019-06-23 16:13:23 +02:00
case zeromq::Pattern::PUBSUB:
2019-04-22 23:43:46 +02:00
pattern = "pubsub";
break;
2017-06-15 13:59:09 +02:00
#ifdef ZMQ_BUILD_DISH
2019-06-23 16:13:23 +02:00
case zeromq::Pattern::RADIODISH:
2019-04-22 23:43:46 +02:00
pattern = "radiodish";
break;
2017-06-15 13:59:09 +02:00
#endif
}
2017-07-24 19:33:35 +02:00
2021-05-10 00:12:30 +02:00
strcatf(&buf, "pattern=%s, ipv6=%s, crypto=%s, in.bind=%s, out.bind=%s, in.subscribe=[ ",
pattern,
z->ipv6 ? "yes" : "no",
z->curve.enabled ? "yes" : "no",
z->in.bind ? "yes" : "no",
z->out.bind ? "yes" : "no"
);
2017-07-24 19:33:35 +02:00
for (size_t i = 0; i < vlist_length(&z->in.endpoints); i++) {
char *ep = (char *) vlist_at(&z->in.endpoints, i);
strcatf(&buf, "%s ", ep);
}
strcatf(&buf, "], out.publish=[ ");
2019-01-07 10:28:55 +01:00
for (size_t i = 0; i < vlist_length(&z->out.endpoints); i++) {
char *ep = (char *) vlist_at(&z->out.endpoints, i);
2017-07-24 19:33:35 +02:00
strcatf(&buf, "%s ", ep);
}
strcatf(&buf, "]");
2017-07-24 19:33:35 +02:00
if (z->in.filter)
strcatf(&buf, ", in.filter=%s", z->in.filter);
if (z->out.filter)
strcatf(&buf, ", out.filter=%s", z->out.filter);
return buf;
}
2020-08-25 21:00:52 +02:00
int zeromq_check(struct vnode *n)
{
struct zeromq *z = (struct zeromq *) n->_vd;
if (vlist_length(&z->in.endpoints) == 0 &&
vlist_length(&z->out.endpoints) == 0)
return -1;
return 0;
}
2019-04-23 13:14:47 +02:00
int zeromq_type_start(villas::node::SuperNode *sn)
{
context = zmq_ctx_new();
2019-04-22 23:45:38 +02:00
return context == nullptr;
}
int zeromq_type_stop()
{
return zmq_ctx_term(context);
}
2020-08-25 21:00:52 +02:00
int zeromq_start(struct vnode *n)
{
int ret;
2017-10-18 15:39:53 +02:00
struct zeromq *z = (struct zeromq *) n->_vd;
2017-07-24 19:33:35 +02:00
struct zeromq::Dir* dirs[] = { &z->out, &z->in };
2021-05-10 00:12:30 +02:00
z->formatter->start(&n->in.signals, ~(int) SampleFlags::HAS_OFFSET);
switch (z->pattern) {
2017-06-15 13:59:09 +02:00
#ifdef ZMQ_BUILD_DISH
2019-06-23 16:13:23 +02:00
case zeromq::Pattern::RADIODISH:
z->in.socket = zmq_socket(context, ZMQ_DISH);
z->out.socket = zmq_socket(context, ZMQ_RADIO);
break;
2017-06-15 13:59:09 +02:00
#endif
2017-07-24 19:33:35 +02:00
2019-06-23 16:13:23 +02:00
case zeromq::Pattern::PUBSUB:
z->in.socket = zmq_socket(context, ZMQ_SUB);
z->out.socket = zmq_socket(context, ZMQ_PUB);
break;
}
2017-07-24 19:33:35 +02:00
if (!z->in.socket || !z->out.socket) {
2017-05-23 11:13:41 +02:00
ret = -1;
goto fail;
}
2017-07-24 19:33:35 +02:00
2017-05-23 11:15:00 +02:00
/* Join group */
switch (z->pattern) {
2017-06-15 13:59:09 +02:00
#ifdef ZMQ_BUILD_DISH
2019-06-23 16:13:23 +02:00
case zeromq::Pattern::RADIODISH:
ret = zmq_join(z->in.socket, z->in.filter);
2017-05-23 11:15:00 +02:00
break;
2017-06-15 13:59:09 +02:00
#endif
2017-07-24 19:33:35 +02:00
2019-06-23 16:13:23 +02:00
case zeromq::Pattern::PUBSUB:
ret = zmq_setsockopt(z->in.socket, ZMQ_SUBSCRIBE, z->in.filter, z->in.filter ? strlen(z->in.filter) : 0);
2017-05-23 11:15:00 +02:00
break;
2017-07-24 19:33:35 +02:00
2017-05-23 15:03:39 +02:00
default:
ret = -1;
2017-05-23 11:15:00 +02:00
}
2017-07-24 19:33:35 +02:00
2017-05-23 11:15:00 +02:00
if (ret < 0)
goto fail;
2017-07-24 19:33:35 +02:00
if (z->curve.enabled) {
/* Publisher has server role */
ret = zmq_setsockopt(z->out.socket, ZMQ_CURVE_SECRETKEY, z->curve.server.secret_key, 41);
if (ret)
2017-05-23 11:13:41 +02:00
goto fail;
2017-07-24 19:33:35 +02:00
ret = zmq_setsockopt(z->out.socket, ZMQ_CURVE_PUBLICKEY, z->curve.server.public_key, 41);
if (ret)
2017-05-23 11:13:41 +02:00
goto fail;
2017-07-24 19:33:35 +02:00
int curve_server = 1;
ret = zmq_setsockopt(z->out.socket, ZMQ_CURVE_SERVER, &curve_server, sizeof(curve_server));
if (ret)
2017-05-23 11:13:41 +02:00
goto fail;
2017-07-24 19:33:35 +02:00
/* Create temporary client keys first */
ret = zmq_curve_keypair(z->curve.client.public_key, z->curve.client.secret_key);
if (ret)
2017-05-23 11:13:41 +02:00
goto fail;
/* Subscriber has client role */
ret = zmq_setsockopt(z->in.socket, ZMQ_CURVE_SECRETKEY, z->curve.client.secret_key, 41);
if (ret)
2017-05-23 11:13:41 +02:00
goto fail;
ret = zmq_setsockopt(z->in.socket, ZMQ_CURVE_PUBLICKEY, z->curve.client.public_key, 41);
if (ret)
2017-05-23 11:13:41 +02:00
goto fail;
ret = zmq_setsockopt(z->in.socket, ZMQ_CURVE_SERVERKEY, z->curve.server.public_key, 41);
if (ret)
2017-05-23 11:13:41 +02:00
goto fail;
}
2017-07-24 19:33:35 +02:00
for (auto d : dirs) {
const char *mon_ep = d == &z->in ? "inproc://monitor-in" : "inproc://monitor-out";
2017-05-23 09:20:57 +02:00
ret = zmq_setsockopt(d->socket, ZMQ_IPV6, &z->ipv6, sizeof(z->ipv6));
if (ret)
goto fail;
2017-05-23 09:20:57 +02:00
int linger = 1000;
ret = zmq_setsockopt(d->socket, ZMQ_LINGER, &linger, sizeof(linger));
if (ret)
goto fail;
2017-05-23 09:20:57 +02:00
/* Monitor events on the server */
ret = zmq_socket_monitor(d->socket, mon_ep, ZMQ_EVENT_ALL);
if (ret < 0)
goto fail;
2017-07-24 19:33:35 +02:00
/* Create socket for collecting monitor events */
d->mon_socket = zmq_socket(context, ZMQ_PAIR);
if (!d->mon_socket) {
ret = -1;
goto fail;
}
/* Connect it to the inproc endpoints so they'll get events */
ret = zmq_connect(d->mon_socket, mon_ep);
if (ret < 0)
2017-05-23 11:13:41 +02:00
goto fail;
/* Connect / bind sockets to endpoints */
for (size_t i = 0; i < vlist_length(&d->endpoints); i++) {
char *ep = (char *) vlist_at(&d->endpoints, i);
if (d->bind) {
ret = zmq_bind(d->socket, ep);
if (ret < 0)
goto fail;
}
else {
ret = zmq_connect(d->socket, ep);
if (ret < 0)
goto fail;
}
d->pending++;
}
}
2017-07-24 19:33:35 +02:00
/* Wait for all connections to be connected */
for (auto d : dirs) {
while (d->pending > 0) {
int evt = d->bind ? ZMQ_EVENT_LISTENING : ZMQ_EVENT_CONNECTED;
ret = get_monitor_event(d->mon_socket, nullptr, nullptr);
if (ret == evt)
d->pending--;
}
}
2018-10-20 17:35:01 +02:00
#if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_MAJOR_VERSION >= 4 && ZMQ_MINOR_VERSION >= 2 && ZMQ_MINOR_VERSION >= 3
if (z->curve.enabled) {
2019-04-22 23:45:38 +02:00
ret = get_monitor_event(z->in.mon_socket, nullptr, nullptr);
return ret == ZMQ_EVENT_HANDSHAKE_SUCCEEDED;
}
else
return 0; /* The handshake events are only emitted for CurveZMQ sessions. */
2017-05-23 09:20:57 +02:00
#else
return 0;
2017-05-23 09:20:57 +02:00
#endif
2017-07-24 19:33:35 +02:00
2017-05-23 11:13:41 +02:00
fail:
2021-02-16 14:15:14 +01:00
n->logger->info("Failed to start: {}", zmq_strerror(errno));
2017-07-24 19:33:35 +02:00
2017-05-23 11:13:41 +02:00
return ret;
}
2020-08-25 21:00:52 +02:00
int zeromq_stop(struct vnode *n)
{
int ret;
2017-10-18 15:39:53 +02:00
struct zeromq *z = (struct zeromq *) n->_vd;
2017-07-24 19:33:35 +02:00
struct zeromq::Dir* dirs[] = { &z->out, &z->in };
2017-07-24 19:33:35 +02:00
for (auto d : dirs) {
ret = zmq_close(d->socket);
if (ret)
return ret;
ret = zmq_close(d->mon_socket);
if (ret)
return ret;
}
2021-05-10 00:12:30 +02:00
delete z->formatter;
return 0;
}
2020-08-25 21:00:52 +02:00
int zeromq_destroy(struct vnode *n)
2018-05-12 15:25:29 +02:00
{
int ret;
struct zeromq *z = (struct zeromq *) n->_vd;
if (z->in.filter)
free(z->in.filter);
if (z->out.filter)
free(z->out.filter);
2019-04-22 23:45:38 +02:00
ret = vlist_destroy(&z->out.endpoints, nullptr, true);
2018-05-12 15:25:29 +02:00
if (ret)
return ret;
return 0;
}
2021-05-10 00:12:30 +02:00
int zeromq_read(struct vnode *n, struct sample * const smps[], unsigned cnt)
{
int recv, ret;
2017-10-18 15:39:53 +02:00
struct zeromq *z = (struct zeromq *) n->_vd;
zmq_msg_t m;
2017-07-24 19:33:35 +02:00
ret = zmq_msg_init(&m);
if (ret < 0)
return ret;
2017-07-24 19:33:35 +02:00
if (z->in.filter) {
2017-05-23 11:15:00 +02:00
switch (z->pattern) {
2019-06-23 16:13:23 +02:00
case zeromq::Pattern::PUBSUB:
2017-05-23 11:15:00 +02:00
/* Discard envelope */
2019-04-22 23:45:38 +02:00
zmq_recv(z->in.socket, nullptr, 0, 0);
2017-05-23 11:15:00 +02:00
break;
2017-07-24 19:33:35 +02:00
2017-05-23 11:15:00 +02:00
default: { }
}
}
2017-07-24 19:33:35 +02:00
2017-05-23 11:15:00 +02:00
/* Receive payload */
ret = zmq_msg_recv(&m, z->in.socket, 0);
if (ret < 0)
return ret;
2021-05-10 00:12:30 +02:00
recv = z->formatter->sscan((const char *) zmq_msg_data(&m), zmq_msg_size(&m), nullptr, smps, cnt);
2017-07-24 19:33:35 +02:00
ret = zmq_msg_close(&m);
if (ret)
return ret;
2017-07-24 19:33:35 +02:00
return recv;
}
2021-05-10 00:12:30 +02:00
int zeromq_write(struct vnode *n, struct sample * const smps[], unsigned cnt)
{
int ret;
2017-10-18 15:39:53 +02:00
struct zeromq *z = (struct zeromq *) n->_vd;
2017-07-24 19:33:35 +02:00
size_t wbytes;
zmq_msg_t m;
2017-07-24 19:33:35 +02:00
2017-08-23 15:48:34 +02:00
char data[4096];
2021-05-10 00:12:30 +02:00
ret = z->formatter->sprint(data, sizeof(data), &wbytes, smps, cnt);
if (ret <= 0)
return -1;
ret = zmq_msg_init_size(&m, wbytes);
2017-07-24 19:33:35 +02:00
if (z->out.filter) {
2017-05-23 11:15:00 +02:00
switch (z->pattern) {
2017-06-15 13:59:09 +02:00
#ifdef ZMQ_BUILD_DISH
2019-06-23 16:13:23 +02:00
case zeromq::Pattern::RADIODISH:
ret = zmq_msg_set_group(&m, z->out.filter);
2017-05-23 11:15:00 +02:00
if (ret < 0)
goto fail;
break;
2017-06-15 13:59:09 +02:00
#endif
2017-07-24 19:33:35 +02:00
2019-06-23 16:13:23 +02:00
case zeromq::Pattern::PUBSUB: /* Send envelope */
zmq_send(z->out.socket, z->out.filter, strlen(z->out.filter), ZMQ_SNDMORE);
2017-05-23 11:15:00 +02:00
break;
}
}
2017-07-24 19:33:35 +02:00
memcpy(zmq_msg_data(&m), data, wbytes);
ret = zmq_msg_send(&m, z->out.socket, 0);
if (ret < 0)
goto fail;
2017-07-24 19:33:35 +02:00
ret = zmq_msg_close(&m);
if (ret < 0)
return ret;
return cnt;
fail:
zmq_msg_close(&m);
return ret;
}
2020-08-25 21:00:52 +02:00
int zeromq_poll_fds(struct vnode *n, int fds[])
{
int ret;
2017-10-18 15:39:53 +02:00
struct zeromq *z = (struct zeromq *) n->_vd;
int fd;
size_t len = sizeof(fd);
ret = zmq_getsockopt(z->in.socket, ZMQ_FD, &fd, &len);
if (ret)
return ret;
fds[0] = fd;
return 1;
}
2020-08-25 21:00:52 +02:00
int zeromq_netem_fds(struct vnode *n, int fds[])
{
int ret;
struct zeromq *z = (struct zeromq *) n->_vd;
int fd;
size_t len = sizeof(fd);
ret = zmq_getsockopt(z->out.socket, ZMQ_FD, &fd, &len);
if (ret)
return ret;
fds[0] = fd;
return 1;
}
2021-06-21 16:11:42 -04:00
static struct vnode_type p;
__attribute__((constructor(110)))
static void register_plugin() {
2021-06-21 16:11:42 -04:00
p.name = "zeromq";
p.description = "ZeroMQ Distributed Messaging (libzmq)";
p.vectorize = 0;
p.size = sizeof(struct zeromq);
p.type.start = zeromq_type_start;
p.type.stop = zeromq_type_stop;
p.init = zeromq_init;
p.destroy = zeromq_destroy;
p.check = zeromq_check;
p.parse = zeromq_parse;
p.print = zeromq_print;
p.start = zeromq_start;
p.stop = zeromq_stop;
p.read = zeromq_read;
p.write = zeromq_write;
p.reverse = zeromq_reverse;
p.poll_fds = zeromq_poll_fds;
p.netem_fds = zeromq_netem_fds;
if (!node_types)
node_types = new NodeTypeList();
node_types->push_back(&p);
2019-04-23 13:14:47 +02:00
}