From 7767ae497b23c859a9824a6bd78f910ef8043407 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 6 Apr 2015 00:22:51 -0400 Subject: [PATCH] Revert "Added a hack to de-duplicate hosts and some more checks when adding a host to minimize the chances for dupes" This reverts commit fd9ee45daccb3d119218ba3dfb0a6b7f59e4121c. --- Limelight/Network/CleanupCrew.h | 22 ------------ Limelight/Network/CleanupCrew.m | 54 ---------------------------- Limelight/Network/DiscoveryManager.h | 3 +- Limelight/Network/DiscoveryManager.m | 29 +++++---------- 4 files changed, 10 insertions(+), 98 deletions(-) delete mode 100644 Limelight/Network/CleanupCrew.h delete mode 100644 Limelight/Network/CleanupCrew.m diff --git a/Limelight/Network/CleanupCrew.h b/Limelight/Network/CleanupCrew.h deleted file mode 100644 index ae48f94..0000000 --- a/Limelight/Network/CleanupCrew.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// CleanupCrew.h -// Limelight -// -// Created by Diego Waxemberg on 4/5/15. -// Copyright (c) 2015 Limelight Stream. All rights reserved. -// - -#import -#import "Host.h" - -@protocol CleanupCallback - -- (void) cleanedUpHosts:(NSSet*) host; - -@end - -@interface CleanupCrew : NSOperation - -- (id) initWithHostList:(NSArray*) hostList andCallback:(id)callback; - -@end diff --git a/Limelight/Network/CleanupCrew.m b/Limelight/Network/CleanupCrew.m deleted file mode 100644 index 791baf6..0000000 --- a/Limelight/Network/CleanupCrew.m +++ /dev/null @@ -1,54 +0,0 @@ -// -// CleanupCrew.m -// Limelight -// -// Created by Diego Waxemberg on 4/5/15. -// Copyright (c) 2015 Limelight Stream. All rights reserved. -// - -#import "CleanupCrew.h" - -@implementation CleanupCrew { - NSArray* _hostList; - id _callback; -} - -static const int CLEANUP_RATE = 2; - - -- (id) initWithHostList:(NSArray *)hostList andCallback:(id)callback { - self = [super init]; - _hostList = hostList; - _callback = callback; - return self; -} - -- (void) main { - while (!self.isCancelled) { - NSMutableSet* dirtyHosts = [[NSMutableSet alloc] init]; - - for (Host* host in _hostList) { - for (Host* other in _hostList) { - if (self.isCancelled) { - break; - } - - // We check the name as well as a hack to remove duplicates - if (host != other && ([host.uuid isEqualToString:other.uuid] - || [host.name isEqualToString:other.name])) { - [dirtyHosts addObject:other]; - } - } - } - - if (dirtyHosts.count > 0) { - [_callback cleanedUpHosts:dirtyHosts]; - } - - if (!self.cancelled) { - [NSThread sleepForTimeInterval:CLEANUP_RATE]; - } - } -} - -@end diff --git a/Limelight/Network/DiscoveryManager.h b/Limelight/Network/DiscoveryManager.h index 36db9ff..f0a75a9 100644 --- a/Limelight/Network/DiscoveryManager.h +++ b/Limelight/Network/DiscoveryManager.h @@ -9,7 +9,6 @@ #import #import "MDNSManager.h" #import "Host.h" -#import "CleanupCrew.h" @protocol DiscoveryCallback @@ -17,7 +16,7 @@ @end -@interface DiscoveryManager : NSObject +@interface DiscoveryManager : NSObject - (id) initWithHosts:(NSArray*)hosts andCallback:(id) callback; - (void) startDiscovery; diff --git a/Limelight/Network/DiscoveryManager.m b/Limelight/Network/DiscoveryManager.m index 99ca24d..b7f208e 100644 --- a/Limelight/Network/DiscoveryManager.m +++ b/Limelight/Network/DiscoveryManager.m @@ -15,7 +15,7 @@ #import "ServerInfoResponse.h" @implementation DiscoveryManager { - NSMutableArray* _hostList; + NSMutableArray* _hostQueue; NSMutableArray* _discoveredHosts; id _callback; MDNSManager* _mdnsMan; @@ -27,7 +27,7 @@ - (id)initWithHosts:(NSArray *)hosts andCallback:(id)callback { self = [super init]; - _hostList = [NSMutableArray arrayWithArray:hosts]; + _hostQueue = [NSMutableArray arrayWithArray:hosts]; _callback = callback; _opQueue = [[NSOperationQueue alloc] init]; _mdnsMan = [[MDNSManager alloc] initWithCallback:self]; @@ -66,11 +66,9 @@ Log(LOG_I, @"Starting discovery"); shouldDiscover = YES; [_mdnsMan searchForHosts]; - for (Host* host in _hostList) { + for (Host* host in _hostQueue) { [_opQueue addOperation:[self createWorkerForHost:host]]; } - CleanupCrew* cleanup = [[CleanupCrew alloc] initWithHostList:_hostList andCallback:self]; - [_opQueue addOperation:cleanup]; } - (void) stopDiscovery { @@ -90,8 +88,8 @@ } - (BOOL) addHostToDiscovery:(Host *)host { - if (host.uuid.length > 0 && ![self isHostInDiscovery:host]) { - [_hostList addObject:host]; + if (![self isHostInDiscovery:host]) { + [_hostQueue addObject:host]; if (shouldDiscover) { [_opQueue addOperation:[self createWorkerForHost:host]]; } @@ -106,16 +104,7 @@ [worker cancel]; } } - [_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]; + [_hostQueue removeObject:host]; } // Override from MDNSCallback @@ -130,7 +119,7 @@ [worker discoverHost]; if ([self addHostToDiscovery:host]) { Log(LOG_I, @"Adding host to discovery: %@", host.name); - [_callback updateAllHosts:_hostList]; + [_callback updateAllHosts:_hostQueue]; } else { Log(LOG_I, @"Not adding host to discovery: %@", host.name); [dataMan removeHost:host]; @@ -141,8 +130,8 @@ } - (BOOL) isHostInDiscovery:(Host*)host { - for (int i = 0; i < _hostList.count; i++) { - Host* discoveredHost = [_hostList objectAtIndex:i]; + for (int i = 0; i < _hostQueue.count; i++) { + Host* discoveredHost = [_hostQueue objectAtIndex:i]; if (discoveredHost.uuid.length > 0 && [discoveredHost.uuid isEqualToString:host.uuid]) { return YES; }