Пример #1
0
        //call StartNetwork after network changed
        //forcerestart will make current http request failed.
        public void StartNetwork(bool forcerestart)
        {
            if (forcerestart || (WebServer == null) || (WebServer.State != WebServerState.Listening) || (nodeDiscovery.State != NodeDiscoveryState.Listening))
            {
                InitWebServer();
                nodeDiscovery.StopNetwork();
                CleanKnownNodes();
            }
            else
            {
                using var cts = new CancellationTokenSource(500);
                try
                {
                    using var resp = httpclient.GetAsync($"http://127.0.0.1:{ServerPort}/", HttpCompletionOption.ResponseHeadersRead, cts.Token).Result;
                }
                catch
                {
                    InitWebServer();
                    nodeDiscovery.StopNetwork();
                    CleanKnownNodes();
                }
            }

            nodeDiscovery.StartMonitoring();
            _ = nodeDiscovery.RePublish(NodeId, ServerPort);
            nodeDiscovery.StartSearch();
        }