def record(self, msg: Message, force_record_meta=False, notify_agents=True): record_meta = False if msg.action == ACTION_RECEIVED: key = msg.key meta = self.meta_table() if key in meta.db: del meta.db[key] elif msg.action == ACTION_WRITE: self.write(msg.path, msg.key, msg.value) if msg.dest == DEST_LOCAL: record_meta = False elif msg.dest == DEST_NODE: record_meta = not (msg.dest_node == self.node_id) elif msg.dest == DEST_PARENT: record_meta = False elif msg.dest == DEST_CHILD: record_meta = False elif msg.dest == DEST_NEIGHBORS: record_meta = False else: record_meta = True elif msg.action == ACTION_REQUEST: record_meta = True try: # If we have the requested data, create a response message with that data key, val = self.latest(msg.path) msg.key = key msg.value = val msg.action = ACTION_RESPONSE except ValueError: # Otherwise just store the message to forward it to other nodes pass elif msg.action == ACTION_RESPONSE: if (msg.dest == DEST_NODE and msg.dest_node == self.node_id) or \ (msg.dest == DEST_UPLINK and self.is_uplink): self.write(msg.path, msg.key, msg.value) if record_meta or force_record_meta: self._record_meta(msg) if notify_agents: self.notify_agents(msg)