def test_recvRelayCell_sendme_cell(self, mock_decrypt): cell = RelaySendMeCell.make(ID, ID) mock_decrypt.return_value = (cell, 2) self.circuit._processRelaySendMeCell = mock.Mock() self.circuit._recvRelayCell(cell) self.circuit._processRelaySendMeCell.assert_called_once_with(cell, 2)
def sendStreamSendMe(self, stream_id): '''Send a stream-level RelaySendMe cell with its stream_id equal to *stream_id*. Construct the send me cell, encrypt it, and immediately write it to this circuit's connection. :param int stream_id: stream_id to use in the RelaySendMeCell ''' cell = RelaySendMeCell.make(self.circuit_id, stream_id=stream_id) enc = crypto.encryptCellToTarget(cell, self._crypt_path) self.writeCell(enc)
def _decDeliverWindow(self): '''Decrement this circuit's deliver window. Called when we deliver an incoming RelayDataCell's payload to a stream. If the delivery window is below the default threshold, send a RelaySendMeCell. ''' self._deliver_window -= 1 if self._deliver_window <= SENDME_THRESHOLD: cell = RelaySendMeCell.make(self.circuit_id) enc = crypto.encryptCellToTarget(cell, self._crypt_path) self.writeCell(enc) self._deliver_window += WINDOW_SIZE
def sendStreamSendMe(self, stream): '''Send a stream-level RelaySendMe cell with its stream_id equal to *stream_id*. Construct the send me cell, encrypt it, and immediately write it to this circuit's connection. :param int stream_id: stream_id to use in the RelaySendMeCell ''' cell = RelaySendMeCell.make(self.circuit_id, stream_id=stream.stream_id) self._encryptAndSendCell(cell) msg = ("Circuit {} sent a RelaySendMeCell for stream {}.".format( self.circuit_id, stream.stream_id)) logging.debug(msg)
def sendStreamSendMe(self, stream): '''Send a stream-level RelaySendMe cell with its stream_id equal to *stream_id*. Construct the send me cell, encrypt it, and immediately write it to this circuit's connection. :param int stream_id: stream_id to use in the RelaySendMeCell ''' cell = RelaySendMeCell.make(self.circuit_id, stream_id=stream.stream_id) self._encryptAndSendCell(cell) msg = ("Circuit {} sent a RelaySendMeCell for stream {}." .format(self.circuit_id, stream.stream_id)) logging.debug(msg)
def _decDeliverWindow(self): '''Decrement this circuit's deliver window. Called when we deliver an incoming RelayDataCell's payload to a stream. If the delivery window is below the default threshold, send a RelaySendMeCell. ''' self._deliver_window -= 1 if self._deliver_window <= SENDME_THRESHOLD: cell = RelaySendMeCell.make(self.circuit_id) self._encryptAndSendCell(cell) self._deliver_window += WINDOW_SIZE msg = ("Circuit {}'s delivery window dropped to {}. The circuit " "sent a circuit-level RelaySendMeCell and incremented " "its delivery window to {}.".format( self.circuit_id, self._deliver_window - WINDOW_SIZE, self._deliver_window)) logging.debug(msg)
def _decDeliverWindow(self): '''Decrement this circuit's deliver window. Called when we deliver an incoming RelayDataCell's payload to a stream. If the delivery window is below the default threshold, send a RelaySendMeCell. ''' self._deliver_window -= 1 if self._deliver_window <= SENDME_THRESHOLD: cell = RelaySendMeCell.make(self.circuit_id) self._encryptAndSendCell(cell) self._deliver_window += WINDOW_SIZE msg = ("Circuit {}'s delivery window dropped to {}. The circuit " "sent a circuit-level RelaySendMeCell and incremented " "its delivery window to {}." .format(self.circuit_id, self._deliver_window - WINDOW_SIZE, self._deliver_window)) logging.debug(msg)