Example #1
0
        private async Task InvalidateChallengeToken(Server server)
        {
            var       request = RequestFormingService.HandshakeRequestPackage(server.SessionId);
            IResponse response;

            while (true)
            {
                response = await udpService.SendReceive(server, request);

                if (response is TimeoutResponse)
                {
                    if (ServersTimeoutCounters[server] > MaxTriesBeforeSocketInvalidate)
                    {
                        var delayTask = Task.Delay(RetryAwaitLongInterval);

                        server.InvalidateSocket();
                        ResetTimeoutCounter(server);

                        await delayTask;
                        continue;
                    }

                    ServersTimeoutCounters[server]++;
                    await Task.Delay(RetryAwaitShortInterval);

                    continue;
                }

                break;
            }

            byte[] challengeToken = ResposeParsingService.ParseHandshake((RawResponse)response);

            server.ChallengeToken.UpdateToken(challengeToken);
        }
Example #2
0
        public async Task <ServerFullStateResponse> GetFullStatus(Server server)
        {
            if (!server.ChallengeToken.IsFine)
            {
                await InvalidateChallengeToken(server);
            }

            IResponse response;

            while (true)
            {
                var request = RequestFormingService.GetFullStatusRequestPackage(server.SessionId, server.ChallengeToken);
                response = await udpService.SendReceive(server, request);

                if (response is TimeoutResponse)
                {
                    if (ServersTimeoutCounters[server] > MaxTriesBeforeSocketInvalidate)
                    {
                        var delayTask = Task.Delay(RetryAwaitLongInterval);

                        server.InvalidateSocket();
                        var invalidateTask = InvalidateChallengeToken(server);
                        ResetTimeoutCounter(server);

                        Task.WaitAll(new Task[] { delayTask, invalidateTask });
                        continue;
                    }

                    ServersTimeoutCounters[server]++;
                    await Task.Delay(RetryAwaitShortInterval);

                    continue;
                }

                break;
            }

            var fullStateResponse = ResposeParsingService.ParseFullState((RawResponse)response);

            return(fullStateResponse);
        }