How to use the broker.TOPICS function in broker

To help you get started, we’ve selected a few broker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / WAFBench / ftw_compatible_tool / traffic.py View on Github external
def __init__(self, start_pattern, end_pattern, topic, ctx):
        super(_RawPacketCollector, self).__init__(start_pattern, end_pattern)
        self._topic = topic
        self._ctx = ctx
        self._ctx.broker.subscribe(broker.TOPICS.PYWB_OUTPUT, self)
        self._ctx.broker.subscribe(broker.TOPICS.RESET, self._reset)
github microsoft / WAFBench / ftw_compatible_tool / traffic.py View on Github external
def __init__(self, start_pattern, end_pattern, topic, ctx):
        super(_RawPacketCollector, self).__init__(start_pattern, end_pattern)
        self._topic = topic
        self._ctx = ctx
        self._ctx.broker.subscribe(broker.TOPICS.PYWB_OUTPUT, self)
        self._ctx.broker.subscribe(broker.TOPICS.RESET, self._reset)
github microsoft / WAFBench / ftw_compatible_tool / base.py View on Github external
And subscribe itself for COMMAND and FATAL.
        """
        self._ctx = ctx
        self._conf = conf

        functions = {
            "load": self._load_yaml_tests,
            "gen": self._gen_requests,
            "start": self._start_experiment,
            "import": self._import_log,
            "report": self._report_experiment,
            "exit": self._exit,
        }
        functions.update(self._conf.functions)
        self._conf.functions = functions
        self._ctx.broker.subscribe(broker.TOPICS.COMMAND, self._command)
        self._ctx.broker.subscribe(broker.TOPICS.FATAL,
                                   self._notification_processor)
github microsoft / WAFBench / ftw_compatible_tool / traffic.py View on Github external
def __init__(self, ctx):
        super(RawResponseCollector, self).__init__(
            RESPONSE_PATTERN, r"(%s)|(%s)|(%s)" %
            (RESPONSE_PATTERN, REQUEST_PATTERN, FINISH_PATTERN),
            broker.TOPICS.RAW_RESPONSE, ctx)
github microsoft / WAFBench / ftw_compatible_tool / log.py View on Github external
def __init__(self, ctx):
        """ Create a LogCollector object.
            Initialize SwitchCollector with delimiter log.
            Subscribe itself to RAW_LOG and RESET.
        """
        self._ctx = ctx
        self._unique_id_pattern = re.compile(
            r'\[unique_id "([^\]]+)"\]'
        )
        super(LogCollector, self).__init__(
            self._ctx.delimiter.get_delimiter_log(),
            self._ctx.delimiter.get_delimiter_log(), 
            save_entire_line = True)
        self._reset()

        self._ctx.broker.subscribe(broker.TOPICS.RAW_LOG, self)
        self._ctx.broker.subscribe(broker.TOPICS.RESET, self._reset)
github microsoft / WAFBench / ftw_compatible_tool / traffic.py View on Github external
def _publish(self):
        elapse_time = None
        if self._request_time and self._response_time:
            elapse_time = self._response_time - self._request_time
        self._ctx.broker.publish(
            broker.TOPICS.SQL_COMMAND,
            sql.SQL_INSERT_RAW_TRAFFIC,
            self._request_buffer,
            self._response_buffer,
            elapse_time,
            self._current_key,
        )
        self._ctx.broker.publish(
            broker.TOPICS.RAW_TRAFFIC,
            self._current_key,
            self._request_buffer,
            self._response_buffer,
        )
github microsoft / WAFBench / ftw_compatible_tool / traffic.py View on Github external
- raw_resonse: A string which is a single response.
        """
        if self._current_key is None:
            if self._state == collector.COLLECT_STATE.START_COLLECT:
                self._state = collector.COLLECT_STATE.FINISH_COLLECT
        # key was set
        elif self._state == collector.COLLECT_STATE.FINISH_COLLECT:
            self._state = collector.COLLECT_STATE.START_COLLECT
        elif self._state == collector.COLLECT_STATE.START_COLLECT:
            if self._request_buffer:
                if not self._response_time:
                    self._response_time = time.time()
                self._response_buffer += raw_response

        else:
            self._ctx.broker.publish(broker.TOPICS.ERROR,
                                     "Internal state error")
            return