解决了语音上传到问题,接下来要解决下载播放问题
This commit is contained in:
94
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfig.h
generated
Normal file
94
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfig.h
generated
Normal file
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// QNServerConfig.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2021/8/30.
|
||||
// Copyright © 2021 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNCache.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QNServerRegionConfig : NSObject
|
||||
|
||||
@property(nonatomic, assign, readonly)long clearId;
|
||||
@property(nonatomic, assign, readonly)BOOL clearCache;
|
||||
|
||||
+ (instancetype)config:(NSDictionary *)info;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface QNServerDnsServer : NSObject
|
||||
|
||||
@property(nonatomic, assign, readonly)BOOL isOverride;
|
||||
@property(nonatomic, strong, readonly)NSArray <NSString *> *servers;
|
||||
|
||||
+ (instancetype)config:(NSDictionary *)info;
|
||||
|
||||
@end
|
||||
|
||||
@interface QNServerDohConfig : NSObject
|
||||
|
||||
@property(nonatomic, strong, readonly)NSNumber *enable;
|
||||
@property(nonatomic, strong, readonly)QNServerDnsServer *ipv4Server;
|
||||
@property(nonatomic, strong, readonly)QNServerDnsServer *ipv6Server;
|
||||
|
||||
+ (instancetype)config:(NSDictionary *)info;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface QNServerUdpDnsConfig : NSObject
|
||||
|
||||
@property(nonatomic, strong, readonly)NSNumber *enable;
|
||||
@property(nonatomic, strong, readonly)QNServerDnsServer *ipv4Server;
|
||||
@property(nonatomic, strong, readonly)QNServerDnsServer *ipv6Server;
|
||||
|
||||
+ (instancetype)config:(NSDictionary *)info;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface QNServerDnsConfig : NSObject
|
||||
|
||||
@property(nonatomic, strong, readonly)NSNumber *enable;
|
||||
@property(nonatomic, assign, readonly)long clearId;
|
||||
@property(nonatomic, assign, readonly)BOOL clearCache;
|
||||
@property(nonatomic, strong, readonly)QNServerUdpDnsConfig *udpConfig;
|
||||
@property(nonatomic, strong, readonly)QNServerDohConfig *dohConfig;
|
||||
|
||||
+ (instancetype)config:(NSDictionary *)info;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface QNConnectCheckConfig : NSObject
|
||||
|
||||
@property(nonatomic, assign, readonly)BOOL isOverride;
|
||||
@property(nonatomic, strong, readonly)NSNumber *enable;
|
||||
@property(nonatomic, strong, readonly)NSNumber *timeoutMs;
|
||||
@property(nonatomic, strong, readonly)NSArray <NSString *> *urls;
|
||||
|
||||
+ (instancetype)config:(NSDictionary *)info;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface QNServerConfig : NSObject<QNCacheObject>
|
||||
|
||||
@property(nonatomic, assign, readonly)BOOL isValid;
|
||||
@property(nonatomic, assign, readonly)long ttl;
|
||||
@property(nonatomic, strong, readonly)QNServerRegionConfig *regionConfig;
|
||||
@property(nonatomic, strong, readonly)QNServerDnsConfig *dnsConfig;
|
||||
@property(nonatomic, strong, readonly)QNConnectCheckConfig *connectCheckConfig;
|
||||
|
||||
@property(nonatomic, strong, readonly)NSDictionary *info;
|
||||
|
||||
+ (instancetype)config:(NSDictionary *)info;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
160
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfig.m
generated
Normal file
160
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfig.m
generated
Normal file
@@ -0,0 +1,160 @@
|
||||
//
|
||||
// QNServerConfig.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2021/8/30.
|
||||
// Copyright © 2021 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNServerConfig.h"
|
||||
|
||||
@interface QNServerRegionConfig()
|
||||
@property(nonatomic, assign)long clearId;
|
||||
@property(nonatomic, assign)BOOL clearCache;
|
||||
@end
|
||||
@implementation QNServerRegionConfig
|
||||
+ (instancetype)config:(NSDictionary *)info {
|
||||
QNServerRegionConfig *config = [[QNServerRegionConfig alloc] init];
|
||||
config.clearId = [info[@"clear_id"] longValue];
|
||||
config.clearCache = [info[@"clear_cache"] longValue];
|
||||
return config;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface QNServerDnsServer()
|
||||
@property(nonatomic, assign)BOOL isOverride;
|
||||
@property(nonatomic, strong)NSArray <NSString *> *servers;
|
||||
@end
|
||||
@implementation QNServerDnsServer
|
||||
+ (instancetype)config:(NSDictionary *)info {
|
||||
QNServerDnsServer *config = [[QNServerDnsServer alloc] init];
|
||||
config.isOverride = [info[@"override_default"] boolValue];
|
||||
if (info[@"ips"] && [info[@"ips"] isKindOfClass:[NSArray class]]) {
|
||||
config.servers = info[@"ips"];
|
||||
} else if ([info[@"urls"] isKindOfClass:[NSArray class]]){
|
||||
config.servers = info[@"urls"];
|
||||
}
|
||||
return config;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface QNServerDohConfig()
|
||||
@property(nonatomic, strong)NSNumber *enable;
|
||||
@property(nonatomic, strong)QNServerDnsServer *ipv4Server;
|
||||
@property(nonatomic, strong)QNServerDnsServer *ipv6Server;
|
||||
@end
|
||||
@implementation QNServerDohConfig
|
||||
+ (instancetype)config:(NSDictionary *)info {
|
||||
QNServerDohConfig *config = [[QNServerDohConfig alloc] init];
|
||||
config.enable = info[@"enabled"];
|
||||
config.ipv4Server = [QNServerDnsServer config:info[@"ipv4"]];
|
||||
config.ipv6Server = [QNServerDnsServer config:info[@"ipv6"]];
|
||||
return config;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface QNServerUdpDnsConfig()
|
||||
@property(nonatomic, strong)NSNumber *enable;
|
||||
@property(nonatomic, strong)QNServerDnsServer *ipv4Server;
|
||||
@property(nonatomic, strong)QNServerDnsServer *ipv6Server;
|
||||
@end
|
||||
@implementation QNServerUdpDnsConfig
|
||||
+ (instancetype)config:(NSDictionary *)info {
|
||||
QNServerUdpDnsConfig *config = [[QNServerUdpDnsConfig alloc] init];
|
||||
config.enable = info[@"enabled"];
|
||||
config.ipv4Server = [QNServerDnsServer config:info[@"ipv4"]];
|
||||
config.ipv6Server = [QNServerDnsServer config:info[@"ipv6"]];
|
||||
return config;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@interface QNServerDnsConfig()
|
||||
@property(nonatomic, strong)NSNumber *enable;
|
||||
@property(nonatomic, assign)long clearId;
|
||||
@property(nonatomic, assign)BOOL clearCache;
|
||||
@property(nonatomic, strong)QNServerUdpDnsConfig *udpConfig;
|
||||
@property(nonatomic, strong)QNServerDohConfig *dohConfig;
|
||||
@end
|
||||
@implementation QNServerDnsConfig
|
||||
+ (instancetype)config:(NSDictionary *)info {
|
||||
QNServerDnsConfig *config = [[QNServerDnsConfig alloc] init];
|
||||
config.enable = info[@"enabled"];
|
||||
config.clearId = [info[@"clear_id"] longValue];
|
||||
config.clearCache = [info[@"clear_cache"] longValue];
|
||||
config.dohConfig = [QNServerDohConfig config:info[@"doh"]];
|
||||
config.udpConfig = [QNServerUdpDnsConfig config:info[@"udp"]];
|
||||
return config;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@interface QNConnectCheckConfig()
|
||||
@property(nonatomic, assign)BOOL isOverride;
|
||||
@property(nonatomic, strong)NSNumber *enable;
|
||||
@property(nonatomic, strong)NSNumber *timeoutMs;
|
||||
@property(nonatomic, strong)NSArray <NSString *> *urls;
|
||||
@end
|
||||
@implementation QNConnectCheckConfig
|
||||
+ (instancetype)config:(NSDictionary *)info {
|
||||
QNConnectCheckConfig *config = [[QNConnectCheckConfig alloc] init];
|
||||
config.isOverride = [info[@"override_default"] boolValue];
|
||||
config.enable = info[@"enabled"];
|
||||
config.timeoutMs = info[@"timeout_ms"];
|
||||
if (info[@"urls"] && [info[@"urls"] isKindOfClass:[NSArray class]]) {
|
||||
config.urls = info[@"urls"];
|
||||
}
|
||||
return config;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@interface QNServerConfig()
|
||||
@property(nonatomic, strong)NSDictionary *info;
|
||||
@property(nonatomic, assign)double timestamp;
|
||||
@property(nonatomic, assign)long ttl;
|
||||
@property(nonatomic, strong)QNServerRegionConfig *regionConfig;
|
||||
@property(nonatomic, strong)QNServerDnsConfig *dnsConfig;
|
||||
@property(nonatomic, strong)QNConnectCheckConfig *connectCheckConfig;
|
||||
@end
|
||||
@implementation QNServerConfig
|
||||
|
||||
+ (instancetype)config:(NSDictionary *)info {
|
||||
return [[QNServerConfig alloc] initWithDictionary:info];
|
||||
}
|
||||
|
||||
- (nonnull id<QNCacheObject>)initWithDictionary:(nullable NSDictionary *)info {
|
||||
if (self = [self init]) {
|
||||
if (info) {
|
||||
self.ttl = [info[@"ttl"] longValue];
|
||||
self.regionConfig = [QNServerRegionConfig config:info[@"region"]];
|
||||
self.dnsConfig = [QNServerDnsConfig config:info[@"dns"]];
|
||||
self.connectCheckConfig = [QNConnectCheckConfig config:info[@"connection_check"]];
|
||||
|
||||
if (self.ttl < 10) {
|
||||
self.ttl = 10;
|
||||
}
|
||||
|
||||
NSMutableDictionary *mutableInfo = [info mutableCopy];
|
||||
if (info[@"timestamp"] != nil) {
|
||||
self.timestamp = [info[@"timestamp"] doubleValue];
|
||||
}
|
||||
if (self.timestamp == 0) {
|
||||
self.timestamp = [[NSDate date] timeIntervalSince1970];
|
||||
mutableInfo[@"timestamp"] = @(self.timestamp);
|
||||
}
|
||||
self.info = [mutableInfo copy];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable NSDictionary *)toDictionary {
|
||||
return [self.info copy];
|
||||
}
|
||||
|
||||
- (BOOL)isValid {
|
||||
return [[NSDate date] timeIntervalSince1970] < (self.timestamp + self.ttl);
|
||||
}
|
||||
|
||||
@end
|
||||
29
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigCache.h
generated
Normal file
29
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigCache.h
generated
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// QNServerConfigCache.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2021/8/30.
|
||||
// Copyright © 2021 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNServerConfig.h"
|
||||
#import "QNServerUserConfig.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QNServerConfigCache : NSObject
|
||||
|
||||
@property(nonatomic, strong)QNServerConfig *config;
|
||||
@property(nonatomic, strong)QNServerUserConfig *userConfig;
|
||||
|
||||
- (QNServerConfig *)getConfigFromDisk;
|
||||
- (void)saveConfigToDisk:(QNServerConfig *)config;
|
||||
|
||||
- (QNServerUserConfig *)getUserConfigFromDisk;
|
||||
- (void)saveUserConfigToDisk:(QNServerUserConfig *)config;
|
||||
|
||||
- (void)removeConfigCache;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
65
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigCache.m
generated
Normal file
65
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigCache.m
generated
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// QNServerConfigCache.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2021/8/30.
|
||||
// Copyright © 2021 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNServerConfigCache.h"
|
||||
#import "QNUtils.h"
|
||||
#import "QNCache.h"
|
||||
|
||||
#define kQNServerConfigDiskKey @"config"
|
||||
#define kQNServerUserConfigDiskKey @"userConfig"
|
||||
|
||||
@interface QNServerConfigCache(){
|
||||
QNServerConfig *_config;
|
||||
QNServerUserConfig *_userConfig;
|
||||
}
|
||||
@property(nonatomic, strong) QNCache *configCache;
|
||||
@property(nonatomic, strong) QNCache *userConfigCache;
|
||||
@end
|
||||
@implementation QNServerConfigCache
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
QNCacheOption *option = [[QNCacheOption alloc] init];
|
||||
option.version = @"v1.0.0";
|
||||
self.configCache = [QNCache cache:[QNServerConfig class] option:option];
|
||||
|
||||
option = [[QNCacheOption alloc] init];
|
||||
option.version = @"v1.0.0";
|
||||
self.userConfigCache = [QNCache cache:[QNServerUserConfig class] option:option];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
//MARK: --- config
|
||||
- (QNServerConfig *)getConfigFromDisk {
|
||||
return [self.configCache cacheForKey:kQNServerConfigDiskKey];
|
||||
}
|
||||
|
||||
- (void)saveConfigToDisk:(QNServerConfig *)config {
|
||||
[self.configCache cache:config forKey:kQNServerConfigDiskKey atomically:true];
|
||||
}
|
||||
|
||||
//MARK: --- user config
|
||||
- (QNServerUserConfig *)getUserConfigFromDisk {
|
||||
return [self.userConfigCache cacheForKey:kQNServerUserConfigDiskKey];
|
||||
}
|
||||
|
||||
- (void)saveUserConfigToDisk:(QNServerUserConfig *)config {
|
||||
[self.userConfigCache cache:config forKey:kQNServerUserConfigDiskKey atomically:true];
|
||||
}
|
||||
|
||||
- (void)removeConfigCache {
|
||||
@synchronized (self) {
|
||||
[self.configCache clearMemoryCache];
|
||||
[self.configCache clearDiskCache];
|
||||
[self.userConfigCache clearMemoryCache];
|
||||
[self.userConfigCache clearDiskCache];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
33
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigMonitor.h
generated
Normal file
33
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigMonitor.h
generated
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// QNServerConfiguration.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2021/8/25.
|
||||
// Copyright © 2021 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QNServerConfigMonitor : NSObject
|
||||
|
||||
@property(nonatomic, assign, class)BOOL enable;
|
||||
|
||||
@property(class, nonatomic, strong)NSString *token;
|
||||
|
||||
// 开始监控
|
||||
+ (void)startMonitor;
|
||||
|
||||
// 停止监控
|
||||
+ (void)endMonitor;
|
||||
|
||||
// 配置 token
|
||||
+ (void)setToken:(NSString *)token;
|
||||
|
||||
// 移除缓存
|
||||
+ (void)removeConfigCache;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
237
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigMonitor.m
generated
Normal file
237
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigMonitor.m
generated
Normal file
@@ -0,0 +1,237 @@
|
||||
//
|
||||
// QNServerConfiguration.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2021/8/25.
|
||||
// Copyright © 2021 Qiniu. All rights reserved.
|
||||
//
|
||||
#import "QNLogUtil.h"
|
||||
#import "QNDefine.h"
|
||||
#import "QNAutoZone.h"
|
||||
#import "QNDnsPrefetch.h"
|
||||
#import "QNConfiguration.h"
|
||||
#import "QNServerConfigSynchronizer.h"
|
||||
#import "QNServerConfigCache.h"
|
||||
#import "QNServerConfigMonitor.h"
|
||||
#import "QNTransactionManager.h"
|
||||
|
||||
#define kQNServerConfigTransactionKey @"QNServerConfig"
|
||||
|
||||
@interface QNGlobalConfiguration(DnsDefaultServer)
|
||||
@property(nonatomic, strong)NSArray *defaultConnectCheckUrls;
|
||||
@property(nonatomic, strong)NSArray *defaultDohIpv4Servers;
|
||||
@property(nonatomic, strong)NSArray *defaultDohIpv6Servers;
|
||||
@property(nonatomic, strong)NSArray *defaultUdpDnsIpv4Servers;
|
||||
@property(nonatomic, strong)NSArray *defaultUdpDnsIpv6Servers;
|
||||
@end
|
||||
@implementation QNGlobalConfiguration(DnsDefaultServer)
|
||||
@dynamic defaultConnectCheckUrls;
|
||||
@dynamic defaultDohIpv4Servers;
|
||||
@dynamic defaultDohIpv6Servers;
|
||||
@dynamic defaultUdpDnsIpv4Servers;
|
||||
@dynamic defaultUdpDnsIpv6Servers;
|
||||
@end
|
||||
|
||||
@interface QNServerConfigMonitor()
|
||||
|
||||
@property(nonatomic, assign)BOOL enable;
|
||||
@property(nonatomic, strong)QNServerConfigCache *cache;
|
||||
|
||||
@end
|
||||
@implementation QNServerConfigMonitor
|
||||
+ (instancetype)share {
|
||||
static QNServerConfigMonitor *monitor = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
monitor = [[QNServerConfigMonitor alloc] init];
|
||||
});
|
||||
return monitor;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_enable = true;
|
||||
_cache = [[QNServerConfigCache alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (BOOL)enable {
|
||||
return [[QNServerConfigMonitor share] enable];
|
||||
}
|
||||
|
||||
+ (void)setEnable:(BOOL)enable {
|
||||
[QNServerConfigMonitor share].enable = enable;
|
||||
}
|
||||
|
||||
+ (NSString *)token {
|
||||
return QNServerConfigSynchronizer.token;
|
||||
}
|
||||
|
||||
// 配置 token
|
||||
+ (void)setToken:(NSString *)token {
|
||||
QNServerConfigSynchronizer.token = token;
|
||||
}
|
||||
|
||||
// 开始监控
|
||||
+ (void)startMonitor {
|
||||
if (![QNServerConfigMonitor share].enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
@synchronized (self) {
|
||||
BOOL isExist = [kQNTransactionManager existTransactionsForName:kQNServerConfigTransactionKey];
|
||||
if (isExist) {
|
||||
return;
|
||||
}
|
||||
|
||||
int interval = 120 + arc4random()%240;
|
||||
QNTransaction *transaction = [QNTransaction timeTransaction:kQNServerConfigTransactionKey after:0 interval:interval action:^{
|
||||
[[QNServerConfigMonitor share] monitor];
|
||||
}];
|
||||
[kQNTransactionManager addTransaction:transaction];
|
||||
}
|
||||
}
|
||||
|
||||
// 停止监控
|
||||
+ (void)endMonitor {
|
||||
@synchronized (self) {
|
||||
NSArray *transactions = [kQNTransactionManager transactionsForName:kQNServerConfigTransactionKey];
|
||||
for (QNTransaction *transaction in transactions) {
|
||||
[kQNTransactionManager removeTransaction:transaction];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)removeConfigCache {
|
||||
[[QNServerConfigMonitor share].cache removeConfigCache];
|
||||
}
|
||||
|
||||
- (void)monitor {
|
||||
if (!self.enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.cache.config == nil) {
|
||||
QNServerConfig *config = [self.cache getConfigFromDisk];
|
||||
[self handleServerConfig:config];
|
||||
self.cache.config = config;
|
||||
}
|
||||
|
||||
if (!self.cache.config.isValid) {
|
||||
[QNServerConfigSynchronizer getServerConfigFromServer:^(QNServerConfig * _Nonnull config) {
|
||||
if (config == nil) {
|
||||
return;
|
||||
}
|
||||
[self handleServerConfig:config];
|
||||
self.cache.config = config;
|
||||
[self.cache saveConfigToDisk:config];
|
||||
}];
|
||||
}
|
||||
|
||||
if (self.cache.userConfig == nil) {
|
||||
QNServerUserConfig *config = [self.cache getUserConfigFromDisk];
|
||||
[self handleServerUserConfig:config];
|
||||
self.cache.userConfig = config;
|
||||
}
|
||||
|
||||
if (!self.cache.userConfig.isValid) {
|
||||
[QNServerConfigSynchronizer getServerUserConfigFromServer:^(QNServerUserConfig * _Nonnull config) {
|
||||
if (config == nil) {
|
||||
return;
|
||||
}
|
||||
[self handleServerUserConfig:config];
|
||||
self.cache.userConfig = config;
|
||||
[self.cache saveUserConfigToDisk:config];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleServerConfig:(QNServerConfig *)config {
|
||||
if (config == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 清理 region 缓存
|
||||
if (self.cache.config.regionConfig &&
|
||||
config.regionConfig.clearId > self.cache.config.regionConfig.clearId &&
|
||||
config.regionConfig.clearCache) {
|
||||
QNLogDebug(@"server config: clear region cache");
|
||||
[QNAutoZone clearCache];
|
||||
}
|
||||
|
||||
// dns 配置
|
||||
if (config.dnsConfig.enable) {
|
||||
QNLogDebug(@"server config: dns enable %@", config.dnsConfig.enable);
|
||||
kQNGlobalConfiguration.isDnsOpen = [config.dnsConfig.enable boolValue];
|
||||
}
|
||||
|
||||
// 清理 dns 缓存
|
||||
if (self.cache.config.dnsConfig &&
|
||||
config.dnsConfig.clearId > self.cache.config.dnsConfig.clearId &&
|
||||
config.dnsConfig.clearCache) {
|
||||
QNLogDebug(@"server config: clear dns cache");
|
||||
[kQNDnsPrefetch clearDnsCache:nil];
|
||||
}
|
||||
|
||||
// udp 配置
|
||||
if (config.dnsConfig.udpConfig.enable) {
|
||||
QNLogDebug(@"server config: udp enable %@", config.dnsConfig.udpConfig.enable);
|
||||
kQNGlobalConfiguration.udpDnsEnable = [config.dnsConfig.udpConfig.enable boolValue];
|
||||
}
|
||||
|
||||
if (config.dnsConfig.udpConfig.ipv4Server.isOverride &&
|
||||
[config.dnsConfig.udpConfig.ipv4Server.servers isKindOfClass:[NSArray class]]) {
|
||||
QNLogDebug(@"server config: udp config ipv4Server %@", config.dnsConfig.udpConfig.ipv4Server.servers);
|
||||
kQNGlobalConfiguration.defaultUdpDnsIpv4Servers = [config.dnsConfig.udpConfig.ipv4Server.servers copy];
|
||||
}
|
||||
if (config.dnsConfig.udpConfig.ipv6Server.isOverride &&
|
||||
[config.dnsConfig.udpConfig.ipv6Server.servers isKindOfClass:[NSArray class]]) {
|
||||
QNLogDebug(@"server config: udp config ipv6Server %@", config.dnsConfig.udpConfig.ipv6Server.servers);
|
||||
kQNGlobalConfiguration.defaultUdpDnsIpv6Servers = [config.dnsConfig.udpConfig.ipv6Server.servers copy];
|
||||
}
|
||||
|
||||
// doh 配置
|
||||
if (config.dnsConfig.dohConfig.enable) {
|
||||
kQNGlobalConfiguration.dohEnable = [config.dnsConfig.dohConfig.enable boolValue];
|
||||
QNLogDebug(@"server config: doh enable %@", config.dnsConfig.dohConfig.enable);
|
||||
}
|
||||
if (config.dnsConfig.dohConfig.ipv4Server.isOverride &&
|
||||
[config.dnsConfig.dohConfig.ipv4Server.servers isKindOfClass:[NSArray class]]) {
|
||||
QNLogDebug(@"server config: doh config ipv4Server %@", config.dnsConfig.dohConfig.ipv4Server.servers);
|
||||
kQNGlobalConfiguration.defaultDohIpv4Servers = [config.dnsConfig.dohConfig.ipv4Server.servers copy];
|
||||
}
|
||||
if (config.dnsConfig.dohConfig.ipv6Server.isOverride &&
|
||||
[config.dnsConfig.dohConfig.ipv6Server.servers isKindOfClass:[NSArray class]]) {
|
||||
QNLogDebug(@"server config: doh config ipv6Server %@", config.dnsConfig.dohConfig.ipv6Server.servers);
|
||||
kQNGlobalConfiguration.defaultDohIpv6Servers = [config.dnsConfig.dohConfig.ipv6Server.servers copy];
|
||||
}
|
||||
|
||||
// connect check
|
||||
if (config.connectCheckConfig.enable) {
|
||||
kQNGlobalConfiguration.connectCheckEnable = [config.connectCheckConfig.enable boolValue];
|
||||
QNLogDebug(@"server config: connect check enable %@", config.dnsConfig.dohConfig.enable);
|
||||
}
|
||||
if (config.connectCheckConfig.timeoutMs) {
|
||||
kQNGlobalConfiguration.connectCheckTimeout = [config.connectCheckConfig.timeoutMs doubleValue] / 1000;
|
||||
QNLogDebug(@"server config: connect check timeout %@", config.connectCheckConfig.timeoutMs);
|
||||
}
|
||||
if (config.connectCheckConfig.isOverride &&
|
||||
config.connectCheckConfig.urls &&
|
||||
[config.connectCheckConfig.urls isKindOfClass:[NSArray class]]) {
|
||||
kQNGlobalConfiguration.defaultConnectCheckUrls = config.connectCheckConfig.urls;
|
||||
QNLogDebug(@"server config: connect check urls %@", config.connectCheckConfig.urls);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleServerUserConfig:(QNServerUserConfig *)config {
|
||||
if (config == nil) {
|
||||
return;
|
||||
}
|
||||
if (config.networkCheckEnable) {
|
||||
QNLogDebug(@"server config: connect check enable %@", config.networkCheckEnable);
|
||||
kQNGlobalConfiguration.connectCheckEnable = [config.networkCheckEnable boolValue];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
24
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigSynchronizer.h
generated
Normal file
24
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigSynchronizer.h
generated
Normal file
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// QNServerConfigSynchronizer.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2021/8/30.
|
||||
// Copyright © 2021 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNServerConfig.h"
|
||||
#import "QNServerUserConfig.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QNServerConfigSynchronizer : NSObject
|
||||
|
||||
@property(class, nonatomic, strong)NSString *token;
|
||||
@property(class, nonatomic, strong)NSArray <NSString *> *hosts;
|
||||
|
||||
+ (void)getServerConfigFromServer:(void(^)(QNServerConfig *config))complete;
|
||||
+ (void)getServerUserConfigFromServer:(void(^)(QNServerUserConfig *config))complete;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
158
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigSynchronizer.m
generated
Normal file
158
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerConfigSynchronizer.m
generated
Normal file
@@ -0,0 +1,158 @@
|
||||
//
|
||||
// QNServerConfigSynchronizer.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2021/8/30.
|
||||
// Copyright © 2021 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNConfig.h"
|
||||
#import "QNUpToken.h"
|
||||
#import "QNZoneInfo.h"
|
||||
#import "QNResponseInfo.h"
|
||||
#import "QNRequestTransaction.h"
|
||||
#import "QNServerConfigSynchronizer.h"
|
||||
#import <pthread.h>
|
||||
|
||||
static NSString *Token = nil;
|
||||
static NSArray <NSString *> *Hosts = nil;
|
||||
static pthread_mutex_t TokenMutexLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t HostsMutexLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static QNRequestTransaction *serverConfigTransaction = nil;
|
||||
static QNRequestTransaction *serverUserConfigTransaction = nil;
|
||||
|
||||
@implementation QNServerConfigSynchronizer
|
||||
|
||||
//MARK: --- server config
|
||||
+ (void)getServerConfigFromServer:(void(^)(QNServerConfig *config))complete {
|
||||
if (complete == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
QNRequestTransaction *transaction = [self createServerConfigTransaction];
|
||||
if (transaction == nil) {
|
||||
complete(nil);
|
||||
return;
|
||||
}
|
||||
|
||||
[transaction serverConfig:^(QNResponseInfo * _Nullable responseInfo, QNUploadRegionRequestMetrics * _Nullable metrics, NSDictionary * _Nullable response) {
|
||||
if (responseInfo.isOK && response != nil) {
|
||||
complete([QNServerConfig config:response]);
|
||||
} else {
|
||||
complete(nil);
|
||||
}
|
||||
[self destroyServerConfigRequestTransaction];
|
||||
}];
|
||||
}
|
||||
|
||||
+ (QNRequestTransaction *)createServerConfigTransaction {
|
||||
@synchronized (self) {
|
||||
// 上传时才会有 token,不上传不请求,避免不必要请求
|
||||
if (serverConfigTransaction != nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
QNUpToken *token = [QNUpToken parse:self.token];
|
||||
if (token == nil) {
|
||||
token = [QNUpToken getInvalidToken];
|
||||
}
|
||||
|
||||
NSArray *hosts = self.hosts;
|
||||
if (hosts == nil) {
|
||||
hosts = kQNPreQueryHosts;
|
||||
}
|
||||
QNRequestTransaction *transaction = [[QNRequestTransaction alloc] initWithHosts:hosts
|
||||
regionId:QNZoneInfoEmptyRegionId
|
||||
token:token];
|
||||
serverConfigTransaction = transaction;
|
||||
return transaction;
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)destroyServerConfigRequestTransaction {
|
||||
@synchronized (self) {
|
||||
serverConfigTransaction = nil;
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: --- server user config
|
||||
+ (void)getServerUserConfigFromServer:(void(^)(QNServerUserConfig *config))complete {
|
||||
if (complete == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
QNRequestTransaction *transaction = [self createServerUserConfigTransaction];
|
||||
if (transaction == nil) {
|
||||
complete(nil);
|
||||
return;
|
||||
}
|
||||
|
||||
[transaction serverUserConfig:^(QNResponseInfo * _Nullable responseInfo, QNUploadRegionRequestMetrics * _Nullable metrics, NSDictionary * _Nullable response) {
|
||||
if (responseInfo.isOK && response != nil) {
|
||||
complete([QNServerUserConfig config:response]);
|
||||
} else {
|
||||
complete(nil);
|
||||
}
|
||||
[self destroyServerConfigRequestTransaction];
|
||||
}];
|
||||
}
|
||||
|
||||
+ (QNRequestTransaction *)createServerUserConfigTransaction {
|
||||
@synchronized (self) {
|
||||
if (serverConfigTransaction != nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
QNUpToken *token = [QNUpToken parse:self.token];
|
||||
if (token == nil || !token.isValid) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSArray *hosts = self.hosts;
|
||||
if (hosts == nil) {
|
||||
hosts = kQNPreQueryHosts;
|
||||
}
|
||||
QNRequestTransaction *transaction = [[QNRequestTransaction alloc] initWithHosts:hosts
|
||||
regionId:QNZoneInfoEmptyRegionId
|
||||
token:token];
|
||||
serverUserConfigTransaction = transaction;
|
||||
return transaction;
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)destroyServerUserConfigRequestTransaction {
|
||||
@synchronized (self) {
|
||||
serverUserConfigTransaction = nil;
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)setToken:(NSString *)token {
|
||||
pthread_mutex_lock(&TokenMutexLock);
|
||||
Token = token;
|
||||
pthread_mutex_unlock(&TokenMutexLock);
|
||||
}
|
||||
|
||||
+ (NSString *)token {
|
||||
NSString *token = nil;
|
||||
pthread_mutex_lock(&TokenMutexLock);
|
||||
token = Token;
|
||||
pthread_mutex_unlock(&TokenMutexLock);
|
||||
return token;
|
||||
}
|
||||
|
||||
+ (void)setHosts:(NSArray<NSString *> *)servers {
|
||||
pthread_mutex_lock(&HostsMutexLock);
|
||||
Hosts = [servers copy];
|
||||
pthread_mutex_unlock(&HostsMutexLock);
|
||||
}
|
||||
|
||||
+ (NSArray<NSString *> *)hosts {
|
||||
NSArray<NSString *> *hosts = nil;
|
||||
pthread_mutex_lock(&HostsMutexLock);
|
||||
hosts = [Hosts copy];
|
||||
pthread_mutex_unlock(&HostsMutexLock);
|
||||
return hosts;
|
||||
}
|
||||
|
||||
@end
|
||||
27
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerUserConfig.h
generated
Normal file
27
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerUserConfig.h
generated
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// QNServerUserConfig.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2021/8/30.
|
||||
// Copyright © 2021 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNCache.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QNServerUserConfig : NSObject<QNCacheObject>
|
||||
|
||||
@property(nonatomic, assign, readonly)BOOL isValid;
|
||||
@property(nonatomic, assign, readonly)long ttl;
|
||||
@property(nonatomic, strong, readonly)NSNumber *http3Enable;
|
||||
@property(nonatomic, strong, readonly)NSNumber *networkCheckEnable;
|
||||
|
||||
@property(nonatomic, strong, readonly)NSDictionary *info;
|
||||
|
||||
+ (instancetype)config:(NSDictionary *)info;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
58
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerUserConfig.m
generated
Normal file
58
Pods/Qiniu/QiniuSDK/Storage/ServerConfig/QNServerUserConfig.m
generated
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// QNServerUserConfig.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2021/8/30.
|
||||
// Copyright © 2021 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNServerUserConfig.h"
|
||||
|
||||
@interface QNServerUserConfig()
|
||||
@property(nonatomic, strong)NSDictionary *info;
|
||||
@property(nonatomic, assign)double timestamp;
|
||||
@property(nonatomic, assign)long ttl;
|
||||
@property(nonatomic, strong)NSNumber *http3Enable;
|
||||
@property(nonatomic, strong)NSNumber *retryMax;
|
||||
@property(nonatomic, strong)NSNumber *networkCheckEnable;
|
||||
@end
|
||||
@implementation QNServerUserConfig
|
||||
|
||||
+ (instancetype)config:(NSDictionary *)info {
|
||||
return [[QNServerUserConfig alloc] initWithDictionary:info];
|
||||
}
|
||||
|
||||
- (nonnull id<QNCacheObject>)initWithDictionary:(nullable NSDictionary *)info {
|
||||
if (self = [super init]) {
|
||||
if (info) {
|
||||
self.ttl = [info[@"ttl"] longValue];
|
||||
self.http3Enable = info[@"http3"][@"enabled"];
|
||||
self.networkCheckEnable = info[@"network_check"][@"enabled"];
|
||||
|
||||
if (self.ttl < 10) {
|
||||
self.ttl = 10;
|
||||
}
|
||||
|
||||
NSMutableDictionary *mutableInfo = [info mutableCopy];
|
||||
if (info[@"timestamp"] != nil) {
|
||||
self.timestamp = [info[@"timestamp"] doubleValue];
|
||||
}
|
||||
if (self.timestamp == 0) {
|
||||
self.timestamp = [[NSDate date] timeIntervalSince1970];
|
||||
mutableInfo[@"timestamp"] = @(self.timestamp);
|
||||
}
|
||||
self.info = [mutableInfo copy];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (nullable NSDictionary *)toDictionary {
|
||||
return [self.info copy];
|
||||
}
|
||||
|
||||
- (BOOL)isValid {
|
||||
return [[NSDate date] timeIntervalSince1970] < (self.timestamp + self.ttl);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user