/// <summary> /// Queues a search for a route to a network /// </summary> /// <param name="network">The network to search for</param> private void _queueNetworkSearch(ushort network) { foreach (var timer in _networkSearchTimers) { if (timer.Network == network) { timer.Reset(); return; } } var newTimer = new NetworkSearchTimer(this, network); _networkSearchTimers.AddLast(newTimer); }
/// <summary> /// Called whenever a network search ticks /// </summary> /// <param name="timer">The timer instance</param> /// <param name="attempt">The attempt number</param> private void _networkSearchTick(NetworkSearchTimer timer, int attempt) { lock (_lock) { if (!_networkSearchTimers.Contains(timer)) { // if the timer is not present, it has already // been disposed (probably because the i-am-router // request came back) so we don't need to do anything return; } if (attempt <= Router.NetworkSearchAttempts) { _searchForRouteToNetwork(timer.Network); } else { for (var node = _netgramQueue.First; node != null;) { if (node.Value.Destination.Network == timer.Network) { var temp = node.Next; _netgramQueue.Remove(node); node = temp; } else { node = node.Next; } } _networkSearchTimers.Remove(timer); timer.Dispose(); } } }