'Processes an incoming packet as a sender.
:param packet: The incoming packet dictionary.'

def _handle_packet_as_sender(self, session, packet):

    if (packet['opcode'] != OPCODE_ACK):
        self._logger.error(u'%s    got    OPCODE(%s)    while    expecting    %s', session, packet['opcode'], OPCODE_ACK)
        self._handle_error(session, 4)
        return
    if (packet['block_number'] < session.block_number):
        self._logger.warn(u'%s    ignore    old    block    number    ACK    %s    <    %s', session, packet['block_number'], session.block_number)
        return
    if (packet['block_number'] != session.block_number):
        msg = ('%s    got    ACK    with    block#    %s    while    expecting    %s' % (session, packet['block_number'], session.block_number))
        self._logger.error(msg)
        self._handle_error(session, 0, error_msg=msg)
        return
    if session.is_waiting_for_last_ack:
        session.is_done = True
        return
    data = self._get_next_data(session)
    self._send_data_packet(session, session.block_number, data)
