Ejemplo n.º 1
0
        /// <summary>
        /// 收到客户端请求,通过 REQ/REP的模式向远端Actor请求处理,并获得数据
        /// </summary>
        /// <param name="protocolPackage"></param>
        /// <param name="body"></param>
        public virtual Out ProcessRequest(IProtocolPackage protocolPackage, byte[] body)
        {
            //LRU
            //REQ --- Router/Router --- REQ

            if (protocolPackage == null)
            {
                return(null);
            }
            if (Logger.IsDebugEnabled)
            {
                Logger.Debug($"request from #{protocolPackage.Id}# {protocolPackage.RemoteEndPoint}");
            }

            if (protocolPackage.CryptoByte > 0)
            {
                var last = NetSend.GetProtocolPackage(protocolPackage.Rid);
                if (!Equals(last.Id, protocolPackage.Id))
                {
                    if (Logger.IsDebugEnabled)
                    {
                        Logger.Warn($"!Equals(last.Id, protocolPackage.Id)");
                    }

                    protocolPackage.Close();

                    if (Logger.IsDebugEnabled)
                    {
                        Logger.Debug($"#{protocolPackage.Id}# !Equals(last.Id, protocolPackage.Id)");
                    }
                    return(null);
                }
            }
            //解密Cient数据包
            var request = protocolPackage.UnPackToPacket(body);

            var din = new In()
            {
                Version     = 1,
                Action      = PirateXAction.Req,
                HeaderBytes = request.HeaderBytes,
                QueryBytes  = request.ContentBytes,
                Ip          = (protocolPackage.RemoteEndPoint as IPEndPoint).Address.ToString(),
                LastNo      = protocolPackage.LastNo,
                SessionId   = protocolPackage.Id,
                FrontendID  = FrontendID,
            };

            if (ProfilerLog.ProfilerLogger.IsInfoEnabled)
            {
                din.Profile.Add("_tin_", $"{DateTime.UtcNow.Ticks}");
            }

            return(RequestToRemoteResponseSocket(din));
        }