Exemplo n.º 1
0
    def _on_pull_intercept(self, epid, buf, n_bytes):
        opid = 1 - epid
        splitter = self._splitters[epid]
        handler = self._handler

        # steal data
        if n_bytes > 0:
            splitter.append(buf.last(n_bytes))
            buf._end -= n_bytes

        # decode and forward data
        while True:
            segment = splitter.pull_segment()
            if segment is None:
                break

            decoded = decoder.decode_packet(*segment)
            action = handler.on_packet(epid, decoded)

            if action == INTERCEPT_REJECT:
                # nothing to do in this case
                pass
            elif action == INTERCEPT_ACCEPT:
                offset = decoder.encode_packet(decoded, self._encode_buf)

                # forward packet (hopefully everything fits into the buffer)
                buf.append(self._encode_buf[:offset])
Exemplo n.º 2
0
    def _on_pull_intercept(self, epid, buf, n_bytes):
        opid = 1 - epid
        splitter = self._splitters[epid]
        handler = self._handler

        # steal data
        if n_bytes > 0:
            splitter.append(buf.last(n_bytes))
            buf._end -= n_bytes

        # decode and forward data
        while True:
            segment = splitter.pull_segment()
            if segment is None:
                break

            decoded = decoder.decode_packet(*segment)
            action = handler.on_packet(epid, decoded)

            if action == INTERCEPT_REJECT:
                # nothing to do in this case
                pass
            elif action == INTERCEPT_ACCEPT:
                offset = decoder.encode_packet(decoded, self._encode_buf)

                # forward packet (hopefully everything fits into the buffer)
                buf.append(self._encode_buf[:offset])
Exemplo n.º 3
0
    def _on_pull_lurking(self, epid, buf, n_bytes):
        opid = 1 - epid
        splitter = self._splitters[epid]

        if splitter.free < n_bytes:
            print('WARNING: not enough buffer space, going into passive mode')
            self._mode = MODE_PASSIVE
            return

        # Check if we have a full segment
        splitter.append(buf.last(n_bytes))
        segment = splitter.pull_segment()
        if segment is None:
            return

        # Calculate how much of the n_bytes don't belong to the first segment
        remaining = splitter.used
        assert remaining < n_bytes, "We missed the pull that completed the first segment!"

        # Clear splitter
        splitter.clear()

        try:
            decoded = decoder.decode_packet(*segment)
            print('Decoded first packet, is of type {0!r}'.format(
                decoded.__class__))

            if isinstance(decoded, mtypes.AuroraHandshake):
                print(
                    'Is an aurora handshake - going into full intercept mode.')
                self._mode = MODE_INTERCEPT
                self._handler.on_start_intercept(decoded)
                self._on_pull_intercept(epid, buf, remaining)
            else:
                print(
                    'WARNING: first packet was not aurora handshake - going into passive mode'
                )
                self._mode = MODE_PASSIVE
        except Exception as e:
            print('WARNING: Got exception {0!r} while trying to decode packet'.
                  format(e))
            self._mode = MODE_PASSIVE
Exemplo n.º 4
0
    def _on_pull_lurking(self, epid, buf, n_bytes):
        opid = 1 - epid
        splitter = self._splitters[epid]

        if splitter.free < n_bytes:
            print("WARNING: not enough buffer space, going into passive mode")
            self._mode = MODE_PASSIVE
            return

        # Check if we have a full segment
        splitter.append(buf.last(n_bytes))
        segment = splitter.pull_segment()
        if segment is None:
            return

        # Calculate how much of the n_bytes don't belong to the first segment
        remaining = splitter.used
        assert remaining < n_bytes, "We missed the pull that completed the first segment!"

        # Clear splitter
        splitter.clear()

        try:
            decoded = decoder.decode_packet(*segment)
            print("Decoded first packet, is of type {0!r}".format(decoded.__class__))

            if isinstance(decoded, mtypes.AuroraHandshake):
                print("Is an aurora handshake - going into full intercept mode.")
                self._mode = MODE_INTERCEPT
                self._handler.on_start_intercept(decoded)
                self._on_pull_intercept(epid, buf, remaining)
            else:
                print("WARNING: first packet was not aurora handshake - going into passive mode")
                self._mode = MODE_PASSIVE
        except Exception as e:
            print("WARNING: Got exception {0!r} while trying to decode packet".format(e))
            self._mode = MODE_PASSIVE
Exemplo n.º 5
0
 def feed(self, who, buf):
     for atype, abuf in self._s[who].feed(buf):
         decoded = decode_packet(atype, abuf)
         self._t.process(who, decoded)
Exemplo n.º 6
0
 def feed(self, who, buf):
     for atype, abuf in self._s[who].feed(buf):
         decoded = decode_packet(atype, abuf)
         self._t.process(who, decoded)
Exemplo n.º 7
0
 def feed(self, who, buf):
     for atype, abuf in self._s[who].feed(buf):
         decoded = decode_packet(atype, abuf)
         yield decoded
Exemplo n.º 8
0
Arquivo: common.py Projeto: 6f/Hearthy
 def feed(self, who, buf):
     for atype, abuf in self._s[who].feed(buf):
         decoded = decode_packet(atype, abuf)
         yield decoded