def on_receive(self, message): self.logger.debug("Got message: %s" % (message,)) assert "headers" in message assert len(message["headers"]) > 0 assert "ttl" in message["headers"][-1] # it should be properly wrapped, so check ttl. # some defaults here? last_ttl = message["headers"][-1]["ttl"] if last_ttl < 1: self.logger.warning("TTL Drop: message loop") return # walk through our registered interests and see if anyone # wants it. for ref, asts in self.interests.iteritems(): sent_message = False if self.config.get("hairpin", False) is False: # we want to not consider same ref inmod = message["headers"][-1]["source"] if ref == self.name_to_ref.get(inmod, None): continue if ref == self.name_to_ref.get("%s-reverse" % inmod, None): continue for ast in asts: if ast.eval_node(message) is True: # we don't want to send the same message twice to # the same plugin. if sent_message is False: ref.tell(message) sent_message = True
def _eval(self, node, expression, ns=None): ast = reactor.ast.FilterBuilder(reactor.ast.FilterTokenizer(), input_expression=expression, ns=ns) return ast.eval_node(node)