Ejemplo n.º 1
0
    def sendRoutineCoreRpc(targetNodeId, content, reqId, rpcId):
        logger.info("发送RPC记录,目标节点:%s,请求ID:%s,RPC ID:%s", targetNodeId, reqId,
                    rpcId)
        dep = DataExchangeProtocol()
        dep.contentType = DataExchangeProtocol.ContentType.ROUTINE
        dep.reqId = reqId
        dep.rpcType = DataExchangeProtocol.RpcType.CORE_RPC
        dep.rpcId = rpcId
        dep.sourceNodeId = Config.nodeId
        dep.targetNodeId = targetNodeId
        dep.timestamp = int(round(time.time() * 1000))
        dep.contentBytes = content

        if not WebSocketClientHandler.sendData(dep.SerializeToString()):
            logger.error("发送RPC错误,目标节点:%s,请求ID:%s,RPC ID:%s", targetNodeId,
                         reqId, rpcId)
            return False
        return True
Ejemplo n.º 2
0
    def sendLz4CoreRpc(targetNodeId, content, reqId, rpcId):
        logger.info("发送RPC记录,目标节点:%s,请求ID:%s,RPC ID:%s", targetNodeId, reqId,
                    rpcId)
        try:
            encodeContent = lz4framed.compress(content)
        except Exception:
            logger.error("发送RPC错误,压缩错误,目标节点:%s,请求ID:%s,RPC ID:%s",
                         targetNodeId,
                         reqId,
                         rpcId,
                         exc_info=True)
            return False

        dep = DataExchangeProtocol()
        dep.contentType = DataExchangeProtocol.ContentType.COMPRESSED_LZ4
        dep.reqId = reqId
        dep.rpcType = DataExchangeProtocol.RpcType.CORE_RPC
        dep.rpcId = rpcId
        dep.sourceNodeId = Config.nodeId
        dep.targetNodeId = targetNodeId
        dep.timestamp = int(round(time.time() * 1000))
        dep.contentBytes = encodeContent
        if not WebSocketClientHandler.sendData(dep.SerializeToString()):
            logger.error("发送RPC错误,目标节点:%s,请求ID:%s,RPC ID:%s", targetNodeId,
                         reqId, rpcId)
            return False
        return True
Ejemplo n.º 3
0
    def processData(data):
        try:
            dep = DataExchangeProtocol()
            dep.ParseFromString(data)

        except Exception as e:
            logger.error("处理DEP错误,PB解析数据发生错误")
            logger.error(e, exc_info=True)
            logger.error("处理DEP错误,PB解析数据发生错误,原始数据:%s", data)
            return

        sourceNodeId = dep.sourceNodeId
        targetNodeId = dep.targetNodeId

        if targetNodeId != Config.nodeId:
            logger.error("处理DEP错误,目标节点ID不匹配当前节点ID:%s,目标节点ID:%s", Config.nodeId,
                         targetNodeId)
            return

        rpcId = dep.rpcId
        timestamp = dep.timestamp
        contentType = dep.contentType
        rpcType = dep.rpcType
        reqId = dep.reqId
        logger.info(
            "处理DEP记录,来源节点ID:%s,RPC类型:%s,RPC ID:%s,请求ID:%s内容类型:%s,时间戳:%s",
            sourceNodeId, rpcType, rpcId, reqId, contentType, timestamp)

        if contentType == DataExchangeProtocol.ContentType.COMPRESSED_LZ4:
            try:
                contentByteString = lz4framed.decompress(dep.contentBytes)
            except Exception:
                logger.error(
                    "处理DEP异常,来源节点ID:%s,RPC类型:%s,RPC ID:%s,请求ID:%s时间戳:%s,无法使用LZ4正确解析报文内容",
                    sourceNodeId,
                    rpcType,
                    rpcId,
                    reqId,
                    timestamp,
                    exc_info=True)
                RpcClientProcessService.sendExceptionRsp(
                    sourceNodeId, rpcId, reqId, timestamp, "无法使用LZ4正确解析报文内容")
                return
        elif contentType == DataExchangeProtocol.ContentType.ROUTINE:
            contentByteString = dep.contentBytes
        else:
            logger.error(
                "处理DEP错误,来源节点ID:%s,RPC类型:%s,RPC ID:%s,请求ID:%s内容类型:%s,时间戳:%s,不支持的报文类型",
                sourceNodeId, rpcType, rpcId, reqId, contentType, timestamp)
            RpcClientProcessService.sendExceptionRsp(sourceNodeId, rpcId,
                                                     reqId, timestamp,
                                                     "不支持的报文类型")
            return

        if not contentByteString or len(contentByteString) <= 0:
            logger.error(
                "处理DEP错误,来源节点ID:%s,RPC类型:%s,RPC ID:%s,请求ID:%s内容类型:%s,时间戳:%s,报文内容长度错误",
                sourceNodeId, rpcType, rpcId, contentType, timestamp)
            RpcClientProcessService.sendExceptionRsp(sourceNodeId, rpcId,
                                                     reqId, timestamp,
                                                     "报文内容长度错误")
            return

        if rpcType != DataExchangeProtocol.RpcType.CORE_RPC:
            logger.error(
                "处理DEP错误,来源节点ID:%s,RPC类型:%s,RPC ID:%s,请求ID:%s内容类型:%s,时间戳:%s,未能识别的RPC类型",
                sourceNodeId, rpcType, rpcId, reqId, contentType, timestamp)
            return

        RpcClientProcessService.doCoreRpc(sourceNodeId, rpcId, reqId,
                                          contentByteString, timestamp)