Commit ccc6335e authored by Antoine Millet's avatar Antoine Millet

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

parent 971207ff
......@@ -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):
'''
......@@ -70,8 +71,12 @@ class CCServer(object):
:param connection: connection to register
:param tags: tags to add for the client
'''
self._connected[login] = CCClient(login, role, self, connection)
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):
'''
......
#!/usr/bin/env python
#coding=utf8
class AlreadyRegistered(Exception):
pass
class AuthenticationError(Exception):
pass
......@@ -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:
self._server.register(login, role, connection)
# 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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment