예제 #1
0
    def __init__(self,
                 circuit_manager,
                 circuit_id,
                 conn,
                 circuit_type,
                 path,
                 crypt_path,
                 max_streams=MAX_STREAMS_V3):
        '''
        :param int cid: id of this circuit
        '''
        self._circuit_manager = circuit_manager
        self.circuit_id = circuit_id
        self._connection = conn
        self.circuit_type = circuit_type
        self._path = path
        self._crypt_path = crypt_path
        # _read_queue handles incoming cells from the network
        self._read_queue = defer.DeferredQueue()
        self._read_task = None
        # _write_queue handles incoming data from local applications
        self._write_queue = defer.DeferredQueue()
        self._write_task = None
        self._streams = {}
        self._ctr = ctr(max_streams)
        self._max_streams = max_streams
        self._state = CState.OPEN
        # deliver window is incoming data cells
        self._deliver_window = CIRCUIT_WINDOW_THRESHOLD_INIT
        # package window is outgoing data cells
        self._package_window = CIRCUIT_WINDOW_THRESHOLD_INIT

        self._pollReadQueue()
        self._pollWriteQueue()
예제 #2
0
파일: circuit.py 프로젝트: nskinkel/oppy
    def __init__(self, circuit_manager, circuit_id, conn, circuit_type,
                 path, crypt_path, max_streams=MAX_STREAMS_V3):
        '''
        :param int cid: id of this circuit
        '''
        self._circuit_manager = circuit_manager
        self.circuit_id = circuit_id
        self._connection = conn
        self.circuit_type = circuit_type
        self._path = path
        self._crypt_path = crypt_path
        # _read_queue handles incoming cells from the network
        self._read_queue = defer.DeferredQueue()
        self._read_task = None
        # _write_queue handles incoming data from local applications
        self._write_queue = defer.DeferredQueue()
        self._write_task = None
        self._streams = {}
        self._ctr = ctr(max_streams)
        self._max_streams = max_streams
        self._state = CState.OPEN
        # deliver window is incoming data cells
        self._deliver_window = CIRCUIT_WINDOW_THRESHOLD_INIT
        # package window is outgoing data cells
        self._package_window = CIRCUIT_WINDOW_THRESHOLD_INIT

        self._pollReadQueue()
        self._pollWriteQueue()
예제 #3
0
    def __init__(self, connection_manager, netstatus, autobuild=True):
        logging.debug("Creating circuit manager.")
        self._netstatus = netstatus
        self._guard_manager = GuardManager(netstatus)
        self._connection_manager = connection_manager
        self._ctr = ctr(MAX_STREAMS_V3)
        self._open_circuit_dict = {}
        self._circuit_build_task_dict = {}
        self._pending_stream_list = []
        self._min_IPv4_count = DEFAULT_OPEN_IPv4
        self._min_IPv6_count = DEFAULT_OPEN_IPv6
        self._sent_open_message = False

        if autobuild is True:
            self._buildCircuits(self._min_IPv4_count,
                                circuit_type=CircuitType.IPv4)
            self._buildCircuits(self._min_IPv6_count,
                                circuit_type=CircuitType.IPv6)
예제 #4
0
    def __init__(self, connection_manager, netstatus, autobuild=True):
        logging.debug("Creating circuit manager.")
        self._netstatus = netstatus
        self._guard_manager = GuardManager(netstatus)
        self._connection_manager = connection_manager
        self._ctr = ctr(MAX_STREAMS_V3)
        self._open_circuit_dict = {}
        self._circuit_build_task_dict = {}
        self._pending_stream_list = []
        self._min_IPv4_count = DEFAULT_OPEN_IPv4
        self._min_IPv6_count = DEFAULT_OPEN_IPv6
        self._sent_open_message = False

        if autobuild is True:
            self._buildCircuits(self._min_IPv4_count,
                                circuit_type=CircuitType.IPv4)
            self._buildCircuits(self._min_IPv6_count,
                                circuit_type=CircuitType.IPv6)
예제 #5
0
    def test_addStreamAndSetStreamID_ctr_rollover_find_next_free_id(self):
        self.circuit._ctr = ctr(TEST_MAX_STREAMS)
        for i in xrange(1, TEST_MAX_STREAMS - 4):
            next(self.circuit._ctr)

        self.circuit._streams[TEST_MAX_STREAMS - 4] = mock.Mock()
        self.circuit._streams[TEST_MAX_STREAMS - 3] = mock.Mock()
        self.circuit._streams[TEST_MAX_STREAMS - 2] = mock.Mock()
        self.circuit._streams[TEST_MAX_STREAMS - 1] = mock.Mock()
        self.circuit._streams[TEST_MAX_STREAMS] = mock.Mock()
        self.circuit._streams[1] = mock.Mock()
        self.circuit._streams[2] = mock.Mock()
        self.circuit._streams[3] = mock.Mock()

        mock_stream = mock.Mock()
        self.circuit.addStreamAndSetStreamID(mock_stream)

        self.assertEqual(mock_stream.stream_id, 4)
        self.assertTrue(self.circuit._streams[4] == mock_stream)
예제 #6
0
    def test_addStreamAndSetStreamID_ctr_rollover_find_next_free_id(self):
        self.circuit._ctr = ctr(TEST_MAX_STREAMS)
        for i in xrange(1, TEST_MAX_STREAMS-4):
            next(self.circuit._ctr)

        self.circuit._streams[TEST_MAX_STREAMS-4] = mock.Mock()
        self.circuit._streams[TEST_MAX_STREAMS-3] = mock.Mock()
        self.circuit._streams[TEST_MAX_STREAMS-2] = mock.Mock()
        self.circuit._streams[TEST_MAX_STREAMS-1] = mock.Mock()
        self.circuit._streams[TEST_MAX_STREAMS] = mock.Mock()
        self.circuit._streams[1] = mock.Mock()
        self.circuit._streams[2] = mock.Mock()
        self.circuit._streams[3] = mock.Mock()

        mock_stream = mock.Mock() 
        self.circuit.addStreamAndSetStreamID(mock_stream)

        self.assertEqual(mock_stream.stream_id, 4)
        self.assertTrue(self.circuit._streams[4] == mock_stream)
예제 #7
0
 def test_ctr(self):
     c = tools.ctr(10)
     for i in range(1, 10):
         self.assertEqual(i, next(c))
     self.assertEqual(1, next(c))