diff --git a/VoidLink/Database/TemporaryHost.h b/VoidLink/Database/TemporaryHost.h index 3cf5110c..5ac0b858 100644 --- a/VoidLink/Database/TemporaryHost.h +++ b/VoidLink/Database/TemporaryHost.h @@ -31,6 +31,7 @@ NS_ASSUME_NONNULL_BEGIN @property (atomic, retain) NSString *name; @property (atomic, retain) NSString *uuid; @property (atomic, retain) NSSet *appList; +@property (atomic, retain) NSMutableSet * activeAddressPool; - (id) initFromHost:(Host*)host; diff --git a/VoidLink/Database/TemporaryHost.m b/VoidLink/Database/TemporaryHost.m index 09fee264..f49501eb 100644 --- a/VoidLink/Database/TemporaryHost.m +++ b/VoidLink/Database/TemporaryHost.m @@ -28,6 +28,17 @@ self = [self init]; self.address = host.address; + + NSSet *classes = [NSSet setWithObjects: [NSMutableSet class], nil]; + NSError *error = nil; + self.activeAddressPool = [NSKeyedUnarchiver unarchivedObjectOfClasses:classes fromData:host.activeAddressPool error:&error]; + if(self.activeAddressPool){ + for(NSString* address in _activeAddressPool){ + NSLog(@"%@, persisted addr: %@", host.name, address); + } + } + else self.activeAddressPool = [[NSMutableSet alloc] init]; + self.externalAddress = host.externalAddress; self.localAddress = host.localAddress; self.ipv6Address = host.ipv6Address; @@ -57,7 +68,7 @@ return self; } -- (void) propagateChangesToParent:(Host*)parentHost { +- (void) propagateChangesToParent:(Host*)parentHost { // update persisted host data // Avoid overwriting existing data with nil if // we don't have everything populated in the temporary // host. @@ -73,6 +84,15 @@ if (self.ipv6Address != nil) { parentHost.ipv6Address = self.ipv6Address; } + + if(self.activeAddressPool.count>0){ + NSError *error; + parentHost.activeAddressPool = [NSKeyedArchiver archivedDataWithRootObject:self.activeAddressPool requiringSecureCoding:YES error:&error]; + } + else [self.activeAddressPool addObject:self.activeAddress]; + + // NSLog(@"Persisting activeAddressPool, pool count %lu ... %f, host: %@", (unsigned long)self.activeAddressPool.count, CACurrentMediaTime(), self.name); + // try to fix invalid mac happens in some cases // 添加主机crash问题重点关注 if (!(self.mac == nil || [self.mac isEqualToString:@"00:00:00:00:00:00"])) parentHost.mac = self.mac; diff --git a/VoidLink/Limelight.xcdatamodeld/VoidLink v1.0.xcdatamodel/contents b/VoidLink/Limelight.xcdatamodeld/VoidLink v1.0.xcdatamodel/contents index 74783f19..1fde4181 100644 --- a/VoidLink/Limelight.xcdatamodeld/VoidLink v1.0.xcdatamodel/contents +++ b/VoidLink/Limelight.xcdatamodeld/VoidLink v1.0.xcdatamodel/contents @@ -8,6 +8,7 @@ + diff --git a/VoidLink/Network/DiscoveryManager.m b/VoidLink/Network/DiscoveryManager.m index 4cdabb96..360e758e 100644 --- a/VoidLink/Network/DiscoveryManager.m +++ b/VoidLink/Network/DiscoveryManager.m @@ -30,6 +30,7 @@ NSString* _uniqueId; NSData* _cert; BOOL shouldDiscover; + DataManager* dataMan; } - (id)initWithHosts:(NSArray *)hosts andCallback:(id)callback { @@ -52,6 +53,7 @@ [CryptoManager generateKeyPairUsingSSL]; _uniqueId = [IdManager getUniqueId]; _cert = [CryptoManager readCertFromFile]; + DataManager* dataMan = [[DataManager alloc] init]; return self; } @@ -139,6 +141,8 @@ if ([serverInfoResponse isStatusOk]) { host = [[TemporaryHost alloc] init]; host.activeAddress = host.address = hostAddress; + if(!host.activeAddressPool) host.activeAddressPool = [[NSMutableSet alloc] init]; + [host.activeAddressPool addObject:host.activeAddress]; host.state = StateOnline; [serverInfoResponse populateHost:host]; @@ -284,8 +288,9 @@ existingHost.externalAddress = host.externalAddress; } existingHost.activeAddress = host.activeAddress; + [existingHost.activeAddressPool addObject:host.activeAddress]; existingHost.state = host.state; - return NO; + return NO; // returning a "NO" here means Updating addresses of existing host } else { @synchronized (_hostQueue) { diff --git a/VoidLink/Network/DiscoveryWorker.m b/VoidLink/Network/DiscoveryWorker.m index a3c80aa7..86de7a6d 100644 --- a/VoidLink/Network/DiscoveryWorker.m +++ b/VoidLink/Network/DiscoveryWorker.m @@ -41,11 +41,21 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds } - (NSArray*) getHostAddressList { - NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:3]; + NSMutableArray *array = [[NSMutableArray alloc] init]; if (_host.localAddress != nil) { [array addObject:_host.localAddress]; } + if(_host.activeAddressPool.count>0){ + for(NSString* address in _host.activeAddressPool){ + if([address containsString:@":"]) break; + [array addObject:address]; + } + for(NSString* address in _host.activeAddressPool){ + if(![address containsString:@":"]) break; + [array addObject:address]; + } + } if (_host.address != nil) { [array addObject:_host.address]; } @@ -61,6 +71,7 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds // to preserve insertion order of addresses. for (int i = 0; i < [array count]; i++) { NSString *addr1 = [array objectAtIndex:i]; + NSLog(@"iterates discovery addrs %@, host: %@", addr1, _host.name); for (int j = 1; j < [array count]; j++) { if (i == j) { @@ -104,6 +115,8 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds receivedResponse = [self checkResponse:serverInfoResp]; if (receivedResponse) { _host.activeAddress = address; + if(!_host.activeAddressPool) _host.activeAddressPool = [[NSMutableSet alloc] init]; + [_host.activeAddressPool addObject:address]; [serverInfoResp populateHost:_host]; // Update the database using the response diff --git a/VoidLink/Network/MDNSManager.m b/VoidLink/Network/MDNSManager.m index c0e0265f..2f0e3def 100644 --- a/VoidLink/Network/MDNSManager.m +++ b/VoidLink/Network/MDNSManager.m @@ -228,6 +228,7 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp"; Log(LOG_I, @"IPv6 address chosen: %@ -> %@", [service hostName], host.ipv6Address); host.activeAddress = host.localAddress; + // [host.activeAddressPool addObject:host.localAddress]; host.name = service.hostName; [self.callback updateHost:host]; }); diff --git a/VoidLink/Network/ServerInfoResponse.m b/VoidLink/Network/ServerInfoResponse.m index 9b794dda..212598a3 100644 --- a/VoidLink/Network/ServerInfoResponse.m +++ b/VoidLink/Network/ServerInfoResponse.m @@ -46,6 +46,7 @@ // If we reached this host through this port, store our port there if (host.activeAddress && [lanAddr isEqualToString:[Utils addressPortStringToAddress:host.activeAddress]]) { localPort = [Utils addressPortStringToPort:host.activeAddress]; + [host.activeAddressPool addObject:host.activeAddress]; } else if (host.localAddress) { // If there's an existing local address, use the port from that @@ -57,6 +58,7 @@ } host.localAddress = [Utils addressAndPortToAddressPortString:lanAddr port:localPort]; + [host.activeAddressPool addObject:lanAddr]; } // This is a Sunshine extension for WAN port remapping diff --git a/VoidLink/ViewControllers/MainFrameViewController.m b/VoidLink/ViewControllers/MainFrameViewController.m index ec78583c..7d1a70e7 100644 --- a/VoidLink/ViewControllers/MainFrameViewController.m +++ b/VoidLink/ViewControllers/MainFrameViewController.m @@ -765,6 +765,10 @@ static NSMutableSet* hostList; [hostNotFoundAlert addAction:[UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Ok"] style:UIAlertActionStyleDefault handler:nil]]; dispatch_async(dispatch_get_main_queue(), ^{ [self hideLoadingFrame:^{ + if([error isEqualToString:[LocalizationHelper localizedStringForKey:@"Host information updated"]]){ + DataManager* dataMan = [[DataManager alloc] init]; + [dataMan updateHost:host]; + } [[self activeViewController] presentViewController:hostNotFoundAlert animated:YES completion:nil]; }]; });