Home telegram - mtTransport
Post
Cancel

telegram - mtTransport

MTTransportDelegate

protocol MTTransportDelegate

// transport network availability changed
- (void)transportNetworkAvailabilityChanged:(MTTransport *)transport isNetworkAvailable:(bool)isNetworkAvailable;

// transport connection state changed
- (void)transportConnectionStateChanged:(MTTransport *)transport isConnected:(bool)isConnected proxySettings:(MTSocksProxySettings *)proxySettings;

// transport connection failed for scheme
- (void)transportConnectionFailed:(MTTransport *)transport scheme:(MTTransportScheme *)scheme;

// transport connection context update state changed
- (void)transportConnectionContextUpdateStateChanged:(MTTransport *)transport isUpdatingConnectionContext:(bool)isUpdatingConnectionContext;

// transport connection problems status changed
- (void)transportConnectionProblemsStatusChanged:(MTTransport *)transport scheme:(MTTransportScheme *)scheme hasConnectionProblems:(bool)hasConnectionProblems isProbablyHttp:(bool)isProbablyHttp;

// transport ready for transaction 
- (void)transportReadyForTransaction:(MTTransport *)transport scheme:(MTTransportScheme *)scheme transportSpecificTransaction:(MTMessageTransaction *)transportSpecificTransaction forceConfirmations:(bool)forceConfirmations transactionReady:(void (^)(NSArray *))transactionReady;

// transport has incoming data
- (void)transportHasIncomingData:(MTTransport *)transport scheme:(MTTransportScheme *)scheme data:(NSData *)data transactionId:(id)transactionId requestTransactionAfterProcessing:(bool)requestTransactionAfterProcessing decodeResult:(void (^)(id transactionId, bool success))decodeResult;

// transport transaction may have failed
- (void)transportTransactionsMayHaveFailed:(MTTransport *)transport transactionIds:(NSArray *)transactionIds;

// transport received quick ack
- (void)transportReceivedQuickAck:(MTTransport *)transport quickAckId:(int32_t)quickAckId;

// transport decode progress token
- (void)transportDecodeProgressToken:(MTTransport *)transport scheme:(MTTransportScheme *)scheme data:(NSData *)data token:(int64_t)token completion:(void (^)(int64_t token, id progressToken))completion;

// transport data receive progress updated 
- (void)transportUpdatedDataReceiveProgress:(MTTransport *)transport progressToken:(id)progressToken packetLength:(NSInteger)packetLength progress:(float)progress;

MTTransport

class MTTransport:MTMessageService,MTNetworkAvailabilityDelegate

// delegate
@property (nonatomic, weak) id<MTTransportDelegate> delegate;

// context
@property (nonatomic, strong, readonly) MTContext *context;

// datacenter id
@property (nonatomic, readonly) NSInteger datacenterId;

// proxy setting
@property (nonatomic, strong, readonly) MTSocksProxySettings *proxySettings;

// enable simultaneous transaction
@property (nonatomic) bool simultaneousTransactionsEnabled;

// report transport `connection context update` states
@property (nonatomic) bool reportTransportConnectionContextUpdateStates;

// network availability
MTNetworkAvailability *_networkAvailability;

- (instancetype)initWithDelegate:(id<MTTransportDelegate>)delegate context:(MTContext *)context datacenterId:(NSInteger)datacenterId schemes:(NSArray<MTTransportScheme *> * _Nonnull)schemes proxySettings:(MTSocksProxySettings *)proxySettings usageCalculationInfo:(MTNetworkUsageCalculationInfo *)usageCalculationInfo;

// network usage calculation info
- (void)setUsageCalculationInfo:(MTNetworkUsageCalculationInfo *)usageCalculationInfo;

// 需要奇偶校验
- (bool)needsParityCorrection;

// reset
- (void)reset;

// stop
- (void)stop;

// update connection state
- (void)updateConnectionState;

// set delegate needs transaction
- (void)setDelegateNeedsTransaction;

// process incoming data
- (void)_processIncomingData:(NSData *)data scheme:(MTTransportScheme *)scheme transactionId:(id)transactionId requestTransactionAfterProcessing:(bool)requestTransactionAfterProcessing decodeResult:(void (^)(id transactionId, bool success))decodeResult;

- (void)_networkAvailabilityChanged:(bool)networkAvailable
{
    id<MTTransportDelegate> delegate = _delegate;
    if ([delegate respondsToSelector:@selector(transportNetworkAvailabilityChanged:isNetworkAvailable:)])
        [delegate transportNetworkAvailabilityChanged:self isNetworkAvailable:networkAvailable];
}

_processIncomingData

- (void)_processIncomingData:(NSData *)data scheme:(MTTransportScheme *)scheme transactionId:(id)transactionId requestTransactionAfterProcessing:(bool)requestTransactionAfterProcessing decodeResult:(void (^)(id transactionId, bool success))decodeResult
{
    id<MTTransportDelegate> delegate = _delegate;
  // notify to delegate incoming data
    if ([delegate respondsToSelector:@selector(transportHasIncomingData:scheme:data:transactionId:requestTransactionAfterProcessing:decodeResult:)])
    {
        [delegate transportHasIncomingData:self scheme:scheme data:data transactionId:transactionId requestTransactionAfterProcessing:requestTransactionAfterProcessing decodeResult:decodeResult];
    }
}
This post is licensed under CC BY 4.0 by the author.