|
@@ -25,6 +25,8 @@ WHPingDelegate
|
|
|
WHPingTester *whPingTester;
|
|
|
|
|
|
BOOL didRuiYunInitOkType;
|
|
|
+
|
|
|
+ BOOL disconnected_cb_type;//瑞云回调链接断开了
|
|
|
}
|
|
|
|
|
|
@property (nonatomic, strong) NSTimer *connectCheckTimer;
|
|
@@ -252,15 +254,11 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
/// 3. 根据对端的 SDN ID 创建连接
|
|
|
[RaylinkProxy.sharedManager createNewConnection:curSdnId];
|
|
|
|
|
|
- /// 4. 创建 HttpService
|
|
|
- self.tcpPort = [RaylinkProxy.sharedManager createHttpService:curSdnId];
|
|
|
- self.tcpPortStr = [[NSString alloc] initWithFormat:@"%ld",self.tcpPort];
|
|
|
+
|
|
|
|
|
|
self.socket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
|
|
|
|
|
|
- /// 6. 添加端口防火墙
|
|
|
- [RaylinkProxy.sharedManager addSdnId:curSdnId allowPort:9300];
|
|
|
- [RaylinkProxy.sharedManager addSdnId:curSdnId allowPort:9100];
|
|
|
+
|
|
|
|
|
|
|
|
|
//[self.connectBtn setEnabled:NO];
|
|
@@ -317,13 +315,33 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
|
|
|
|
|
|
if (status == 0) {
|
|
|
+
|
|
|
+ /// 4. 创建 HttpService
|
|
|
+ self.tcpPort = [RaylinkProxy.sharedManager createHttpService:sdnId];
|
|
|
+ self.tcpPortStr = [[NSString alloc] initWithFormat:@"%ld",self.tcpPort];
|
|
|
+
|
|
|
+ /// 5. 添加端口防火墙
|
|
|
+ [RaylinkProxy.sharedManager addSdnId:sdnId allowPort:9300];
|
|
|
+ [RaylinkProxy.sharedManager addSdnId:sdnId allowPort:9100];
|
|
|
+
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"onProxyConnected connectToHost"];
|
|
|
+
|
|
|
/// 6. 等待连接成功回调,创建 TCP socket 连接 HttpService 的端口
|
|
|
- [self.socket connectToHost:@"127.0.0.1" onPort:self.tcpPort error:NULL];
|
|
|
+ NSError *error;
|
|
|
|
|
|
- _curConnectDeviceState = DeviceConnectDeciceOk;
|
|
|
+ NSString*log1 = [[NSString alloc] initWithFormat:@"onProxyConnected connectToHost begin %ld", (long)self.tcpPort];
|
|
|
+ [cachesFileManager writeLogsWithMsg:log1];
|
|
|
+
|
|
|
+ [self.socket connectToHost:@"127.0.0.1" onPort:self.tcpPort error:&error];
|
|
|
|
|
|
+ NSString*log2 = [[NSString alloc] initWithFormat:@"onProxyConnected connectToHost end %ld, self.socket = %@ error = %@", (long)self.tcpPort, self.socket, error];
|
|
|
+ [cachesFileManager writeLogsWithMsg:log2];
|
|
|
+
|
|
|
+ _curConnectDeviceState = DeviceConnectDeciceOk;
|
|
|
_Pre_sdnId = self.DeviceThirdIdMod.data.sdnId;
|
|
|
|
|
|
+ disconnected_cb_type = NO;
|
|
|
+
|
|
|
// [self.connectBtn setTitle:@"连接成功" forState:UIControlStateDisabled];
|
|
|
// [self.sendBtn setEnabled:YES];
|
|
|
} else {
|
|
@@ -334,6 +352,67 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)OnProxyDisconnected_cb:(NSString *)sdnId {
|
|
|
+ [RaylinkProxy.sharedManager closeHttpService:sdnId];
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"OnProxyDisconnected_cb"];
|
|
|
+ disconnected_cb_type = YES;
|
|
|
+}
|
|
|
+
|
|
|
+//瑞云sock 断开了 需要重连
|
|
|
+- (void)tryReconnectFun{
|
|
|
+
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"tryReconnect"];
|
|
|
+ if(!disconnected_cb_type){
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"tryReconnect return"];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ NSURL *logUrl = [[NSFileManager.defaultManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask].firstObject URLByAppendingPathComponent:@"logs"];
|
|
|
+
|
|
|
+ if (![NSFileManager.defaultManager fileExistsAtPath:logUrl.path]) {
|
|
|
+ [NSFileManager.defaultManager createDirectoryAtURL:logUrl withIntermediateDirectories:YES attributes:NULL error:NULL];
|
|
|
+ }
|
|
|
+
|
|
|
+ dispatch_queue_t reinitProxyQueue = dispatch_queue_create("reinit_proxy", 0);
|
|
|
+
|
|
|
+
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"tryReconnect initProxy 0"];
|
|
|
+ dispatch_async(reinitProxyQueue, ^{
|
|
|
+ NSData *sdnInfo = [NSData dataWithContentsOfURL:[[NSBundle.mainBundle bundleURL] URLByAppendingPathComponent:@"planet.1ali_3ry_peer"]];
|
|
|
+
|
|
|
+ /// 1. 初始化代理库
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"tryReconnect initProxy 1"];
|
|
|
+ self->disconnected_cb_type = NO;
|
|
|
+ self->_isReInitType = YES;
|
|
|
+ [RaylinkProxy.sharedManager initProxy:logUrl.path rootSdnInfo:sdnInfo];
|
|
|
+ self->_isReInitType = NO;
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"tryReconnect initProxy 2"];
|
|
|
+ });
|
|
|
+
|
|
|
+// //KWeakSelf
|
|
|
+// NSMutableDictionary *paraDict = [NSMutableDictionary new];
|
|
|
+// if(self.DeviceThirdIdMod.data.sn){
|
|
|
+// [paraDict setValue:self.DeviceThirdIdMod.data.sn forKey:@"sn"];
|
|
|
+// }
|
|
|
+//
|
|
|
+// [cachesFileManager writeLogsWithMsg:@"tryReconnect CommonGetWithCallBackCode"];
|
|
|
+// [[netWorkManager shareInstance] CommonGetWithCallBackCode:getThirdIdBySn Parameters:paraDict success:^(id _Nonnull responseObject) {
|
|
|
+//
|
|
|
+// dispatch_async(self->initProxyQueue, ^{
|
|
|
+// NSData *sdnInfo = [NSData dataWithContentsOfURL:[[NSBundle.mainBundle bundleURL] URLByAppendingPathComponent:@"planet.1ali_3ry_peer"]];
|
|
|
+//
|
|
|
+// /// 1. 初始化代理库
|
|
|
+// [RaylinkProxy.sharedManager initProxy:logUrl.path rootSdnInfo:sdnInfo];
|
|
|
+// [cachesFileManager writeLogsWithMsg:@"tryReconnect initProxy"];
|
|
|
+// });
|
|
|
+//
|
|
|
+//
|
|
|
+// } failure:^(NSError * _Nonnull error) {
|
|
|
+// HLog("网络报错");
|
|
|
+// }];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port {
|
|
|
|
|
|
NSLog(@"didConnectToHost %d", port);
|
|
@@ -350,10 +429,11 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
[thread start];
|
|
|
|
|
|
/// 7. Socket 连接成功后,通过 socket 发送, self.peerPortTF 为对端服务端口
|
|
|
- [sock writeData:[[NSString stringWithFormat:@"CONNECT 127.0.0.1:%@ HTTP/1.0\r\n\r\n", @"9100"] dataUsingEncoding:NSUTF8StringEncoding] withTimeout:-1 tag:0];
|
|
|
+ //[sock writeData:[[NSString stringWithFormat:@"CONNECT 127.0.0.1:%@ HTTP/1.0\r\n\r\n", @"9100"] dataUsingEncoding:NSUTF8StringEncoding] withTimeout:-1 tag:0];
|
|
|
|
|
|
NSLog(@"readDataToData");
|
|
|
|
|
|
+ [cachesFileManager writeLogsWithMsg:@"didConnectToHost writeData"];
|
|
|
}
|
|
|
|
|
|
- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
|