Пример #1
0
        private void NewNodeHandler(RedisChannel arg1, RedisValue arg2)
        {
            var ep = ((byte[])arg2).ParseIP();

            var nn = new Node(Redis, (ip) => { NewNodeQueue.Post(ip); }, GeoIp, ep);

            if (!nn.IsBadNode().Result&& !nn.IsGoodNode().Result)  //exclude already known nodes
            {
                NewNodeSemaphore.Wait();
                Console.WriteLine($"Checking new node {ep}");
                Task.Factory.StartNew(async() =>
                {
                    await nn.Connect();
                    NewNodeSemaphore.Release();
                });
            }
        }
Пример #2
0
        private async Task NewNodeWorker()
        {
            while (Running)
            {
                var ep = await NewNodeQueue.ReceiveAsync();

                var nn = new Node(Redis, (ip) => { NewNodeQueue.Post(ip); }, GeoIp, ep);
                if (!await nn.IsBadNode() && !await nn.IsGoodNode()) //exclude already known nodes
                {
                    await NewNodeSemaphore.WaitAsync();

                    Console.WriteLine($"Checking new node {ep}");
                    await Task.Factory.StartNew(async() =>
                    {
                        await nn.Connect();
                        NewNodeSemaphore.Release();
                    });
                }
            }
        }