Skip to main content

Nodes and discovery

Python and C++ provide node helpers for long-running components plus Zeroconf discovery for finding services on a local network. They are optional layers over the core transport APIs.

Node helpers​

NodeWrapsTypical use
BaseNodeA managed processing loopPeriodic or custom background work
SourceNodeA StreamWriterSensors and publishers
SinkNodeA StreamReaderConsumers and recorders
ProcessNodeReader + writerFilters and transformation pipelines
ServerNodeAn RpcResponderConcurrent command/query services

Nodes provide a lifecycle around setup, processing, pause/resume, cleanup, and termination. Use the raw transport classes when you already have an application runtime; use nodes when MAGPIE should own the worker loop.

import time
from luxai.magpie.nodes import BaseNode

class HeartbeatNode(BaseNode):
def setup(self, interval):
self.interval = interval

def process(self):
print("alive")
time.sleep(self.interval)

node = HeartbeatNode(name="heartbeat", setup_kwargs={"interval": 1})
try:
time.sleep(10)
finally:
node.terminate()

Zeroconf discovery​

Discovery advertises a node ID, port, and small JSON-compatible payload through mDNS/Zeroconf. It is suited to local networks where hard-coded IP addresses are undesirable.

from luxai.magpie.discovery import ZconfDiscovery

# Service process
with ZconfDiscovery() as discovery:
discovery.advertise_node(
"camera-service",
port=5555,
payload={"role": "camera", "transport": "zmq"},
)
input("Advertising; press Enter to stop\n")
from luxai.magpie.discovery import ZconfDiscovery

# Client process
with ZconfDiscovery() as discovery:
info = discovery.resolve_node("camera-service", timeout=5)
if info:
host = discovery.pick_best_ip(info)
print(f"tcp://{host}:{info.port}")

Boundaries​

Zeroconf is local discovery, not identity or authorization. Do not trust an advertised payload simply because it appeared on the network. Authenticate the transport or application protocol before performing privileged operations.

For brokered deployments, a retained MQTT presence topic may be a better registry. For internet deployments, use your platform’s service discovery or configuration layer.