From 609aca7093055ea2c4079a488de685152c00c779 Mon Sep 17 00:00:00 2001 From: vastly Date: Tue, 8 Feb 2022 11:23:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E4=B8=8B=E6=95=B0=E7=BB=84=E5=8F=96=E5=80=BC=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MSDKDns/CacheManager/MSDKDnsManager.m | 29 ++++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/MSDKDns/CacheManager/MSDKDnsManager.m b/MSDKDns/CacheManager/MSDKDnsManager.m index 4e31d26..faa49be 100644 --- a/MSDKDns/CacheManager/MSDKDnsManager.m +++ b/MSDKDns/CacheManager/MSDKDnsManager.m @@ -734,20 +734,21 @@ - (void)switchDnsServer { } self.waitToSwitch = YES; dispatch_async([MSDKDnsInfoTool msdkdns_queue], ^{ - self.serverIndex += 1; - if (!self.firstFailTime) { - self.firstFailTime = [NSDate date]; - // 一定时间后自动切回主ip - __weak __typeof__(self) weakSelf = self; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW,[[MSDKDnsParamsManager shareInstance] msdkDnsGetMinutesBeforeSwitchToMain] * 60 * NSEC_PER_SEC), [MSDKDnsInfoTool msdkdns_queue], ^{ - if (weakSelf.firstFailTime && [[NSDate date] timeIntervalSinceDate:weakSelf.firstFailTime] >= [[MSDKDnsParamsManager shareInstance] msdkDnsGetMinutesBeforeSwitchToMain] * 60) { - MSDKDNSLOG(@"auto reset server index, use main ip now."); - weakSelf.serverIndex = 0; - weakSelf.firstFailTime = nil; - } - }); - } - if (self.serverIndex >= [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] count]) { + if (self.serverIndex < [[[MSDKDnsParamsManager shareInstance] msdkDnsGetServerIps] count]) { + self.serverIndex += 1; + if (!self.firstFailTime) { + self.firstFailTime = [NSDate date]; + // 一定时间后自动切回主ip + __weak __typeof__(self) weakSelf = self; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW,[[MSDKDnsParamsManager shareInstance] msdkDnsGetMinutesBeforeSwitchToMain] * 60 * NSEC_PER_SEC), [MSDKDnsInfoTool msdkdns_queue], ^{ + if (weakSelf.firstFailTime && [[NSDate date] timeIntervalSinceDate:weakSelf.firstFailTime] >= [[MSDKDnsParamsManager shareInstance] msdkDnsGetMinutesBeforeSwitchToMain] * 60) { + MSDKDNSLOG(@"auto reset server index, use main ip now."); + weakSelf.serverIndex = 0; + weakSelf.firstFailTime = nil; + } + }); + } + } else { self.serverIndex = 0; self.firstFailTime = nil; }