Пример #1
0
async def counter(websocket, path, dbFileName):
    # register(websocket) sends user_event() to websocket
    #await register(websocket)
    openRequestTokens = set()
    authenticatedChannelIds = set()
    try:
        async for message in websocket:
            data = json.loads(message)
            logging.debug("%s, %s", data, path)

            requestToken = data["requestToken"]
            if requestToken in openRequestTokens:
                # request token collision or request has already been added to the list
                # please try again with a different request token or don't bother, we already got the message
                websocket.send(
                    json.dumps({
                        'message': 'collision',
                        'requestToken': requestToken
                    }))
                continue
            else:
                openRequestTokens.add(requestToken)

            if data["message"] == "create channel":
                await createChannel(websocket, dbFileName, data)
            elif data["message"] == "authenticate":
                await authenticate(websocket, dbFileName, data)
                logging.debug(
                    "auth channels total: %i, auth clients total: %i",
                    connections.activeChannels(), connections.activeClients())

            openRequestTokens.remove(requestToken)
    finally:
        connections.forget(websocket)
Пример #2
0
async def connector(client, path, dbFileName):
    # register(client) sends user_event() to client
    #await register(client)
    openRequestTokens = set()
    authenticatedChannelIds = set()
    try:
        async for message in client:
            message = json.loads(message)
            # if message["header"]["acknowledge"] == True:
            #     await messages.acknowledge(client, message);

            subject = message["header"]["subject"]
            if subject == "create accounts":
                await createAccounts(client, dbFileName, message)
            elif subject == "create identities":
                await createIdentities(client, dbFileName, message)
            elif subject == "authenticate":
                await authenticate(client, dbFileName, message)
            elif subject == "get":
                await get(client, dbFileName, message)
            elif subject == "save":
                await save(client, dbFileName, message)
            elif subject == "send message":
                await sendMessage(client, dbFileName, message)
            #elif subject == "delete":
            #    await delete(client, dbFileName, message)
    finally:
        connections.forget(client)
Пример #3
0
async def counter(websocket, path, dbFileName):
    # register(websocket) sends user_event() to websocket
    #await register(websocket)
    openRequestTokens = set()
    authenticatedChannelIds = set()
    try:
        async for message in websocket:
            data = json.loads(message)
            logging.debug("%s, %s", data, path)

            requestId = data["requestId"]
            if requestId in openRequestTokens:
                # request token collision or request has already been added to the list
                # please try again with a different request token or don't bother, we already got the message
                await requests.send(websocket, requestId, {
                    'status': 'failed',
                    'reason': 'request id collision'
                })
                continue
            else:
                openRequestTokens.add(requestId)

            if data["message"] == "create channel":
                await createChannel(websocket, dbFileName, data)
            elif data["message"] == "authenticate":
                await authenticate(websocket, dbFileName, data)
            elif data["message"] == "send message":
                await sendMessage(websocket, dbFileName, data)

            openRequestTokens.remove(requestId)
    finally:
        connections.forget(websocket)
Пример #4
0
async def counter(websocket, path, dbFileName):
    # register(websocket) sends user_event() to websocket
    #await register(websocket)
    openRequestTokens = set()
    authenticatedChannelIds = set()
    try:
        async for message in websocket:
            message = json.loads(message)
            if message["acknowledge"] == True:
                await messages.acknowledge(websocket, message)

            if message["subject"] == "create channel":
                await createChannel(websocket, dbFileName, message)
            elif message["subject"] == "authenticate":
                await authenticate(websocket, dbFileName, message)
            elif message["subject"] == "send message":
                await sendMessage(websocket, dbFileName, message)
    finally:
        connections.forget(websocket)