/// <summary>
 /// TCP调用客户端
 /// </summary>
 /// <param name="attribute">TCP 调用服务器端配置信息</param>
 /// <param name="clientRoute">TCP 客户端路由</param>
 /// <param name="log">日志接口</param>
 public TcpInternalStreamClient(AutoCSer.Net.TcpInternalStreamServer.ServerAttribute attribute = null, AutoCSer.Net.TcpServer.ClientLoadRoute <AutoCSer.Net.TcpInternalStreamServer.ClientSocketSender> clientRoute = null, AutoCSer.Log.ILog log = null)
 {
     if (attribute == null)
     {
         attribute = AutoCSer.Net.TcpInternalStreamServer.ServerAttribute.GetConfig("TcpInternalStreamServerPerformance", typeof(AutoCSer.TestCase.TcpInternalStreamServerPerformance.InternalStreamServer));
     }
     _TcpClient_ = new AutoCSer.Net.TcpInternalStreamServer.Client <TcpInternalStreamClient>(this, attribute, log, clientRoute);
     if (attribute.IsAuto)
     {
         _TcpClient_.TryCreateSocket();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 时间验证客户端验证
        /// </summary>
        /// <param name="verify">时间验证服务客户端委托</param>
        /// <param name="sender"></param>
        /// <param name="client"></param>
        /// <returns></returns>
        public unsafe static bool Verify(Verifier verify, ClientSocketSender sender, AutoCSer.Net.TcpInternalStreamServer.Client client)
        {
            long            ticks;
            ServerAttribute attribute    = client.Attribute;
            string          verifyString = attribute.VerifyString;

            if (verifyString == null)
            {
                ticks = 0;
                return(verify(sender, 0, null, ref ticks).Value);
            }
            ulong markData = 0;

            if (attribute.IsMarkData)
            {
                markData = attribute.VerifyHashCode;
            }
            ticks = Date.NowTime.SetUtc().Ticks;
            TcpServer.ClientSocketBase socket = sender.ClientSocket;
            do
            {
                ulong randomPrefix = Random.Default.SecureNextULongNotZero();
                while (randomPrefix == markData)
                {
                    randomPrefix = Random.Default.SecureNextULongNotZero();
                }
                socket.ReceiveMarkData = attribute.IsMarkData ? markData ^ randomPrefix : 0UL;
                sender.SendMarkData    = 0;
                long lastTicks = ticks;
                TcpServer.ReturnValue <bool> isVerify = verify(sender, randomPrefix, TcpServer.TimeVerifyServer.Md5(verifyString, randomPrefix, ticks), ref ticks);
                if (isVerify.Value)
                {
                    sender.SendMarkData = socket.ReceiveMarkData;
                    return(true);
                }
                if (isVerify.Type != TcpServer.ReturnType.Success || ticks <= lastTicks)
                {
                    socket.Log.add(AutoCSer.Log.LogType.Error, "TCP客户端验证失败 [" + isVerify.Type.ToString() + "] " + ticks.toString() + " <= " + lastTicks.toString());
                    return(false);
                }
                socket.Log.add(AutoCSer.Log.LogType.Error, "TCP客户端验证时间失败重试 " + ticks.toString() + " - " + lastTicks.toString());
            }while (true);
        }