mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
commit
6fa3948d22
@ -31,6 +31,7 @@
|
|||||||
- (void)mtProto:(MTProto *)mtProto protocolErrorReceived:(int32_t)errorCode;
|
- (void)mtProto:(MTProto *)mtProto protocolErrorReceived:(int32_t)errorCode;
|
||||||
- (bool)mtProto:(MTProto *)mtProto shouldRequestMessageWithId:(int64_t)responseMessageId inResponseToMessageId:(int64_t)messageId currentTransactionId:(id)currentTransactionId;
|
- (bool)mtProto:(MTProto *)mtProto shouldRequestMessageWithId:(int64_t)responseMessageId inResponseToMessageId:(int64_t)messageId currentTransactionId:(id)currentTransactionId;
|
||||||
- (void)mtProto:(MTProto *)mtProto updateReceiveProgressForToken:(id)progressToken progress:(float)progress packetLength:(NSInteger)packetLength;
|
- (void)mtProto:(MTProto *)mtProto updateReceiveProgressForToken:(id)progressToken progress:(float)progress packetLength:(NSInteger)packetLength;
|
||||||
|
- (void)mtProtoTransportActivityUpdated:(MTProto *)mtProto;
|
||||||
|
|
||||||
- (void)mtProtoNetworkAvailabilityChanged:(MTProto *)mtProto isNetworkAvailable:(bool)isNetworkAvailable;
|
- (void)mtProtoNetworkAvailabilityChanged:(MTProto *)mtProto isNetworkAvailable:(bool)isNetworkAvailable;
|
||||||
- (void)mtProtoConnectionStateChanged:(MTProto *)mtProto isConnected:(bool)isConnected;
|
- (void)mtProtoConnectionStateChanged:(MTProto *)mtProto isConnected:(bool)isConnected;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
@property (nonatomic) bool hasHighPriority;
|
@property (nonatomic) bool hasHighPriority;
|
||||||
@property (nonatomic) bool dependsOnPasswordEntry;
|
@property (nonatomic) bool dependsOnPasswordEntry;
|
||||||
@property (nonatomic) bool passthroughPasswordEntryError;
|
@property (nonatomic) bool passthroughPasswordEntryError;
|
||||||
|
@property (nonatomic) bool needsTimeoutTimer;
|
||||||
|
|
||||||
@property (nonatomic, copy) void (^completed)(id result, NSTimeInterval completionTimestamp, MTRpcError *error);
|
@property (nonatomic, copy) void (^completed)(id result, NSTimeInterval completionTimestamp, MTRpcError *error);
|
||||||
@property (nonatomic, copy) void (^progressUpdated)(float progress, NSUInteger packetLength);
|
@property (nonatomic, copy) void (^progressUpdated)(float progress, NSUInteger packetLength);
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
- (void)transportDecodeProgressToken:(MTTransport * _Nonnull)transport scheme:(MTTransportScheme * _Nonnull)scheme data:(NSData * _Nonnull)data token:(int64_t)token completion:(void (^ _Nonnull)(int64_t token, id _Nonnull progressToken))completion;
|
- (void)transportDecodeProgressToken:(MTTransport * _Nonnull)transport scheme:(MTTransportScheme * _Nonnull)scheme data:(NSData * _Nonnull)data token:(int64_t)token completion:(void (^ _Nonnull)(int64_t token, id _Nonnull progressToken))completion;
|
||||||
- (void)transportUpdatedDataReceiveProgress:(MTTransport * _Nonnull)transport progressToken:(id _Nonnull)progressToken packetLength:(NSInteger)packetLength progress:(float)progress;
|
- (void)transportUpdatedDataReceiveProgress:(MTTransport * _Nonnull)transport progressToken:(id _Nonnull)progressToken packetLength:(NSInteger)packetLength progress:(float)progress;
|
||||||
|
|
||||||
|
- (void)transportActivityUpdated:(MTTransport * _Nonnull)transport;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface MTTransport : NSObject <MTMessageService>
|
@interface MTTransport : NSObject <MTMessageService>
|
||||||
|
@ -1926,6 +1926,20 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64;
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)transportActivityUpdated:(MTTransport * _Nonnull)transport {
|
||||||
|
[[MTProto managerQueue] dispatchOnQueue:^
|
||||||
|
{
|
||||||
|
if (transport != _transport)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (id<MTMessageService> messageService in _messageServices)
|
||||||
|
{
|
||||||
|
if ([messageService respondsToSelector:@selector(mtProtoTransportActivityUpdated:)])
|
||||||
|
[messageService mtProtoTransportActivityUpdated:self];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)transportTransactionsSucceeded:(NSArray *)transactionIds
|
- (void)transportTransactionsSucceeded:(NSArray *)transactionIds
|
||||||
{
|
{
|
||||||
[[MTProto managerQueue] dispatchOnQueue:^
|
[[MTProto managerQueue] dispatchOnQueue:^
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
NSMutableArray *_dropReponseContexts;
|
NSMutableArray *_dropReponseContexts;
|
||||||
|
|
||||||
MTTimer *_requestsServiceTimer;
|
MTTimer *_requestsServiceTimer;
|
||||||
|
MTTimer *_requestsTimeoutTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -72,6 +73,10 @@
|
|||||||
[_requestsServiceTimer invalidate];
|
[_requestsServiceTimer invalidate];
|
||||||
_requestsServiceTimer = nil;
|
_requestsServiceTimer = nil;
|
||||||
}
|
}
|
||||||
|
if (_requestsTimeoutTimer != nil) {
|
||||||
|
[_requestsTimeoutTimer invalidate];
|
||||||
|
_requestsTimeoutTimer = nil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addRequest:(MTRequest *)request
|
- (void)addRequest:(MTRequest *)request
|
||||||
@ -147,6 +152,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
[self updateRequestsTimer];
|
[self updateRequestsTimer];
|
||||||
|
[self updateRequestsTimeoutTimerWithReset:false];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,6 +273,75 @@
|
|||||||
[mtProto requestTransportTransaction];
|
[mtProto requestTransportTransaction];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)updateRequestsTimeoutTimerWithReset:(bool)reset {
|
||||||
|
CFAbsoluteTime currentTime = MTAbsoluteSystemTime();
|
||||||
|
|
||||||
|
bool needTimer = false;
|
||||||
|
|
||||||
|
for (MTRequest *request in _requests) {
|
||||||
|
if (!request.needsTimeoutTimer) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (request.errorContext != nil) {
|
||||||
|
if (request.errorContext.waitingForRequestToComplete != nil) {
|
||||||
|
bool foundDependency = false;
|
||||||
|
for (MTRequest *anotherRequest in _requests) {
|
||||||
|
if (request.errorContext.waitingForRequestToComplete == anotherRequest.internalId) {
|
||||||
|
foundDependency = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundDependency) {
|
||||||
|
needTimer = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.requestContext == nil) {
|
||||||
|
if (request.errorContext.minimalExecuteTime > currentTime + DBL_EPSILON) {
|
||||||
|
} else {
|
||||||
|
request.errorContext.minimalExecuteTime = 0.0;
|
||||||
|
needTimer = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
needTimer = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needTimer) {
|
||||||
|
if (reset) {
|
||||||
|
if (_requestsTimeoutTimer != nil) {
|
||||||
|
[_requestsTimeoutTimer invalidate];
|
||||||
|
_requestsTimeoutTimer = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_requestsTimeoutTimer == nil) {
|
||||||
|
__weak MTRequestMessageService *weakSelf = self;
|
||||||
|
_requestsTimeoutTimer = [[MTTimer alloc] initWithTimeout:5.0 repeat:false completion:^
|
||||||
|
{
|
||||||
|
__strong MTRequestMessageService *strongSelf = weakSelf;
|
||||||
|
[strongSelf requestTimerTimeoutEvent];
|
||||||
|
} queue:_queue.nativeQueue];
|
||||||
|
[_requestsTimeoutTimer start];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (_requestsTimeoutTimer != nil) {
|
||||||
|
[_requestsTimeoutTimer invalidate];
|
||||||
|
_requestsTimeoutTimer = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)requestTimerTimeoutEvent {
|
||||||
|
MTProto *mtProto = _mtProto;
|
||||||
|
if (mtProto) {
|
||||||
|
[mtProto requestSecureTransportReset];
|
||||||
|
[mtProto requestTransportTransaction];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)mtProtoWillAddService:(MTProto *)mtProto
|
- (void)mtProtoWillAddService:(MTProto *)mtProto
|
||||||
{
|
{
|
||||||
_queue = [mtProto messageServiceQueue];
|
_queue = [mtProto messageServiceQueue];
|
||||||
@ -824,6 +899,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
[self updateRequestsTimer];
|
[self updateRequestsTimer];
|
||||||
|
[self updateRequestsTimeoutTimerWithReset:false];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -840,6 +916,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)mtProtoTransportActivityUpdated:(MTProto *) __unused mtProto {
|
||||||
|
[self updateRequestsTimeoutTimerWithReset:true];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)mtProto:(MTProto *)__unused mtProto messageDeliveryConfirmed:(NSArray *)messageIds
|
- (void)mtProto:(MTProto *)__unused mtProto messageDeliveryConfirmed:(NSArray *)messageIds
|
||||||
{
|
{
|
||||||
for (NSNumber *nMessageId in messageIds)
|
for (NSNumber *nMessageId in messageIds)
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
- (void)tcpConnectionReceivedQuickAck:(MTTcpConnection *)connection quickAck:(int32_t)quickAck;
|
- (void)tcpConnectionReceivedQuickAck:(MTTcpConnection *)connection quickAck:(int32_t)quickAck;
|
||||||
- (void)tcpConnectionDecodePacketProgressToken:(MTTcpConnection *)connection data:(NSData *)data token:(int64_t)token completion:(void (^)(int64_t token, id packetProgressToken))completion;
|
- (void)tcpConnectionDecodePacketProgressToken:(MTTcpConnection *)connection data:(NSData *)data token:(int64_t)token completion:(void (^)(int64_t token, id packetProgressToken))completion;
|
||||||
- (void)tcpConnectionProgressUpdated:(MTTcpConnection *)connection packetProgressToken:(id)packetProgressToken packetLength:(NSUInteger)packetLength progress:(float)progress;
|
- (void)tcpConnectionProgressUpdated:(MTTcpConnection *)connection packetProgressToken:(id)packetProgressToken packetLength:(NSUInteger)packetLength progress:(float)progress;
|
||||||
|
- (void)tcpConnectionDownloadActivityUpdated:(MTTcpConnection *)connection;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -606,6 +606,118 @@ struct ctr_state {
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@protocol MTTcpConnectionInterface;
|
||||||
|
|
||||||
|
@protocol MTTcpConnectionInterfaceDelegate <NSObject>
|
||||||
|
|
||||||
|
- (void)connectionInterface:(id<MTTcpConnectionInterface>)connectionInterface didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag;
|
||||||
|
- (void)connectionInterface:(id<MTTcpConnectionInterface>)connectionInterface didReadData:(NSData *)rawData withTag:(long)tag;
|
||||||
|
- (void)connectionInterface:(id<MTTcpConnectionInterface>)connectionInterface didConnectToHost:(NSString *)host port:(uint16_t)port;
|
||||||
|
- (void)connectionInterfaceDidDisconnect:(id<MTTcpConnectionInterface>)connectionInterface withError:(NSError *)error;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@protocol MTTcpConnectionInterface<NSObject>
|
||||||
|
|
||||||
|
- (void)setGetLogPrefix:(NSString *(^)())getLogPrefix;
|
||||||
|
- (void)setUsageCalculationInfo:(MTNetworkUsageCalculationInfo *)usageCalculationInfo;
|
||||||
|
- (bool)connectToHost:(NSString *)inHost
|
||||||
|
onPort:(uint16_t)port
|
||||||
|
viaInterface:(NSString *)inInterface
|
||||||
|
withTimeout:(NSTimeInterval)timeout
|
||||||
|
error:(NSError **)errPtr;
|
||||||
|
- (void)writeData:(NSData *)data;
|
||||||
|
- (void)readDataToLength:(NSUInteger)length withTimeout:(NSTimeInterval)timeout tag:(long)tag;
|
||||||
|
- (void)disconnect;
|
||||||
|
- (void)resetDelegate;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface MTGcdAsyncSocketTcpConnectionInterface: NSObject<MTTcpConnectionInterface, GCDAsyncSocketDelegate> {
|
||||||
|
GCDAsyncSocket *_socket;
|
||||||
|
__weak id<MTTcpConnectionInterfaceDelegate> _delegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MTGcdAsyncSocketTcpConnectionInterface
|
||||||
|
|
||||||
|
- (instancetype)initWithDelegate:(id<MTTcpConnectionInterfaceDelegate>)delegate delegateQueue:(dispatch_queue_t)delegateQueue {
|
||||||
|
self = [super init];
|
||||||
|
if (self != nil) {
|
||||||
|
_delegate = delegate;
|
||||||
|
_socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:delegateQueue];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setGetLogPrefix:(NSString *(^)())getLogPrefix {
|
||||||
|
_socket.getLogPrefix = getLogPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setUsageCalculationInfo:(MTNetworkUsageCalculationInfo *)usageCalculationInfo {
|
||||||
|
_socket.usageCalculationInfo = usageCalculationInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (bool)connectToHost:(NSString *)inHost
|
||||||
|
onPort:(uint16_t)port
|
||||||
|
viaInterface:(NSString *)inInterface
|
||||||
|
withTimeout:(NSTimeInterval)timeout
|
||||||
|
error:(NSError **)errPtr {
|
||||||
|
return [_socket connectToHost:inHost onPort:port viaInterface:inInterface withTimeout:timeout error:errPtr];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)writeData:(NSData *)data {
|
||||||
|
[_socket writeData:data withTimeout:-1.0 tag:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)readDataToLength:(NSUInteger)length withTimeout:(NSTimeInterval)timeout tag:(long)tag {
|
||||||
|
[_socket readDataToLength:length withTimeout:timeout tag:tag];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)disconnect {
|
||||||
|
[_socket disconnect];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)resetDelegate {
|
||||||
|
_socket.delegate = nil;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)socket:(GCDAsyncSocket *)socket didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)tag {
|
||||||
|
id<MTTcpConnectionInterfaceDelegate> delegate = _delegate;
|
||||||
|
if (delegate) {
|
||||||
|
[delegate connectionInterface:self didReadPartialDataOfLength:partialLength tag:tag];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)socket:(GCDAsyncSocket *)socket didReadData:(NSData *)rawData withTag:(long)tag {
|
||||||
|
id<MTTcpConnectionInterfaceDelegate> delegate = _delegate;
|
||||||
|
if (delegate) {
|
||||||
|
[delegate connectionInterface:self didReadData:rawData withTag:tag];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)socket:(GCDAsyncSocket *)socket didConnectToHost:(NSString *)host port:(uint16_t)port {
|
||||||
|
id<MTTcpConnectionInterfaceDelegate> delegate = _delegate;
|
||||||
|
if (delegate) {
|
||||||
|
[delegate connectionInterface:self didConnectToHost:host port:port];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)socketDidDisconnect:(GCDAsyncSocket *)socket withError:(NSError *)error {
|
||||||
|
id<MTTcpConnectionInterfaceDelegate> delegate = _delegate;
|
||||||
|
if (delegate) {
|
||||||
|
[delegate connectionInterfaceDidDisconnect:self withError:error];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSTimeInterval)socket:(GCDAsyncSocket *)sock shouldTimeoutReadWithTag:(long)tag elapsed:(NSTimeInterval)elapsed bytesDone:(NSUInteger)length {
|
||||||
|
return -1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@interface MTTcpReceiveData : NSObject
|
@interface MTTcpReceiveData : NSObject
|
||||||
|
|
||||||
@property (nonatomic, readonly) int tag;
|
@property (nonatomic, readonly) int tag;
|
||||||
@ -626,11 +738,11 @@ struct ctr_state {
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface MTTcpConnection () <GCDAsyncSocketDelegate>
|
@interface MTTcpConnection () <MTTcpConnectionInterfaceDelegate>
|
||||||
{
|
{
|
||||||
id<EncryptionProvider> _encryptionProvider;
|
id<EncryptionProvider> _encryptionProvider;
|
||||||
|
|
||||||
GCDAsyncSocket *_socket;
|
id<MTTcpConnectionInterface> _socket;
|
||||||
bool _closed;
|
bool _closed;
|
||||||
|
|
||||||
bool _useIntermediateFormat;
|
bool _useIntermediateFormat;
|
||||||
@ -786,7 +898,7 @@ struct ctr_state {
|
|||||||
- (void)setUsageCalculationInfo:(MTNetworkUsageCalculationInfo *)usageCalculationInfo {
|
- (void)setUsageCalculationInfo:(MTNetworkUsageCalculationInfo *)usageCalculationInfo {
|
||||||
[[MTTcpConnection tcpQueue] dispatchOnQueue:^{
|
[[MTTcpConnection tcpQueue] dispatchOnQueue:^{
|
||||||
_usageCalculationInfo = usageCalculationInfo;
|
_usageCalculationInfo = usageCalculationInfo;
|
||||||
_socket.usageCalculationInfo = usageCalculationInfo;
|
[_socket setUsageCalculationInfo:usageCalculationInfo];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -805,9 +917,10 @@ struct ctr_state {
|
|||||||
{
|
{
|
||||||
if (_socket == nil)
|
if (_socket == nil)
|
||||||
{
|
{
|
||||||
_socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:[[MTTcpConnection tcpQueue] nativeQueue]];
|
_socket = [[MTGcdAsyncSocketTcpConnectionInterface alloc] initWithDelegate:self delegateQueue:[[MTTcpConnection tcpQueue] nativeQueue]];
|
||||||
_socket.getLogPrefix = _getLogPrefix;
|
|
||||||
_socket.usageCalculationInfo = _usageCalculationInfo;
|
[_socket setGetLogPrefix:_getLogPrefix];
|
||||||
|
[_socket setUsageCalculationInfo:_usageCalculationInfo];
|
||||||
|
|
||||||
NSString *addressIp = _scheme.address.ip;
|
NSString *addressIp = _scheme.address.ip;
|
||||||
MTSignal *resolveSignal = [MTSignal single:[[MTTcpConnectionData alloc] initWithIp:addressIp port:_scheme.address.port isSocks:false]];
|
MTSignal *resolveSignal = [MTSignal single:[[MTTcpConnectionData alloc] initWithIp:addressIp port:_scheme.address.port isSocks:false]];
|
||||||
@ -990,7 +1103,7 @@ struct ctr_state {
|
|||||||
_helloRandom = [[NSData alloc] initWithBytes:cHMAC length:32];
|
_helloRandom = [[NSData alloc] initWithBytes:cHMAC length:32];
|
||||||
memcpy(((uint8_t *)helloData.mutableBytes) + 11, cHMAC, 32);
|
memcpy(((uint8_t *)helloData.mutableBytes) + 11, cHMAC, 32);
|
||||||
|
|
||||||
[strongSelf->_socket writeData:helloData withTimeout:-1 tag:0];
|
[strongSelf->_socket writeData:helloData];
|
||||||
[strongSelf->_socket readDataToLength:5 withTimeout:-1 tag:MTTcpSocksReceiveHelloResponse];
|
[strongSelf->_socket readDataToLength:5 withTimeout:-1 tag:MTTcpSocksReceiveHelloResponse];
|
||||||
} else {
|
} else {
|
||||||
strongSelf->_readyToSendData = true;
|
strongSelf->_readyToSendData = true;
|
||||||
@ -1011,7 +1124,7 @@ struct ctr_state {
|
|||||||
req.NumberOfMethods += 1;
|
req.NumberOfMethods += 1;
|
||||||
req.Methods[1] = 0x02;
|
req.Methods[1] = 0x02;
|
||||||
}
|
}
|
||||||
[strongSelf->_socket writeData:[NSData dataWithBytes:&req length:2 + req.NumberOfMethods] withTimeout:-1 tag:0];
|
[strongSelf->_socket writeData:[NSData dataWithBytes:&req length:2 + req.NumberOfMethods]];
|
||||||
[strongSelf->_socket readDataToLength:sizeof(struct socks5_ident_resp) withTimeout:-1 tag:MTTcpSocksLogin];
|
[strongSelf->_socket readDataToLength:sizeof(struct socks5_ident_resp) withTimeout:-1 tag:MTTcpSocksLogin];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
@ -1038,7 +1151,7 @@ struct ctr_state {
|
|||||||
_closed = true;
|
_closed = true;
|
||||||
|
|
||||||
[_socket disconnect];
|
[_socket disconnect];
|
||||||
_socket.delegate = nil;
|
[_socket resetDelegate];
|
||||||
_socket = nil;
|
_socket = nil;
|
||||||
|
|
||||||
if (_connectionClosed)
|
if (_connectionClosed)
|
||||||
@ -1232,9 +1345,9 @@ struct ctr_state {
|
|||||||
|
|
||||||
offset += partLength;
|
offset += partLength;
|
||||||
}
|
}
|
||||||
[_socket writeData:partitionedCompleteData withTimeout:-1 tag:0];
|
[_socket writeData:partitionedCompleteData];
|
||||||
} else {
|
} else {
|
||||||
[_socket writeData:completeData withTimeout:-1 tag:0];
|
[_socket writeData:completeData];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1294,7 +1407,7 @@ struct ctr_state {
|
|||||||
[self closeAndNotifyWithError:true];
|
[self closeAndNotifyWithError:true];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)socket:(GCDAsyncSocket *)__unused socket didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)__unused tag
|
- (void)connectionInterface:(id<MTTcpConnectionInterface>)__unused connectionInterface didReadPartialDataOfLength:(NSUInteger)partialLength tag:(long)__unused tag
|
||||||
{
|
{
|
||||||
if (_closed)
|
if (_closed)
|
||||||
return;
|
return;
|
||||||
@ -1313,6 +1426,9 @@ struct ctr_state {
|
|||||||
[delegate tcpConnectionProgressUpdated:self packetProgressToken:_packetProgressToken packetLength:_packetRestLength progress:currentApproximateProgress / 100.0f];
|
[delegate tcpConnectionProgressUpdated:self packetProgressToken:_packetProgressToken packetLength:_packetRestLength progress:currentApproximateProgress / 100.0f];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id<MTTcpConnectionDelegate> delegate = _delegate;
|
||||||
|
[delegate tcpConnectionDownloadActivityUpdated:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)requestSocksConnection {
|
- (void)requestSocksConnection {
|
||||||
@ -1357,15 +1473,18 @@ struct ctr_state {
|
|||||||
unsigned short port = htons(req.DestPort);
|
unsigned short port = htons(req.DestPort);
|
||||||
[reqData appendBytes:&port length:2];
|
[reqData appendBytes:&port length:2];
|
||||||
|
|
||||||
[_socket writeData:reqData withTimeout:-1 tag:0];
|
[_socket writeData:reqData];
|
||||||
[_socket readDataToLength:4 withTimeout:-1 tag:MTTcpSocksRequest];
|
[_socket readDataToLength:4 withTimeout:-1 tag:MTTcpSocksRequest];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)socket:(GCDAsyncSocket *)__unused socket didReadData:(NSData *)rawData withTag:(long)tag
|
- (void)connectionInterface:(id<MTTcpConnectionInterface>)__unused connectionInterface didReadData:(NSData *)rawData withTag:(long)tag
|
||||||
{
|
{
|
||||||
if (_closed)
|
if (_closed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
id<MTTcpConnectionDelegate> delegate = _delegate;
|
||||||
|
[delegate tcpConnectionDownloadActivityUpdated:self];
|
||||||
|
|
||||||
if (tag == MTTcpSocksLogin) {
|
if (tag == MTTcpSocksLogin) {
|
||||||
if (rawData.length != sizeof(struct socks5_ident_resp)) {
|
if (rawData.length != sizeof(struct socks5_ident_resp)) {
|
||||||
if (MTLogEnabled()) {
|
if (MTLogEnabled()) {
|
||||||
@ -1410,7 +1529,7 @@ struct ctr_state {
|
|||||||
[reqData appendBytes:&passwordLength length:1];
|
[reqData appendBytes:&passwordLength length:1];
|
||||||
[reqData appendData:passwordData];
|
[reqData appendData:passwordData];
|
||||||
|
|
||||||
[_socket writeData:reqData withTimeout:-1 tag:0];
|
[_socket writeData:reqData];
|
||||||
[_socket readDataToLength:2 withTimeout:-1 tag:MTTcpSocksReceiveAuthResponse];
|
[_socket readDataToLength:2 withTimeout:-1 tag:MTTcpSocksReceiveAuthResponse];
|
||||||
} else {
|
} else {
|
||||||
[self requestSocksConnection];
|
[self requestSocksConnection];
|
||||||
@ -1899,7 +2018,7 @@ struct ctr_state {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)socket:(GCDAsyncSocket *)__unused socket didConnectToHost:(NSString *)__unused host port:(uint16_t)__unused port
|
- (void)connectionInterface:(id<MTTcpConnectionInterface>)__unused connectionInterface didConnectToHost:(NSString *)__unused host port:(uint16_t)__unused port
|
||||||
{
|
{
|
||||||
if (_socksIp != nil) {
|
if (_socksIp != nil) {
|
||||||
|
|
||||||
@ -1912,7 +2031,7 @@ struct ctr_state {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)socketDidDisconnect:(GCDAsyncSocket *)__unused socket withError:(NSError *)error
|
- (void)connectionInterfaceDidDisconnect:(id<MTTcpConnectionInterface>)__unused connectionInterface withError:(NSError *)error
|
||||||
{
|
{
|
||||||
if (error != nil) {
|
if (error != nil) {
|
||||||
if (MTLogEnabled()) {
|
if (MTLogEnabled()) {
|
||||||
|
@ -551,6 +551,19 @@ static const NSTimeInterval MTTcpTransportSleepWatchdogTimeout = 60.0;
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)tcpConnectionDownloadActivityUpdated:(MTTcpConnection *)connection {
|
||||||
|
MTTcpTransportContext *transportContext = _transportContext;
|
||||||
|
[[MTTcpTransport tcpTransportQueue] dispatchOnQueue:^
|
||||||
|
{
|
||||||
|
if (transportContext.connection != connection)
|
||||||
|
return;
|
||||||
|
|
||||||
|
id<MTTransportDelegate> delegate = self.delegate;
|
||||||
|
if ([delegate respondsToSelector:@selector(transportUpdatedDataReceiveProgress:progressToken:packetLength:progress:)])
|
||||||
|
[delegate transportActivityUpdated:self];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)tcpConnectionBehaviourRequestsReconnection:(MTTcpConnectionBehaviour *)behaviour error:(bool)error
|
- (void)tcpConnectionBehaviourRequestsReconnection:(MTTcpConnectionBehaviour *)behaviour error:(bool)error
|
||||||
{
|
{
|
||||||
MTTcpTransportContext *transportContext = _transportContext;
|
MTTcpTransportContext *transportContext = _transportContext;
|
||||||
|
@ -67,7 +67,9 @@ final class SetupTwoStepVerificationContentNode: ASDisplayNode, UITextFieldDeleg
|
|||||||
self.inputNode.textField.autocapitalizationType = .none
|
self.inputNode.textField.autocapitalizationType = .none
|
||||||
self.inputNode.textField.autocorrectionType = .no
|
self.inputNode.textField.autocorrectionType = .no
|
||||||
if #available(iOSApplicationExtension 12.0, iOS 12.0, *) {
|
if #available(iOSApplicationExtension 12.0, iOS 12.0, *) {
|
||||||
|
#if DEBUG
|
||||||
self.inputNode.textField.textContentType = .newPassword
|
self.inputNode.textField.textContentType = .newPassword
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
case .text:
|
case .text:
|
||||||
break
|
break
|
||||||
|
@ -1081,6 +1081,7 @@ private final class TwoFactorDataInputTextNode: ASDisplayNode, UITextFieldDelega
|
|||||||
self.inputNode.textField.returnKeyType = .next
|
self.inputNode.textField.returnKeyType = .next
|
||||||
}
|
}
|
||||||
if #available(iOS 12.0, *) {
|
if #available(iOS 12.0, *) {
|
||||||
|
#if DEBUG
|
||||||
if !confirmation, let phoneNumber {
|
if !confirmation, let phoneNumber {
|
||||||
let shadowInputNode = TextFieldNode()
|
let shadowInputNode = TextFieldNode()
|
||||||
shadowInputNode.textField.font = Font.regular(17.0)
|
shadowInputNode.textField.font = Font.regular(17.0)
|
||||||
@ -1092,9 +1093,12 @@ private final class TwoFactorDataInputTextNode: ASDisplayNode, UITextFieldDelega
|
|||||||
shadowInputNode.textField.textContentType = .username
|
shadowInputNode.textField.textContentType = .username
|
||||||
shadowInputNode.textField.text = phoneNumber
|
shadowInputNode.textField.text = phoneNumber
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
self.inputNode.textField.textContentType = .newPassword
|
self.inputNode.textField.textContentType = .newPassword
|
||||||
self.inputNode.textField.passwordRules = UITextInputPasswordRules(descriptor: "minlength: 8;")
|
self.inputNode.textField.passwordRules = UITextInputPasswordRules(descriptor: "minlength: 8;")
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
self.hideButtonNode.isHidden = confirmation
|
self.hideButtonNode.isHidden = confirmation
|
||||||
case .email:
|
case .email:
|
||||||
|
@ -150,7 +150,7 @@ public class UnauthorizedAccount {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|> mapToSignal { (localizationSettings, proxySettings, networkSettings) -> Signal<UnauthorizedAccount, NoError> in
|
|> mapToSignal { (localizationSettings, proxySettings, networkSettings) -> Signal<UnauthorizedAccount, NoError> in
|
||||||
return initializedNetwork(accountId: self.id, arguments: self.networkArguments, supplementary: false, datacenterId: Int(masterDatacenterId), keychain: keychain, basePath: self.basePath, testingEnvironment: self.testingEnvironment, languageCode: localizationSettings?.primaryComponent.languageCode, proxySettings: proxySettings, networkSettings: networkSettings, phoneNumber: nil)
|
return initializedNetwork(accountId: self.id, arguments: self.networkArguments, supplementary: false, datacenterId: Int(masterDatacenterId), keychain: keychain, basePath: self.basePath, testingEnvironment: self.testingEnvironment, languageCode: localizationSettings?.primaryComponent.languageCode, proxySettings: proxySettings, networkSettings: networkSettings, phoneNumber: nil, useRequestTimeoutTimers: false)
|
||||||
|> map { network in
|
|> map { network in
|
||||||
let updated = UnauthorizedAccount(networkArguments: self.networkArguments, id: self.id, rootPath: self.rootPath, basePath: self.basePath, testingEnvironment: self.testingEnvironment, postbox: self.postbox, network: network)
|
let updated = UnauthorizedAccount(networkArguments: self.networkArguments, id: self.id, rootPath: self.rootPath, basePath: self.basePath, testingEnvironment: self.testingEnvironment, postbox: self.postbox, network: network)
|
||||||
updated.shouldBeServiceTaskMaster.set(self.shouldBeServiceTaskMaster.get())
|
updated.shouldBeServiceTaskMaster.set(self.shouldBeServiceTaskMaster.get())
|
||||||
@ -206,7 +206,7 @@ public func accountWithId(accountManager: AccountManager<TelegramAccountManagerT
|
|||||||
return (localizationSettings, transaction.getSharedData(SharedDataKeys.proxySettings)?.get(ProxySettings.self))
|
return (localizationSettings, transaction.getSharedData(SharedDataKeys.proxySettings)?.get(ProxySettings.self))
|
||||||
}
|
}
|
||||||
|> mapToSignal { localizationSettings, proxySettings -> Signal<AccountResult, NoError> in
|
|> mapToSignal { localizationSettings, proxySettings -> Signal<AccountResult, NoError> in
|
||||||
return postbox.transaction { transaction -> (PostboxCoding?, LocalizationSettings?, ProxySettings?, NetworkSettings?) in
|
return postbox.transaction { transaction -> (PostboxCoding?, LocalizationSettings?, ProxySettings?, NetworkSettings?, AppConfiguration) in
|
||||||
var state = transaction.getState()
|
var state = transaction.getState()
|
||||||
if state == nil, let backupData = backupData {
|
if state == nil, let backupData = backupData {
|
||||||
let backupState = AuthorizedAccountState(isTestingEnvironment: beginWithTestingEnvironment, masterDatacenterId: backupData.masterDatacenterId, peerId: PeerId(backupData.peerId), state: nil, invalidatedChannels: [])
|
let backupState = AuthorizedAccountState(isTestingEnvironment: beginWithTestingEnvironment, masterDatacenterId: backupData.masterDatacenterId, peerId: PeerId(backupData.peerId), state: nil, invalidatedChannels: [])
|
||||||
@ -229,15 +229,24 @@ public func accountWithId(accountManager: AccountManager<TelegramAccountManagerT
|
|||||||
transaction.setKeychainEntry(data, forKey: "persistent:datacenterAuthInfoById")
|
transaction.setKeychainEntry(data, forKey: "persistent:datacenterAuthInfoById")
|
||||||
}
|
}
|
||||||
|
|
||||||
return (state, localizationSettings, proxySettings, transaction.getPreferencesEntry(key: PreferencesKeys.networkSettings)?.get(NetworkSettings.self))
|
let appConfig = transaction.getPreferencesEntry(key: PreferencesKeys.appConfiguration)?.get(AppConfiguration.self) ?? .defaultValue
|
||||||
|
|
||||||
|
return (state, localizationSettings, proxySettings, transaction.getPreferencesEntry(key: PreferencesKeys.networkSettings)?.get(NetworkSettings.self), appConfig)
|
||||||
}
|
}
|
||||||
|> mapToSignal { (accountState, localizationSettings, proxySettings, networkSettings) -> Signal<AccountResult, NoError> in
|
|> mapToSignal { (accountState, localizationSettings, proxySettings, networkSettings, appConfig) -> Signal<AccountResult, NoError> in
|
||||||
let keychain = makeExclusiveKeychain(id: id, postbox: postbox)
|
let keychain = makeExclusiveKeychain(id: id, postbox: postbox)
|
||||||
|
|
||||||
|
var useRequestTimeoutTimers: Bool = true
|
||||||
|
if let data = appConfig.data {
|
||||||
|
if let _ = data["ios_killswitch_disable_request_timeout"] {
|
||||||
|
useRequestTimeoutTimers = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let accountState = accountState {
|
if let accountState = accountState {
|
||||||
switch accountState {
|
switch accountState {
|
||||||
case let unauthorizedState as UnauthorizedAccountState:
|
case let unauthorizedState as UnauthorizedAccountState:
|
||||||
return initializedNetwork(accountId: id, arguments: networkArguments, supplementary: supplementary, datacenterId: Int(unauthorizedState.masterDatacenterId), keychain: keychain, basePath: path, testingEnvironment: unauthorizedState.isTestingEnvironment, languageCode: localizationSettings?.primaryComponent.languageCode, proxySettings: proxySettings, networkSettings: networkSettings, phoneNumber: nil)
|
return initializedNetwork(accountId: id, arguments: networkArguments, supplementary: supplementary, datacenterId: Int(unauthorizedState.masterDatacenterId), keychain: keychain, basePath: path, testingEnvironment: unauthorizedState.isTestingEnvironment, languageCode: localizationSettings?.primaryComponent.languageCode, proxySettings: proxySettings, networkSettings: networkSettings, phoneNumber: nil, useRequestTimeoutTimers: useRequestTimeoutTimers)
|
||||||
|> map { network -> AccountResult in
|
|> map { network -> AccountResult in
|
||||||
return .unauthorized(UnauthorizedAccount(networkArguments: networkArguments, id: id, rootPath: rootPath, basePath: path, testingEnvironment: unauthorizedState.isTestingEnvironment, postbox: postbox, network: network, shouldKeepAutoConnection: shouldKeepAutoConnection))
|
return .unauthorized(UnauthorizedAccount(networkArguments: networkArguments, id: id, rootPath: rootPath, basePath: path, testingEnvironment: unauthorizedState.isTestingEnvironment, postbox: postbox, network: network, shouldKeepAutoConnection: shouldKeepAutoConnection))
|
||||||
}
|
}
|
||||||
@ -246,7 +255,7 @@ public func accountWithId(accountManager: AccountManager<TelegramAccountManagerT
|
|||||||
return (transaction.getPeer(authorizedState.peerId) as? TelegramUser)?.phone
|
return (transaction.getPeer(authorizedState.peerId) as? TelegramUser)?.phone
|
||||||
}
|
}
|
||||||
|> mapToSignal { phoneNumber in
|
|> mapToSignal { phoneNumber in
|
||||||
return initializedNetwork(accountId: id, arguments: networkArguments, supplementary: supplementary, datacenterId: Int(authorizedState.masterDatacenterId), keychain: keychain, basePath: path, testingEnvironment: authorizedState.isTestingEnvironment, languageCode: localizationSettings?.primaryComponent.languageCode, proxySettings: proxySettings, networkSettings: networkSettings, phoneNumber: phoneNumber)
|
return initializedNetwork(accountId: id, arguments: networkArguments, supplementary: supplementary, datacenterId: Int(authorizedState.masterDatacenterId), keychain: keychain, basePath: path, testingEnvironment: authorizedState.isTestingEnvironment, languageCode: localizationSettings?.primaryComponent.languageCode, proxySettings: proxySettings, networkSettings: networkSettings, phoneNumber: phoneNumber, useRequestTimeoutTimers: useRequestTimeoutTimers)
|
||||||
|> map { network -> AccountResult in
|
|> map { network -> AccountResult in
|
||||||
return .authorized(Account(accountManager: accountManager, id: id, basePath: path, testingEnvironment: authorizedState.isTestingEnvironment, postbox: postbox, network: network, networkArguments: networkArguments, peerId: authorizedState.peerId, auxiliaryMethods: auxiliaryMethods, supplementary: supplementary))
|
return .authorized(Account(accountManager: accountManager, id: id, basePath: path, testingEnvironment: authorizedState.isTestingEnvironment, postbox: postbox, network: network, networkArguments: networkArguments, peerId: authorizedState.peerId, auxiliaryMethods: auxiliaryMethods, supplementary: supplementary))
|
||||||
}
|
}
|
||||||
@ -256,7 +265,7 @@ public func accountWithId(accountManager: AccountManager<TelegramAccountManagerT
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return initializedNetwork(accountId: id, arguments: networkArguments, supplementary: supplementary, datacenterId: 2, keychain: keychain, basePath: path, testingEnvironment: beginWithTestingEnvironment, languageCode: localizationSettings?.primaryComponent.languageCode, proxySettings: proxySettings, networkSettings: networkSettings, phoneNumber: nil)
|
return initializedNetwork(accountId: id, arguments: networkArguments, supplementary: supplementary, datacenterId: 2, keychain: keychain, basePath: path, testingEnvironment: beginWithTestingEnvironment, languageCode: localizationSettings?.primaryComponent.languageCode, proxySettings: proxySettings, networkSettings: networkSettings, phoneNumber: nil, useRequestTimeoutTimers: useRequestTimeoutTimers)
|
||||||
|> map { network -> AccountResult in
|
|> map { network -> AccountResult in
|
||||||
return .unauthorized(UnauthorizedAccount(networkArguments: networkArguments, id: id, rootPath: rootPath, basePath: path, testingEnvironment: beginWithTestingEnvironment, postbox: postbox, network: network, shouldKeepAutoConnection: shouldKeepAutoConnection))
|
return .unauthorized(UnauthorizedAccount(networkArguments: networkArguments, id: id, rootPath: rootPath, basePath: path, testingEnvironment: beginWithTestingEnvironment, postbox: postbox, network: network, shouldKeepAutoConnection: shouldKeepAutoConnection))
|
||||||
}
|
}
|
||||||
@ -1441,7 +1450,8 @@ public func standaloneStateManager(
|
|||||||
languageCode: localizationSettings?.primaryComponent.languageCode,
|
languageCode: localizationSettings?.primaryComponent.languageCode,
|
||||||
proxySettings: proxySettings,
|
proxySettings: proxySettings,
|
||||||
networkSettings: networkSettings,
|
networkSettings: networkSettings,
|
||||||
phoneNumber: phoneNumber
|
phoneNumber: phoneNumber,
|
||||||
|
useRequestTimeoutTimers: false
|
||||||
)
|
)
|
||||||
|> map { network -> AccountStateManager? in
|
|> map { network -> AccountStateManager? in
|
||||||
Logger.shared.log("StandaloneStateManager", "received network")
|
Logger.shared.log("StandaloneStateManager", "received network")
|
||||||
|
@ -43,14 +43,16 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
|
|||||||
let context: MTContext
|
let context: MTContext
|
||||||
let mtProto: MTProto
|
let mtProto: MTProto
|
||||||
let requestService: MTRequestMessageService
|
let requestService: MTRequestMessageService
|
||||||
|
let useRequestTimeoutTimers: Bool
|
||||||
private let logPrefix = Atomic<String?>(value: nil)
|
private let logPrefix = Atomic<String?>(value: nil)
|
||||||
|
|
||||||
private var shouldKeepConnectionDisposable: Disposable?
|
private var shouldKeepConnectionDisposable: Disposable?
|
||||||
|
|
||||||
init(queue: Queue, datacenterId: Int, isMedia: Bool, isCdn: Bool, context: MTContext, masterDatacenterId: Int, usageInfo: MTNetworkUsageCalculationInfo?, shouldKeepConnection: Signal<Bool, NoError>) {
|
init(queue: Queue, datacenterId: Int, isMedia: Bool, isCdn: Bool, context: MTContext, masterDatacenterId: Int, usageInfo: MTNetworkUsageCalculationInfo?, shouldKeepConnection: Signal<Bool, NoError>, useRequestTimeoutTimers: Bool) {
|
||||||
self.datacenterId = datacenterId
|
self.datacenterId = datacenterId
|
||||||
self.isCdn = isCdn
|
self.isCdn = isCdn
|
||||||
self.context = context
|
self.context = context
|
||||||
|
self.useRequestTimeoutTimers = useRequestTimeoutTimers
|
||||||
|
|
||||||
var requiredAuthToken: Any?
|
var requiredAuthToken: Any?
|
||||||
var authTokenMasterDatacenterId: Int = 0
|
var authTokenMasterDatacenterId: Int = 0
|
||||||
@ -203,6 +205,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
|
|||||||
})
|
})
|
||||||
|
|
||||||
request.dependsOnPasswordEntry = false
|
request.dependsOnPasswordEntry = false
|
||||||
|
request.needsTimeoutTimer = self.useRequestTimeoutTimers
|
||||||
|
|
||||||
request.shouldContinueExecutionWithErrorContext = { errorContext in
|
request.shouldContinueExecutionWithErrorContext = { errorContext in
|
||||||
return true
|
return true
|
||||||
@ -254,6 +257,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
|
|||||||
})
|
})
|
||||||
|
|
||||||
request.dependsOnPasswordEntry = false
|
request.dependsOnPasswordEntry = false
|
||||||
|
request.needsTimeoutTimer = self.useRequestTimeoutTimers
|
||||||
|
|
||||||
request.shouldContinueExecutionWithErrorContext = { errorContext in
|
request.shouldContinueExecutionWithErrorContext = { errorContext in
|
||||||
return true
|
return true
|
||||||
@ -301,6 +305,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
|
|||||||
})
|
})
|
||||||
|
|
||||||
request.dependsOnPasswordEntry = false
|
request.dependsOnPasswordEntry = false
|
||||||
|
request.needsTimeoutTimer = self.useRequestTimeoutTimers
|
||||||
|
|
||||||
request.shouldContinueExecutionWithErrorContext = { errorContext in
|
request.shouldContinueExecutionWithErrorContext = { errorContext in
|
||||||
return true
|
return true
|
||||||
@ -342,6 +347,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
|
|||||||
})
|
})
|
||||||
|
|
||||||
request.dependsOnPasswordEntry = false
|
request.dependsOnPasswordEntry = false
|
||||||
|
request.needsTimeoutTimer = self.useRequestTimeoutTimers
|
||||||
|
|
||||||
request.shouldContinueExecutionWithErrorContext = { errorContext in
|
request.shouldContinueExecutionWithErrorContext = { errorContext in
|
||||||
guard let errorContext = errorContext else {
|
guard let errorContext = errorContext else {
|
||||||
@ -393,6 +399,7 @@ class Download: NSObject, MTRequestMessageServiceDelegate {
|
|||||||
})
|
})
|
||||||
|
|
||||||
request.dependsOnPasswordEntry = false
|
request.dependsOnPasswordEntry = false
|
||||||
|
request.needsTimeoutTimer = self.useRequestTimeoutTimers
|
||||||
|
|
||||||
request.shouldContinueExecutionWithErrorContext = { errorContext in
|
request.shouldContinueExecutionWithErrorContext = { errorContext in
|
||||||
guard let errorContext = errorContext else {
|
guard let errorContext = errorContext else {
|
||||||
|
@ -450,7 +450,7 @@ public struct NetworkInitializationArguments {
|
|||||||
private let cloudDataContext = Atomic<CloudDataContext?>(value: nil)
|
private let cloudDataContext = Atomic<CloudDataContext?>(value: nil)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializationArguments, supplementary: Bool, datacenterId: Int, keychain: Keychain, basePath: String, testingEnvironment: Bool, languageCode: String?, proxySettings: ProxySettings?, networkSettings: NetworkSettings?, phoneNumber: String?) -> Signal<Network, NoError> {
|
func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializationArguments, supplementary: Bool, datacenterId: Int, keychain: Keychain, basePath: String, testingEnvironment: Bool, languageCode: String?, proxySettings: ProxySettings?, networkSettings: NetworkSettings?, phoneNumber: String?, useRequestTimeoutTimers: Bool) -> Signal<Network, NoError> {
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
let queue = Queue()
|
let queue = Queue()
|
||||||
queue.async {
|
queue.async {
|
||||||
@ -581,7 +581,7 @@ func initializedNetwork(accountId: AccountRecordId, arguments: NetworkInitializa
|
|||||||
mtProto.delegate = connectionStatusDelegate
|
mtProto.delegate = connectionStatusDelegate
|
||||||
mtProto.add(requestService)
|
mtProto.add(requestService)
|
||||||
|
|
||||||
let network = Network(queue: queue, datacenterId: datacenterId, context: context, mtProto: mtProto, requestService: requestService, connectionStatusDelegate: connectionStatusDelegate, _connectionStatus: connectionStatus, basePath: basePath, appDataDisposable: appDataDisposable, encryptionProvider: arguments.encryptionProvider)
|
let network = Network(queue: queue, datacenterId: datacenterId, context: context, mtProto: mtProto, requestService: requestService, connectionStatusDelegate: connectionStatusDelegate, _connectionStatus: connectionStatus, basePath: basePath, appDataDisposable: appDataDisposable, encryptionProvider: arguments.encryptionProvider, useRequestTimeoutTimers: useRequestTimeoutTimers)
|
||||||
appDataUpdatedImpl = { [weak network] data in
|
appDataUpdatedImpl = { [weak network] data in
|
||||||
guard let data = data else {
|
guard let data = data else {
|
||||||
return
|
return
|
||||||
@ -711,6 +711,7 @@ public final class Network: NSObject, MTRequestMessageServiceDelegate {
|
|||||||
let requestService: MTRequestMessageService
|
let requestService: MTRequestMessageService
|
||||||
let basePath: String
|
let basePath: String
|
||||||
private let connectionStatusDelegate: MTProtoConnectionStatusDelegate
|
private let connectionStatusDelegate: MTProtoConnectionStatusDelegate
|
||||||
|
private let useRequestTimeoutTimers: Bool
|
||||||
|
|
||||||
private let appDataDisposable: Disposable
|
private let appDataDisposable: Disposable
|
||||||
|
|
||||||
@ -754,7 +755,7 @@ public final class Network: NSObject, MTRequestMessageServiceDelegate {
|
|||||||
return "Network context: \(self.context)"
|
return "Network context: \(self.context)"
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate init(queue: Queue, datacenterId: Int, context: MTContext, mtProto: MTProto, requestService: MTRequestMessageService, connectionStatusDelegate: MTProtoConnectionStatusDelegate, _connectionStatus: Promise<ConnectionStatus>, basePath: String, appDataDisposable: Disposable, encryptionProvider: EncryptionProvider) {
|
fileprivate init(queue: Queue, datacenterId: Int, context: MTContext, mtProto: MTProto, requestService: MTRequestMessageService, connectionStatusDelegate: MTProtoConnectionStatusDelegate, _connectionStatus: Promise<ConnectionStatus>, basePath: String, appDataDisposable: Disposable, encryptionProvider: EncryptionProvider, useRequestTimeoutTimers: Bool) {
|
||||||
self.encryptionProvider = encryptionProvider
|
self.encryptionProvider = encryptionProvider
|
||||||
|
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
@ -767,6 +768,7 @@ public final class Network: NSObject, MTRequestMessageServiceDelegate {
|
|||||||
self._connectionStatus = _connectionStatus
|
self._connectionStatus = _connectionStatus
|
||||||
self.appDataDisposable = appDataDisposable
|
self.appDataDisposable = appDataDisposable
|
||||||
self.basePath = basePath
|
self.basePath = basePath
|
||||||
|
self.useRequestTimeoutTimers = useRequestTimeoutTimers
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
@ -899,7 +901,7 @@ public final class Network: NSObject, MTRequestMessageServiceDelegate {
|
|||||||
return shouldKeepConnection || shouldExplicitelyKeepWorkerConnections || (continueInBackground && shouldKeepBackgroundDownloadConnections)
|
return shouldKeepConnection || shouldExplicitelyKeepWorkerConnections || (continueInBackground && shouldKeepBackgroundDownloadConnections)
|
||||||
}
|
}
|
||||||
|> distinctUntilChanged
|
|> distinctUntilChanged
|
||||||
return Download(queue: self.queue, datacenterId: datacenterId, isMedia: isMedia, isCdn: isCdn, context: self.context, masterDatacenterId: self.datacenterId, usageInfo: usageCalculationInfo(basePath: self.basePath, category: (tag as? TelegramMediaResourceFetchTag)?.statsCategory), shouldKeepConnection: shouldKeepWorkerConnection)
|
return Download(queue: self.queue, datacenterId: datacenterId, isMedia: isMedia, isCdn: isCdn, context: self.context, masterDatacenterId: self.datacenterId, usageInfo: usageCalculationInfo(basePath: self.basePath, category: (tag as? TelegramMediaResourceFetchTag)?.statsCategory), shouldKeepConnection: shouldKeepWorkerConnection, useRequestTimeoutTimers: self.useRequestTimeoutTimers)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func worker(datacenterId: Int, isCdn: Bool, isMedia: Bool, tag: MediaResourceFetchTag?) -> Signal<Download, NoError> {
|
private func worker(datacenterId: Int, isCdn: Bool, isMedia: Bool, tag: MediaResourceFetchTag?) -> Signal<Download, NoError> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user