Commit ccc6335e authored by Antoine Millet's avatar Antoine Millet
Browse files

Management of duplicate connections of clients (refuse the extra clients).

parent 971207ff
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ from sjrpc.server import SimpleSslRpcServer
from handlers import WelcomeHandler
from conf import CCConf
from client import CCClient
from exceptions import AlreadyRegistered

class CCServer(object):
    '''
@@ -71,6 +72,10 @@ class CCServer(object):
        :param tags: tags to add for the client
        '''

        if login in self._connected:
            raise AlreadyRegistered('A client is already connected with this '
                                    'account.')
        else:
            self._connected[login] = CCClient(login, role, self, connection)

    def unregister(self, connection):

ccserver/exceptions.py

0 → 100644
+9 −0
Original line number Diff line number Diff line
#!/usr/bin/env python
#coding=utf8


class AlreadyRegistered(Exception):
    pass

class AuthenticationError(Exception):
    pass
+7 −6
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import logging
from sjrpc.utils import RpcHandler, pure
from tql import TqlQuery
from conf import CCConf
from exceptions import AlreadyRegistered, AuthenticationError

def listed(func):
    func.__listed__ = True
@@ -218,10 +219,6 @@ class ClientHandler(OnlineCCHandler):
        client = self._server.get_connection(login)
        return client.connection.call(command, *args, **kwargs)

class AuthenticationError(Exception):
    pass


class WelcomeHandler(CCHandler):
    '''
    Default handler used on client connections of the server.
@@ -248,8 +245,12 @@ class WelcomeHandler(CCHandler):
            logging.info('New authentication from %s: failure' % login)
            raise AuthenticationError('Authentication failure')
        else:
            # If authentication is a success, ask tags to the server:
            # If authentication is a success, try to register the client:
            try:
                self._server.register(login, role, connection)
            except AlreadyRegistered:
                raise AuthenticationError('Authentication failure '
                                          '(already connected)')
            connection.set_handler(WelcomeHandler.ROLES.get(role)(self._server))
            logging.info('New authentication from %s: success' % login)