def _initialize(self, args_line):
        super()._initialize(args_line)
        self._send_request = True
        self._finish = False

        session = SessionManager().get_all_not_inactive_sessions()[0]
        client_uuid = session.client_uuid
        self._request = generate_packet(self.get_command_id(),
                                        ErrorIds.SUCCESSFUL, client_uuid)
        session.status = SessionStatus.wait_for_close
def _handle_server_disconnection():
    # Socket closed by server
    # ToDo: Ask user for trying reactivation
    session = SessionManager().get_all_not_inactive_sessions()[0]
    if session.status == SessionStatus.wait_for_close:
        raise ProgramFinished(ErrorIds.SUCCESSFUL)
    raise Exception("Server socket closed unexpectedly")
Exemple #3
0
def server_state_check(dummy_arg):
    """Check last receive time in all active sessions.

       If time is expired, session will be deactivated.
    """
    # ToDo: Do sth with exceptional sockets
    active_sessions = _get_not_inactive_sessions()
    cur_time = time.time()

    for session in active_sessions:
        if cur_time - session.last_recv_time > _conn_break_timeout:
            LOG.warning(
                "Client %s:%d: seems that physical connection is broken" %
                session.client_address)
            _deactivate_session(session)
            LOG.warning("Client %s:%d: logical connection frozen" %
                        session.client_address)
            _socket_manager.delete_socket_by_address(session.client_address)
            LOG.warning("Client %s:%d: physical connection closed" %
                        session.client_address)

    for sock in _socket_manager.exceptional:
        socket_address = _socket_manager.address_by_socket_id[id(sock)]
        session = SessionManager.get_session(client_address=socket_address)
        LOG.warning("Client %s:%d: seems that physical connection is broken" %
                    session.client_address)
        _deactivate_session(session)
        LOG.warning("Client %s:%d: logical connection frozen" %
                    session.client_address)
        _socket_manager.delete_socket_by_address(session.client_address)
        LOG.warning("Client %s:%d: physical connection closed" %
                    session.client_address)
Exemple #4
0
    def _initialize(self, first_packet_data):
        self._start_time = time.time()
        self._create_default_download_dir()

        self._current_sesion = SessionManager().get_all_not_inactive_sessions()[0]

        if first_packet_data is not None:
            try:
                args = _parse_args(first_packet_data)
            except SystemExit as e:
                raise CommandInvalid(str(e))

            self._server_file_path = args.file
            self._client_file_path = os.path.join(STORAGE_PATH, args.file) if args.dest_path is None else args.dest_path
            self._file_writer = FileWriter(self._client_file_path)
        else:
            self._server_file_path = None
            self._client_file_path = None
            self._file_writer = None

        self.IS_COMMAND_RESTORED = None
        self._command_restored_request_sended = None

        self._server_file_size = None
        self._readed_bytes = 0

        self._generate_request_package = True
        self._first_recived_package = True
        self._send_approve = False
        self._raise_finished = False
Exemple #5
0
 def _initialize(self, first_packet_data):
     self._uuid = get_payload(first_packet_data)
     self._client_address = SessionManager().delete_session(uuid=self._uuid)
     if self._client_address is not None:
         SocketManager().delete_socket_by_address(self._client_address)
         LOG.info('Client %s:%d: logical connection closed' %
                  self._client_address)
         LOG.info('Client %s:%d: physical connection closed' %
                  self._client_address)
     self._finished = True
Exemple #6
0
import logging

from sft.common.sessions.session_manager import SessionManager

LOG = logging.getLogger(__name__)

_session_manager = SessionManager()


def packet_dispatcher(data):
    """Dispatch packets to appropriate sessions.

       :param data: [(client_addr, packet_payload), ...]
       :return []
    """
    # LOG.debug('std packet_dispatcher step')

    for client__address, data in data:
        session = _session_manager.get_session(client_address=client__address)
        session.command_receive_data(data)
Exemple #7
0
import logging
import time

from sft.common.config import Config
from sft.common.sessions.session_manager import SessionManager
from sft.common.socket_manager import SocketManager

LOG = logging.getLogger(__name__)
_get_not_inactive_sessions = SessionManager().get_all_not_inactive_sessions
_deactivate_session = SessionManager().deactivate_session
_conn_break_timeout = Config().connection_break_timeout
_socket_manager = SocketManager()


def server_state_check(dummy_arg):
    """Check last receive time in all active sessions.

       If time is expired, session will be deactivated.
    """
    # ToDo: Do sth with exceptional sockets
    active_sessions = _get_not_inactive_sessions()
    cur_time = time.time()

    for session in active_sessions:
        if cur_time - session.last_recv_time > _conn_break_timeout:
            LOG.warning(
                "Client %s:%d: seems that physical connection is broken" %
                session.client_address)
            _deactivate_session(session)
            LOG.warning("Client %s:%d: logical connection frozen" %
                        session.client_address)
import logging

from sft.common.sessions.session_manager import SessionManager
from sft.common.socket_manager import SocketManager

LOG = logging.getLogger(__name__)

_get_session = SessionManager().get_session
_socket_manager = SocketManager()


def payload_collector(dummy_arg):
    data = []
    for socket in _socket_manager.writable:
        # ToDo: Rewrite payload collector to be appropriate for UDP
        # Slow for TCP and inappropriate for UDP
        # client_address = socket.getpeername()
        client_address = _socket_manager.address_by_socket_id[id(socket)]
        command_data = _get_session(client_address=client_address,
                                    create_new=True).command_generate_data()
        if command_data is not None:
            data.append((client_address, command_data))
    return data