internal static IEnumerable<NodeModel> GenerateRandomConnectedNodes(NodeModel model)
        {
            var otherNodes = Nodes.ToArray().Where(kvp => kvp.Key != model.Guid).Select(kvp => new NodeModel { Guid = kvp.Key, Hostname = kvp.Value.Item1, Port = kvp.Value.Item2 }).ToList();

            var connectedNodes = new List<NodeModel>(otherNodes.Count);
            var modelConnectionsCount = Randomizer.Next(otherNodes.Count / 2);

            for (int i = modelConnectionsCount - 1; i >= 0; i--)
            {
                var otherNodeIdx = Randomizer.Next(otherNodes.Count);
                connectedNodes.Add(otherNodes[otherNodeIdx]);
                otherNodes.RemoveAt(otherNodeIdx);
            }

            return connectedNodes;
        }
 internal static async Task SendConnectToModel(NodeModel model, IEnumerable<NodeModel> connectedNodes)
 {
     var uriBuilder = new UriBuilder(Uri.UriSchemeHttp, model.Hostname, model.Port, "/connectToNodes");
     var req = WebRequest.Create(uriBuilder.Uri) as HttpWebRequest;
     req.Method = WebRequestMethods.Http.Post;
     req.ContentType = new ContentType(MediaTypeNames.Text.Plain) { CharSet = Encoding.ASCII.WebName }.ToString();
     var reqData = Encoding.ASCII.GetBytes(string.Join(Environment.NewLine, connectedNodes.Select(n => $"{n.Hostname}:{n.Port}")));
     req.ContentLength = reqData.LongLength;
     try
     {
         using (var reqStream = await req.GetRequestStreamAsync())
         {
             await reqStream.WriteAsync(reqData, 0, reqData.Length);
             await reqStream.FlushAsync();
         }
         using (var resp = await req.GetResponseAsync() as HttpWebResponse) { }
     }
     catch (WebException) { }
 }
 private static async Task SendDisconnectToModel(NodeModel model)
 {
     var uriBuilder = new UriBuilder(Uri.UriSchemeHttp, model.Hostname, model.Port, "/clearConnections");
     var req = WebRequest.Create(uriBuilder.Uri) as HttpWebRequest;
     try
     {
         using (var resp = await req.GetResponseAsync() as HttpWebResponse) { }
     }
     catch (WebException) { }
 }