void RestartCoreWorker(Action next) { JObject cfg = GetDecodedConfig(true, false, true); if (cfg == null) { StopCoreThen(next); return; } if (!OverwriteInboundSettings( ref cfg, overwriteInboundType, this.inboundIP, this.inboundPort)) { StopCoreThen(next); return; } InjectSkipCNSite(ref cfg); server.RestartCoreThen( cfg.ToString(), next, Lib.Utils.GetEnvVarsFromConfig(cfg)); }
public void RestartCoreWorker(Action next) { JObject cfg = GetDecodedConfig(true); if (cfg == null) { StopCoreThen(next); return; } if (!OverwriteInboundSettings( ref cfg, overwriteInboundType, this.inboundIP, this.inboundPort)) { StopCoreThen(next); return; } server.RestartCoreThen( cfg.ToString(), OnCoreStateChanged, next, Lib.Utils.GetEnvVarsFromConfig(cfg)); }
public void DoSpeedTestThen(Action next = null) { void log(string msg) { SendLog(msg); SetStatus(msg); } void error(string msg) { log(msg); next?.Invoke(); } var port = Lib.Utils.GetFreeTcpPort(); if (port <= 0) { error(I18N("GetFreePortFail")); return; } Thread.Sleep(100); var cfg = GetDecodedConfig(true); if (cfg == null) { error(I18N("DecodeImportFail")); return; } if (!OverwriteInboundSettings( ref cfg, (int)Model.Data.Enum.ProxyTypes.HTTP, "127.0.0.1", port)) { error(I18N("CoreCantSetLocalAddr")); return; } var url = StrConst("SpeedTestUrl"); var text = I18N("Testing") + " ..."; log(text); SendLog(url); var speedTester = new Model.BaseClass.CoreServer(); speedTester.OnLog += OnLogHandler; speedTester.RestartCoreThen(cfg.ToString(), null, () => { // v2ray-core need a little time to get ready. Thread.Sleep(1000); var time = Lib.Utils.VisitWebPageSpeedTest(url, port); text = string.Format("{0}:{1}", I18N("VisitWebPageTest"), time > 0 ? time.ToString() + "ms" : I18N("Timeout")); log(text); speedTester.StopCoreThen(() => { speedTester.OnLog -= OnLogHandler; next?.Invoke(); }); }); }