Exemplo n.º 1
0
    async def processMessages(self):
        try:
            while True:
                data = await self.inQueue.get()

                if data is None:
                    continue

                msg = self.msgDataToJson(data)
                if msg is None:
                    self.debug('Invalid JSON message')
                    continue

                sender = data['from'] if isinstance(data['from'], str) else \
                    data['from'].decode()

                try:
                    gHub.publish(keyPsJson, (sender, self.topic, msg))
                    await self.processJsonMessage(sender, msg)
                except Exception as exc:
                    self.debug('processJsonMessage error: {}'.format(str(exc)))
                    traceback.print_exc()
                    await self.errorsQueue.put((msg, exc))
                    self._errorsCount += 1
        except asyncio.CancelledError:
            self.debug('JSON process cancelled')
        except Exception as err:
            self.debug('JSON process exception: {}'.format(str(err)))
Exemplo n.º 2
0
    async def handleStatusMessage(self, sender, peerCtx, msg):
        sMsg = ChatStatusMessage(msg)
        if not sMsg.valid():
            self.debug('Invalid chat message')
            return

        sMsg.peerCtx = peerCtx
        gHub.publish(self.psKey, sMsg)
Exemplo n.º 3
0
    async def handleChatMessage(self, sender, peerCtx, msg):
        cMsg = ChatRoomMessage(msg)
        if not cMsg.valid():
            self.debug('Invalid chat message')
            return

        cMsg.peerCtx = peerCtx
        gHub.publish(self.psKey, cMsg)
Exemplo n.º 4
0
    async def handleChannelsListMessage(self, ipfsop, msg):
        cMsg = ChatChannelsListMessage(msg)
        if not cMsg.valid():
            self.debug('Invalid channels message')
            return

        self.debug('Received valid chat channels list message')

        # Publish to the hub
        gHub.publish(keyChatChannels, cMsg)
Exemplo n.º 5
0
    async def processMessages(self):
        try:
            asyncConv = getattr(self, 'asyncMsgDataToJson')
        except Exception:
            useAsyncConv = False
        else:
            useAsyncConv = asyncio.iscoroutinefunction(asyncConv)

        try:
            while not self._shuttingDown:
                data = await self.inQueue.get()

                if data is None:
                    continue

                async with self.throttler:
                    if self._shuttingDown:
                        return

                    if useAsyncConv is True:
                        msg = await asyncConv(data)
                    else:
                        msg = self.msgDataToJson(data)

                    if msg is None:
                        self.debug('Invalid JSON message')
                        continue

                    sender = data['from'] if isinstance(
                        data['from'], str) else data['from'].decode()

                    try:
                        if self.hubPublish:
                            gHub.publish(self.hubKey,
                                         (sender, self.topic(), msg))

                        rec = await self.psDbManager.recordMessage(
                            sender, len(data['data']), seqNo=data['seqno'])

                        await self.processJsonMessage(sender,
                                                      msg,
                                                      msgDbRecord=rec)
                    except Exception as exc:
                        self.debug('processJsonMessage error: {}'.format(
                            str(exc)))
                        traceback.print_exc()
                        await self.errorsQueue.put((msg, exc))
                        self._errorsCount += 1

                    self.inQueue.task_done()

        except asyncio.CancelledError:
            self.debug('JSON process cancelled')
        except Exception as err:
            self.debug('JSON process exception: {}'.format(str(err)))
Exemplo n.º 6
0
    async def processFilters(self):
        """
        Filters process task
        """

        while not self.should_stop:
            await asyncio.sleep(5)

            for filter in self.filters:
                for event in filter.get_all_entries():

                    # Push to the hub
                    gHub.publish(self.psKey, event)
Exemplo n.º 7
0
    async def sendChannelsStatus(self):
        msgConfig = cGet('services.chat.messages.UserChannelsListMessage',
                         mod='galacteek.ipfs.pubsub.srvs')
        delay = msgConfig.publishTimer

        pubChannels = {}
        pubChannels = []

        for chan, _w in self.channelWidgets.items():
            pubChannels.append({
                'tokenSigMethod': 'rsa',
                'sessionJwsCid': _w.psService.jwsTokenCid
            })

        userChannelsMsg = UserChannelsListMessage.make(self.userListRev,
                                                       pubChannels)

        # Publish on the keyChatChanList PS key, the PS service catches it
        # and sends the message
        gHub.publish(keyChatChanList, userChannelsMsg)

        ensureLater(delay, self.sendChannelsStatus)
Exemplo n.º 8
0
    async def gHubPublish(self, key, msg):
        gHub.publish(key, msg)

        await asyncio.sleep(0.05)