带阿里标识的版本

This commit is contained in:
robin
2026-02-28 18:55:33 +08:00
parent 150799f41d
commit 5d0b7c7e91
477 changed files with 10813 additions and 4044 deletions

View File

@@ -1,9 +1,9 @@
//
// HttpDnsLocker.h
// AlicloudHttpDNS
// TrustHttpDNS
//
// Created by 王贇 on 2023/8/16.
// Copyright © 2023 alibaba-inc.com. All rights reserved.
// Copyright © 2023 trustapp.com. All rights reserved.
//
#ifndef HttpDnsLocker_h

View File

@@ -1,9 +1,9 @@
//
// HttpDnsLocker.m
// AlicloudHttpDNS
// TrustHttpDNS
//
// Created by on 2023/8/16.
// Copyright © 2023 alibaba-inc.com. All rights reserved.
// Copyright © 2023 trustapp.com. All rights reserved.
//
#import "HttpDnsLocker.h"

View File

@@ -1,9 +1,9 @@
//
// HttpdnsHostObjectInMemoryCache.h
// AlicloudHttpDNS
// TrustHttpDNS
//
// Created by xuyecan on 2024/9/28.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -11,10 +11,10 @@
NS_ASSUME_NONNULL_BEGIN
// 这个字典在HTTPDNS中只用于存储HttpdnsHostObject对象这个对象是整个框架的核心对象用于缓存和处理域名解析结
// 通常从缓存中获得这个对象之后,会根据不同场景改变一些字段的值,而且很可能发生在不同线程
// 这个字典在HTTPDNS中只用于存储HttpdnsHostObject对象这个对象是整个框架的核心对象用于缓存和处理域名解析结<EFBFBD><EFBFBD>?
// 通常从缓存中获得这个对象之后,会根据不同场景改变一些字段的值,而且很可能发生在不同线程<EFBFBD><EFBFBD>?
// 而不同线程从缓存中直接读取共享对象的话很有可能发生线程竞争的情况多线程访问某个对象的同一个字段在swift环境有较高概率发生crash
// 因此除了确保字典操作的线程安全拿出对象的时候也直接copy一个复制对象返回(HttpdnsHostObject对象实现了NSCopying协议)
// 因此除了确保字典操作的线程安全拿出对象的时候也直接copy一个复制对象返<EFBFBD><EFBFBD>?HttpdnsHostObject对象实现了NSCopying协议)
@interface HttpdnsHostObjectInMemoryCache : NSObject
- (void)setHostObject:(HttpdnsHostObject *)object forCacheKey:(NSString *)key;

View File

@@ -1,9 +1,9 @@
//
// HttpdnsHostObjectInMemoryCache.m
// AlicloudHttpDNS
// TrustHttpDNS
//
// Created by xuyecan on 2024/9/28.
// Copyright © 2024 alibaba-inc.com. All rights reserved.
// Copyright © 2024 trustapp.com. All rights reserved.
//
#import "HttpdnsHostObjectInMemoryCache.h"

View File

@@ -1,9 +1,9 @@
//
// HttpdnsIPQualityDetector.h
// AlicloudHttpDNS
// TrustHttpDNS
//
// Created by xuyecan on 2025/3/13.
// Copyright © 2025 alibaba-inc.com. All rights reserved.
// Copyright © 2025 trustapp.com. All rights reserved.
//
#import <Foundation/Foundation.h>
@@ -11,10 +11,10 @@
NS_ASSUME_NONNULL_BEGIN
/**
* IP质量检测回
* @param cacheKey 缓存
* IP质量检测回<EFBFBD><EFBFBD>?
* @param cacheKey 缓存<EFBFBD><EFBFBD>?
* @param ip IP地址
* @param costTime 连接耗时(毫秒)-1表示连接失败
* @param costTime 连接耗时(毫秒)<EFBFBD><EFBFBD>?1表示连接失败
*/
typedef void(^HttpdnsIPQualityCallback)(NSString *cacheKey, NSString *ip, NSInteger costTime);
@@ -32,10 +32,10 @@ typedef void(^HttpdnsIPQualityCallback)(NSString *cacheKey, NSString *ip, NSInte
/**
* 调度一个IP连接质量检测任务不会阻塞当前线程
* @param cacheKey 缓存键,通常是域
* @param cacheKey 缓存键,通常是域<EFBFBD><EFBFBD>?
* @param ip 要检测的IP地址
* @param port 连接端口如果为nil则默认使用80
* @param callback 检测完成后的回
* @param port 连接端口如果为nil则默认使<EFBFBD><EFBFBD>?0
* @param callback 检测完成后的回<EFBFBD><EFBFBD>?
*/
- (void)scheduleIPQualityDetection:(NSString *)cacheKey
ip:(NSString *)ip
@@ -45,12 +45,12 @@ typedef void(^HttpdnsIPQualityCallback)(NSString *cacheKey, NSString *ip, NSInte
#pragma mark - Methods exposed for testing
/**
* 执行IP连接质量检
* @param cacheKey 缓存键,通常是域
* 执行IP连接质量检<EFBFBD><EFBFBD>?
* @param cacheKey 缓存键,通常是域<EFBFBD><EFBFBD>?
* @param ip 要检测的IP地址
* @param port 连接端口如果为nil则默认使用80
* @param callback 检测完成后的回
* @note 此方法主要用于测
* @param port 连接端口如果为nil则默认使<EFBFBD><EFBFBD>?0
* @param callback 检测完成后的回<EFBFBD><EFBFBD>?
* @note 此方法主要用于测<EFBFBD><EFBFBD>?
*/
- (void)executeDetection:(NSString *)cacheKey
ip:(NSString *)ip
@@ -58,21 +58,21 @@ typedef void(^HttpdnsIPQualityCallback)(NSString *cacheKey, NSString *ip, NSInte
callback:(HttpdnsIPQualityCallback)callback;
/**
* 建立TCP连接并测量连接时
* 建立TCP连接并测量连接时<EFBFBD><EFBFBD>?
* @param ip 要连接的IP地址
* @param port 连接端口
* @return 连接耗时(毫秒)-1表示连接失败
* @note 此方法主要用于测
* @return 连接耗时(毫秒)<EFBFBD><EFBFBD>?1表示连接失败
* @note 此方法主要用于测<EFBFBD><EFBFBD>?
*/
- (NSInteger)tcpConnectToIP:(NSString *)ip port:(int)port;
/**
* 添加待处理任
* @param cacheKey 缓存键,通常是域
* 添加待处理任<EFBFBD><EFBFBD>?
* @param cacheKey 缓存键,通常是域<EFBFBD><EFBFBD>?
* @param ip 要检测的IP地址
* @param port 连接端口
* @param callback 检测完成后的回
* @note 此方法主要用于测
* @param callback 检测完成后的回<EFBFBD><EFBFBD>?
* @note 此方法主要用于测<EFBFBD><EFBFBD>?
*/
- (void)addPendingTask:(NSString *)cacheKey
ip:(NSString *)ip
@@ -80,14 +80,14 @@ typedef void(^HttpdnsIPQualityCallback)(NSString *cacheKey, NSString *ip, NSInte
callback:(HttpdnsIPQualityCallback)callback;
/**
* 处理待处理任务队
* @note 此方法主要用于测
* 处理待处理任务队<EFBFBD><EFBFBD>?
* @note 此方法主要用于测<EFBFBD><EFBFBD>?
*/
- (void)processPendingTasksIfNeeded;
/**
* 处理所有待处理任务
* @note 此方法主要用于测
* @note 此方法主要用于测<EFBFBD><EFBFBD>?
*/
- (void)processPendingTasks;

View File

@@ -463,7 +463,7 @@ static void TMReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRea
return HttpdnsReachableVia5G;
}
}
// 使广4G
// 使广<EFBFBD><EFBFBD>?G
return HttpdnsReachableVia4G;
#endif
}

View File

@@ -222,8 +222,8 @@
/**
sessionId
App
sessionId12base62
App<EFBFBD><EFBFBD>?
sessionId<EFBFBD><EFBFBD>?2base62
*/
+ (NSString *)generateSessionID {
static NSString *sessionId = nil;
@@ -256,11 +256,11 @@
+ (NSData *)encryptDataAESCBC:(NSData *)plaintext
withKey:(NSData *)key
error:(NSError **)error {
//
// <EFBFBD><EFBFBD>?
if (plaintext == nil || [plaintext length] == 0 || key == nil || [key length] != kCCKeySizeAES128) {
if (error) {
*error = [NSError errorWithDomain:ALICLOUD_HTTPDNS_ERROR_DOMAIN
code:ALICLOUD_HTTPDNS_ENCRYPT_INVALID_PARAMS_ERROR_CODE
*error = [NSError errorWithDomain:Trust_HTTPDNS_ERROR_DOMAIN
code:Trust_HTTPDNS_ENCRYPT_INVALID_PARAMS_ERROR_CODE
userInfo:@{NSLocalizedDescriptionKey: @"Invalid input parameters"}];
}
return nil;
@@ -271,18 +271,18 @@
int result = SecRandomCopyBytes(kSecRandomDefault, kCCBlockSizeAES128, iv.mutableBytes);
if (result != 0) {
if (error) {
*error = [NSError errorWithDomain:ALICLOUD_HTTPDNS_ERROR_DOMAIN
code:ALICLOUD_HTTPDNS_ENCRYPT_RANDOM_IV_ERROR_CODE
*error = [NSError errorWithDomain:Trust_HTTPDNS_ERROR_DOMAIN
code:Trust_HTTPDNS_ENCRYPT_RANDOM_IV_ERROR_CODE
userInfo:@{NSLocalizedDescriptionKey: @"Failed to generate random IV"}];
}
return nil;
}
// ()
// (<EFBFBD><EFBFBD>?
size_t bufferSize = [plaintext length] + kCCBlockSizeAES128;
size_t encryptedSize = 0;
//
// <EFBFBD><EFBFBD>?
NSMutableData *cipherData = [NSMutableData dataWithLength:bufferSize];
//
@@ -301,17 +301,17 @@
if (cryptStatus != kCCSuccess) {
if (error) {
*error = [NSError errorWithDomain:ALICLOUD_HTTPDNS_ERROR_DOMAIN
code:ALICLOUD_HTTPDNS_ENCRYPT_FAILED_ERROR_CODE
*error = [NSError errorWithDomain:Trust_HTTPDNS_ERROR_DOMAIN
code:Trust_HTTPDNS_ENCRYPT_FAILED_ERROR_CODE
userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Encryption failed with status: %d", cryptStatus]}];
}
return nil;
}
//
// <EFBFBD><EFBFBD>?
[cipherData setLength:encryptedSize];
// IV
// IV<EFBFBD><EFBFBD>?
NSMutableData *resultData = [NSMutableData dataWithData:iv];
[resultData appendData:cipherData];
@@ -338,7 +338,7 @@
return nil;
}
//
// <EFBFBD><EFBFBD>?
NSString *cleanedString = [hexString stringByReplacingOccurrencesOfString:@" " withString:@""];
//
@@ -391,25 +391,25 @@
+ (NSData *)decryptDataAESCBC:(NSData *)ciphertext
withKey:(NSData *)key
error:(NSError **)error {
//
// <EFBFBD><EFBFBD>?
if (ciphertext == nil || [ciphertext length] <= kCCBlockSizeAES128 || key == nil || [key length] != kCCKeySizeAES128) {
if (error) {
*error = [NSError errorWithDomain:ALICLOUD_HTTPDNS_ERROR_DOMAIN
code:ALICLOUD_HTTPDNS_ENCRYPT_INVALID_PARAMS_ERROR_CODE
*error = [NSError errorWithDomain:Trust_HTTPDNS_ERROR_DOMAIN
code:Trust_HTTPDNS_ENCRYPT_INVALID_PARAMS_ERROR_CODE
userInfo:@{NSLocalizedDescriptionKey: @"Invalid input parameters for decryption"}];
}
return nil;
}
// IV16
// IV16<EFBFBD><EFBFBD>?
NSData *iv = [ciphertext subdataWithRange:NSMakeRange(0, kCCBlockSizeAES128)];
NSData *actualCiphertext = [ciphertext subdataWithRange:NSMakeRange(kCCBlockSizeAES128, ciphertext.length - kCCBlockSizeAES128)];
//
// <EFBFBD><EFBFBD>?
size_t bufferSize = actualCiphertext.length + kCCBlockSizeAES128;
size_t decryptedSize = 0;
//
// <EFBFBD><EFBFBD>?
NSMutableData *decryptedData = [NSMutableData dataWithLength:bufferSize];
//
@@ -427,14 +427,14 @@
if (cryptStatus != kCCSuccess) {
if (error) {
*error = [NSError errorWithDomain:ALICLOUD_HTTPDNS_ERROR_DOMAIN
code:ALICLOUD_HTTPDNS_ENCRYPT_FAILED_ERROR_CODE
*error = [NSError errorWithDomain:Trust_HTTPDNS_ERROR_DOMAIN
code:Trust_HTTPDNS_ENCRYPT_FAILED_ERROR_CODE
userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Decryption failed with status: %d", cryptStatus]}];
}
return nil;
}
//
// <EFBFBD><EFBFBD>?
[decryptedData setLength:decryptedSize];
return decryptedData;
@@ -453,14 +453,14 @@
if (dnsService.ttlDelegate && [dnsService.ttlDelegate respondsToSelector:@selector(httpdnsHost:ipType:ttl:)]) {
if ([self isNotEmptyArray:[hostObject getV4Ips]]) {
int64_t customV4TTL = [dnsService.ttlDelegate httpdnsHost:host ipType:AlicloudHttpDNS_IPTypeV4 ttl:hostObject.v4ttl];
int64_t customV4TTL = [dnsService.ttlDelegate httpdnsHost:host ipType:TrustHttpDNS_IPTypeV4 ttl:hostObject.v4ttl];
if (customV4TTL > 0) {
hostObject.v4ttl = customV4TTL;
}
}
if ([self isNotEmptyArray:[hostObject getV6Ips]]) {
int64_t customV6TTL = [dnsService.ttlDelegate httpdnsHost:host ipType:AlicloudHttpDNS_IPTypeV6 ttl:hostObject.v6ttl];
int64_t customV6TTL = [dnsService.ttlDelegate httpdnsHost:host ipType:TrustHttpDNS_IPTypeV6 ttl:hostObject.v6ttl];
if (customV6TTL > 0) {
hostObject.v6ttl = customV6TTL;
}