diff --git a/include/villas/node.h b/include/villas/node.h index e2bdafe33..ef3aece8c 100644 --- a/include/villas/node.h +++ b/include/villas/node.h @@ -34,6 +34,8 @@ struct node int vectorize; /**< Number of messages to send / recv at once (scatter / gather) */ int affinity; /**< CPU Affinity of this node */ + + int id; /**< An id of this node which is only unique in the scope of it's super-node (VILLASnode instance). */ unsigned long sequence; /**< This is a counter of received samples, in case the node-type does not generate sequence numbers itself. */ diff --git a/include/villas/nodes/websocket.h b/include/villas/nodes/websocket.h index 917c8284d..df8b7850f 100644 --- a/include/villas/nodes/websocket.h +++ b/include/villas/nodes/websocket.h @@ -33,7 +33,6 @@ struct websocket { struct pool pool; struct queue queue; /**< For samples which are received from WebSockets a */ - int id; /**< The index of this node */ }; /* Internal datastructures */ diff --git a/lib/apis/nodes.c b/lib/apis/nodes.c index 2487f8435..b65038d3a 100644 --- a/lib/apis/nodes.c +++ b/lib/apis/nodes.c @@ -26,7 +26,8 @@ static int api_nodes(struct api_ressource *r, json_t *args, json_t **resp, struc "name", node_name_short(n), "state", n->state, "vectorize", n->vectorize, - "affinity", n->affinity + "affinity", n->affinity, + "id", i ); /* Add all additional fields of node here. diff --git a/lib/node.c b/lib/node.c index 2cd76bdf5..24218e344 100644 --- a/lib/node.c +++ b/lib/node.c @@ -15,11 +15,15 @@ int node_init(struct node *n, struct node_type *vt) { + static int max_id; + assert(n->state == STATE_DESTROYED); n->_vt = vt; n->_vd = alloc(vt->size); + n->id = max_id++; + /* Default values */ n->vectorize = 1; diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c index e75c5423f..a19f60a26 100644 --- a/lib/nodes/websocket.c +++ b/lib/nodes/websocket.c @@ -22,8 +22,6 @@ #include "nodes/websocket.h" /* Private static storage */ -static int id = 0; /**< Highest assigned ID to websocket nodes. */ - struct list connections; /**< List of active libwebsocket connections which receive samples from all nodes (catch all) */ /* Forward declarations */ @@ -122,7 +120,7 @@ static int websocket_connection_write(struct websocket_connection *c, struct sam msg->endian = WEBMSG_ENDIAN_HOST; msg->length = smps[i]->length; msg->sequence = smps[i]->sequence; - msg->id = w->id; + msg->id = c->node->id; msg->ts.sec = smps[i]->ts.origin.tv_sec; msg->ts.nsec = smps[i]->ts.origin.tv_nsec; @@ -263,8 +261,6 @@ int websocket_start(struct node *n) int ret; struct websocket *w = n->_vd; - w->id = id++; - size_t blocklen = LWS_PRE + WEBMSG_LEN(DEFAULT_VALUES); ret = pool_init(&w->pool, 64 * DEFAULT_QUEUELEN, blocklen, &memtype_hugepage);