def test_recvRelayCell_data_cell(self, mock_decrypt): cell = RelayDataCell.make(ID, ID, 'a') mock_decrypt.return_value = (cell, 2) self.circuit._processRelayDataCell = mock.Mock() self.circuit._recvRelayCell(cell) self.circuit._processRelayDataCell.assert_called_once_with(cell, 2)
def _writeData(self, data_stream_id_tuple): '''Write data to this circuit's connection. Do the following: 1. Package this data (with appropriate stream_id) into a RelayDataCell. 2. Encrypt this cell. 3. Write this cell to this circuit's connection. 4. Decrement this circuit's packaging window (if we can't package anymore data, enter state CState.BUFFERING, otherwise begin polling from _write_queue again). :param tuple, str, int data_stream_id_tuple: tuple of (data, stream_id) to package into a RelayData cell ''' data, stream_id = data_stream_id_tuple cell = RelayDataCell.make(self.circuit_id, stream_id, data) self._encryptAndSendCell(cell) self._decPackageWindow()
def _writeData(self, data_stream_id_tuple): '''Write data to this circuit's connection. Do the following: 1. Package this data (with appropriate stream_id) into a RelayDataCell. 2. Encrypt this cell. 3. Write this cell to this circuit's connection. 4. Decrement this circuit's packaging window (if we can't package anymore data, enter state CState.BUFFERING, otherwise begin polling from _write_queue again). :param tuple, str, int data_stream_id_tuple: tuple of (data, stream_id) to package into a RelayData cell ''' data, stream_id = data_stream_id_tuple assert len(data) <= MAX_RPAYLOAD_LEN cell = RelayDataCell.make(self.circuit_id, stream_id, data) enc = crypto.encryptCellToTarget(cell, self._crypt_path) self.writeCell(enc) self._decPackageWindow()