예제 #1
0
    def doRead(self):
        self.buff += os.read(self.rd_fd, 65536)

        while 1:
            (msg, self.buff) = DR2DPMessage1.recv_from_buffer(self.buff)
            if msg != None:
                self.handle_msg(msg)
            else:
                break
예제 #2
0
    def dataReceived(self, data):
        """
        Read data from Click DR and pass it to the Decoy Proxy.
        """

        self.buff += data
        while 1:
            (msg, self.buff) = DR2DPMessage1.recv_from_buffer(self.buff)
            if msg != None:
                self.handle_msg(msg)
            else:
                break
예제 #3
0
    def send_to_dr(self, pkt):
        """
        Forward the given pkt via the DR.

        If pkt isn't a str or buffer, things are going to behave oddly.
        """

        DEBUG and log_debug('SrcProtocol.send_to_dr')
        msg = DR2DPMessage1(DR2DPMessage1.MESSAGE_TYPE_REQUEST,
                            DR2DPMessage1.OP_TYPE_FORWARD_IP)

        self.transport.write(msg.pack(pkt))
예제 #4
0
    def dataReceived(self, new_data):
        self.recv_buffer += new_data

        # It's possible for more than one message to come in as part
        # of one read, at least in theory.  Therefore we consume as
        # much of the buffer as possible, not just the first message.
        while 1:
            (msg, self.recv_buffer) = DR2DPMessage1.recv_from_buffer(
                self.recv_buffer)
            if msg != None:
                self.handle_msg(msg)
            else:
                break
예제 #5
0
    def dataReceived(self, new_data):
        DEBUG and log_debug(
            'SrcProtocol.dataReceived(%d bytes)' % len(new_data))

        self.recv_buffer += new_data
        #print 'got something from DR!'
        # It's possible for more than one message to come in as part
        # of one read, at least in theory.  Therefore we consume as
        # much of the buffer as possible, not just the first message.
        #
        while 1:
            # print 'LEN %d' % len(self._recv_buffer)
            (msg, self.recv_buffer) = DR2DPMessage1.recv_from_buffer(
                self.recv_buffer)
            if msg != None:
                self.handle_msg(msg)
            else:
                break
예제 #6
0
 def upload_dh_blacklist(self):
     self.forward_message(
         DR2DPMessage1(DR2DPMessage1.MESSAGE_TYPE_REQUEST,
                       DR2DPMessage1.OP_TYPE_DH_BLACKLIST))
예제 #7
0
        def run(self):
            """
            Pause, then inject messages into self.sock
            """

            dummy_payload = '0123456789abcdefghijklmnopqrstuv' * (8 * 32)
            curr_data = ''

            target_MB_per_sec = 10 * 1024 * 1024.0
            min_sleep = 1.0  # minimum pause time

            time.sleep(1.0)

            print 'STARTING'
            while 1:

                # I'm intentionally cramming more than one message into a single
                # send in order to make sure that the correct thing happens when
                # a single recv captures more than one msg, and a single recv
                # might contain only a fraction of a message.

                curr_data += dummy_payload

                print "curr_data len %d" % len(curr_data)

                msgs = []

                msgs.append(
                    DR2DPMessage1(DR2DPMessage1.MESSAGE_TYPE_REQUEST,
                                  DR2DPMessage1.OP_TYPE_PING).pack(curr_data))
                msgs.append(
                    DR2DPMessage1(DR2DPMessage1.MESSAGE_TYPE_REQUEST,
                                  DR2DPMessage1.OP_TYPE_PING).pack(curr_data))
                msgs.append(
                    DR2DPMessage1(DR2DPMessage1.MESSAGE_TYPE_REQUEST,
                                  DR2DPMessage1.OP_TYPE_PING).pack(curr_data))
                msgs.append(
                    DR2DPMessage1(DR2DPMessage1.MESSAGE_TYPE_REQUEST,
                                  DR2DPMessage1.OP_TYPE_PING).pack(curr_data))

                packed_bytes = ''.join(msgs)
                len_packed_bytes = len(packed_bytes)

                third = len_packed_bytes / 3
                print third

                first_part = packed_bytes[:third]
                second_part = packed_bytes[third:2 * third]
                last_part = packed_bytes[2 * third:]

                self.sock.transport.write(first_part)
                self.sock.transport.write(second_part)
                self.sock.transport.write(last_part)

                # make it clear to the gc that it can reuse this space right
                # away.
                packed_bytes = ''
                msgs = []

                drain_delay = len_packed_bytes / target_MB_per_sec
                if drain_delay < min_sleep:
                    drain_delay = min_sleep

                print "drain delay = %fs len %d" % (drain_delay,
                                                    len_packed_bytes)
                print "snoozing"
                time.sleep(drain_delay)
                print "awake"