def METHOD_NAME(self):
    if self.gate.restricted:
        restricted_user = aj.config.data['restricted_user']
        self.demote(pwd.getpwnam(restricted_user).pw_uid)
    else:
        if self.gate.initial_identity:
            AuthenticationService.get(self.context).login(
                self.gate.initial_identity, demote=True
            )
    try:
        socket_namespaces = {}
        while True:
            rq = self.stream.recv()
            if not rq:
                return
            if rq.object['type'] == 'http':
                gevent.spawn(self.handle_http_request, rq)
            if rq.object['type'] == 'socket':
                msg = rq.object['message']
                nsid = rq.object['namespace']
                event = rq.object['event']
                if event == 'connect':
                    socket_namespaces[nsid] = WorkerSocketNamespace(
                        self.context, nsid
                    )
                socket_namespaces[nsid].process_event(event, msg)
                if event == 'disconnect':
                    socket_namespaces[nsid].destroy()
                    logging.debug('Socket disconnected, destroying endpoints')
            if rq.object['type'] == 'config-data':
                logging.debug('Received a config update')
                aj.config.data = rq.object['data']['config']
                aj.users.data = rq.object['data']['users']
                self._master_config_reloaded.set()
            if rq.object['type'] == 'session-list':
                logging.debug('Received a session list update')
                aj.sessions = rq.object['data']
            if rq.object['type'] == 'verify-totp':
                userid = rq.object['data']['userid']
                result = rq.object['data']['result']
                aj.tfa_config.verify_totp[userid] = result
            if rq.object['type'] == 'update-tfa-config':
                aj.tfa_config.data = rq.object['data']
    # pylint: disable=W0703
    except Exception:
        logging.error('Worker crashed!')
        traceback.print_exc()