Ejemplo n.º 1
0
    def on_authenticate(self, data):
        core = Core.getInstance()

        # Check Public ID
        if not 'publicId' in data:
            util.socketError(self, 'Missing public key.')
            return
        publicId = data['publicId']
        if not util.validPublicId(publicId):
            util.socketError(self, 'Invalid public key.')
            return

        # Handle reconnection
        if publicId in core.clients:
            if not core.validIdPair(data):
                self.emit('authenticate', {'status': 'fail'})
                return
            client = core.clients[publicId]
            client.sockets['core'] = self
            self.socket.session['client'] = client
            self.emit('authenticate', {'status': 'success'})
            return

        # Distribute privateId
        secret = None
        if('privateId' in data
           and util.validPrivateId(data['privateId'])):
            secret = data['privateId']
        else:
            secret = util.randomKey(32)
        self.client = Client(publicId, secret)
        self.client.sockets['core'] = self
        core.clients[publicId] = self.client
        self.emit('authenticate', {'status': 'success'
                                 , 'privateId': secret})
Ejemplo n.º 2
0
 def __init__(self, app):
     Core.instance = self
     self.app = app
     self.clients = {}
     self.instanceId = util.randomKey(32);
     app.hookNamespace('/core', CoreNamespace)