mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-16 21:50:57 +00:00
Added a hack to de-duplicate hosts and some more checks when adding a host to minimize the chances for dupes
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#import "ServerInfoResponse.h"
|
||||
|
||||
@implementation DiscoveryManager {
|
||||
NSMutableArray* _hostQueue;
|
||||
NSMutableArray* _hostList;
|
||||
NSMutableArray* _discoveredHosts;
|
||||
id<DiscoveryCallback> _callback;
|
||||
MDNSManager* _mdnsMan;
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
- (id)initWithHosts:(NSArray *)hosts andCallback:(id<DiscoveryCallback>)callback {
|
||||
self = [super init];
|
||||
_hostQueue = [NSMutableArray arrayWithArray:hosts];
|
||||
_hostList = [NSMutableArray arrayWithArray:hosts];
|
||||
_callback = callback;
|
||||
_opQueue = [[NSOperationQueue alloc] init];
|
||||
_mdnsMan = [[MDNSManager alloc] initWithCallback:self];
|
||||
@@ -66,9 +66,11 @@
|
||||
Log(LOG_I, @"Starting discovery");
|
||||
shouldDiscover = YES;
|
||||
[_mdnsMan searchForHosts];
|
||||
for (Host* host in _hostQueue) {
|
||||
for (Host* host in _hostList) {
|
||||
[_opQueue addOperation:[self createWorkerForHost:host]];
|
||||
}
|
||||
CleanupCrew* cleanup = [[CleanupCrew alloc] initWithHostList:_hostList andCallback:self];
|
||||
[_opQueue addOperation:cleanup];
|
||||
}
|
||||
|
||||
- (void) stopDiscovery {
|
||||
@@ -88,8 +90,8 @@
|
||||
}
|
||||
|
||||
- (BOOL) addHostToDiscovery:(Host *)host {
|
||||
if (![self isHostInDiscovery:host]) {
|
||||
[_hostQueue addObject:host];
|
||||
if (host.uuid.length > 0 && ![self isHostInDiscovery:host]) {
|
||||
[_hostList addObject:host];
|
||||
if (shouldDiscover) {
|
||||
[_opQueue addOperation:[self createWorkerForHost:host]];
|
||||
}
|
||||
@@ -104,7 +106,16 @@
|
||||
[worker cancel];
|
||||
}
|
||||
}
|
||||
[_hostQueue removeObject:host];
|
||||
[_hostList removeObject:host];
|
||||
}
|
||||
|
||||
// Override from CleanupCallback
|
||||
- (void) cleanedUpHosts:(NSSet*)dirtyHosts {
|
||||
for (Host* host in dirtyHosts) {
|
||||
Log(LOG_I, @"Cleaning up duplicate host: %@", host.name);
|
||||
[self removeHostFromDiscovery:host];
|
||||
}
|
||||
[_callback updateAllHosts:_hostList];
|
||||
}
|
||||
|
||||
// Override from MDNSCallback
|
||||
@@ -119,7 +130,7 @@
|
||||
[worker discoverHost];
|
||||
if ([self addHostToDiscovery:host]) {
|
||||
Log(LOG_I, @"Adding host to discovery: %@", host.name);
|
||||
[_callback updateAllHosts:_hostQueue];
|
||||
[_callback updateAllHosts:_hostList];
|
||||
} else {
|
||||
Log(LOG_I, @"Not adding host to discovery: %@", host.name);
|
||||
[dataMan removeHost:host];
|
||||
@@ -129,8 +140,8 @@
|
||||
}
|
||||
|
||||
- (BOOL) isHostInDiscovery:(Host*)host {
|
||||
for (int i = 0; i < _hostQueue.count; i++) {
|
||||
Host* discoveredHost = [_hostQueue objectAtIndex:i];
|
||||
for (int i = 0; i < _hostList.count; i++) {
|
||||
Host* discoveredHost = [_hostList objectAtIndex:i];
|
||||
if (discoveredHost.uuid.length > 0 && [discoveredHost.uuid isEqualToString:host.uuid]) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user