You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ShadowsocksController.cs 24 kB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Net;
  6. using System.Net.Sockets;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Web;
  10. using System.Windows.Forms;
  11. using Newtonsoft.Json;
  12. using Shadowsocks.Controller.Strategy;
  13. using Shadowsocks.Model;
  14. using Shadowsocks.Properties;
  15. using Shadowsocks.Util;
  16. using System.Linq;
  17. using Shadowsocks.Controller.Service;
  18. using Shadowsocks.Proxy;
  19. namespace Shadowsocks.Controller
  20. {
  21. public class ShadowsocksController
  22. {
  23. // controller:
  24. // handle user actions
  25. // manipulates UI
  26. // interacts with low level logic
  27. private Thread _ramThread;
  28. private Thread _trafficThread;
  29. private Listener _listener;
  30. private PACServer _pacServer;
  31. private Configuration _config;
  32. private StrategyManager _strategyManager;
  33. private PrivoxyRunner privoxyRunner;
  34. private GFWListUpdater gfwListUpdater;
  35. private readonly ConcurrentDictionary<Server, Sip003Plugin> _pluginsByServer;
  36. public AvailabilityStatistics availabilityStatistics = AvailabilityStatistics.Instance;
  37. public StatisticsStrategyConfiguration StatisticsConfiguration { get; private set; }
  38. private long _inboundCounter = 0;
  39. private long _outboundCounter = 0;
  40. public long InboundCounter => Interlocked.Read(ref _inboundCounter);
  41. public long OutboundCounter => Interlocked.Read(ref _outboundCounter);
  42. public Queue<TrafficPerSecond> trafficPerSecondQueue;
  43. private bool stopped = false;
  44. public class PathEventArgs : EventArgs
  45. {
  46. public string Path;
  47. }
  48. public class TrafficPerSecond
  49. {
  50. public long inboundCounter;
  51. public long outboundCounter;
  52. public long inboundIncreasement;
  53. public long outboundIncreasement;
  54. }
  55. public event EventHandler ConfigChanged;
  56. public event EventHandler EnableStatusChanged;
  57. public event EventHandler EnableGlobalChanged;
  58. public event EventHandler ShareOverLANStatusChanged;
  59. public event EventHandler VerboseLoggingStatusChanged;
  60. public event EventHandler TrafficChanged;
  61. // when user clicked Edit PAC, and PAC file has already created
  62. public event EventHandler<PathEventArgs> PACFileReadyToOpen;
  63. public event EventHandler<PathEventArgs> UserRuleFileReadyToOpen;
  64. public event EventHandler<GFWListUpdater.ResultEventArgs> UpdatePACFromGFWListCompleted;
  65. public event ErrorEventHandler UpdatePACFromGFWListError;
  66. public event ErrorEventHandler Errored;
  67. public ShadowsocksController()
  68. {
  69. _config = Configuration.Load();
  70. StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
  71. _strategyManager = new StrategyManager(this);
  72. _pluginsByServer = new ConcurrentDictionary<Server, Sip003Plugin>();
  73. StartReleasingMemory();
  74. StartTrafficStatistics(61);
  75. }
  76. public void Start()
  77. {
  78. Reload();
  79. }
  80. protected void ReportError(Exception e)
  81. {
  82. if (Errored != null)
  83. {
  84. Errored(this, new ErrorEventArgs(e));
  85. }
  86. }
  87. public Server GetCurrentServer()
  88. {
  89. return _config.GetCurrentServer();
  90. }
  91. // always return copy
  92. public Configuration GetConfigurationCopy()
  93. {
  94. return Configuration.Load();
  95. }
  96. // always return current instance
  97. public Configuration GetCurrentConfiguration()
  98. {
  99. return _config;
  100. }
  101. public IList<IStrategy> GetStrategies()
  102. {
  103. return _strategyManager.GetStrategies();
  104. }
  105. public IStrategy GetCurrentStrategy()
  106. {
  107. foreach (var strategy in _strategyManager.GetStrategies())
  108. {
  109. if (strategy.ID == this._config.strategy)
  110. {
  111. return strategy;
  112. }
  113. }
  114. return null;
  115. }
  116. public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint, EndPoint destEndPoint)
  117. {
  118. IStrategy strategy = GetCurrentStrategy();
  119. if (strategy != null)
  120. {
  121. return strategy.GetAServer(type, localIPEndPoint, destEndPoint);
  122. }
  123. if (_config.index < 0)
  124. {
  125. _config.index = 0;
  126. }
  127. return GetCurrentServer();
  128. }
  129. public EndPoint GetPluginLocalEndPointIfConfigured(Server server)
  130. {
  131. var plugin = _pluginsByServer.GetOrAdd(server, Sip003Plugin.CreateIfConfigured);
  132. if (plugin == null)
  133. {
  134. return null;
  135. }
  136. try
  137. {
  138. if (plugin.StartIfNeeded())
  139. {
  140. Logging.Info(
  141. $"Started SIP003 plugin for {server.Identifier()} on {plugin.LocalEndPoint} - PID: {plugin.ProcessId}");
  142. }
  143. }
  144. catch (Exception ex)
  145. {
  146. Logging.Error("Failed to start SIP003 plugin: " + ex.Message);
  147. throw;
  148. }
  149. return plugin.LocalEndPoint;
  150. }
  151. public void SaveServers(List<Server> servers, int localPort)
  152. {
  153. _config.configs = servers;
  154. _config.localPort = localPort;
  155. Configuration.Save(_config);
  156. }
  157. public void SaveStrategyConfigurations(StatisticsStrategyConfiguration configuration)
  158. {
  159. StatisticsConfiguration = configuration;
  160. StatisticsStrategyConfiguration.Save(configuration);
  161. }
  162. public bool AddServerBySSURL(string ssURL)
  163. {
  164. try
  165. {
  166. if (ssURL.IsNullOrEmpty() || ssURL.IsWhiteSpace()) return false;
  167. var servers = Server.GetServers(ssURL);
  168. if (servers == null || servers.Count == 0) return false;
  169. foreach (var server in servers)
  170. {
  171. _config.configs.Add(server);
  172. }
  173. _config.index = _config.configs.Count - 1;
  174. SaveConfig(_config);
  175. return true;
  176. }
  177. catch (Exception e)
  178. {
  179. Logging.LogUsefulException(e);
  180. return false;
  181. }
  182. }
  183. public void ToggleEnable(bool enabled)
  184. {
  185. _config.enabled = enabled;
  186. SaveConfig(_config);
  187. if (EnableStatusChanged != null)
  188. {
  189. EnableStatusChanged(this, new EventArgs());
  190. }
  191. }
  192. public void ToggleGlobal(bool global)
  193. {
  194. _config.global = global;
  195. SaveConfig(_config);
  196. if (EnableGlobalChanged != null)
  197. {
  198. EnableGlobalChanged(this, new EventArgs());
  199. }
  200. }
  201. public void ToggleShareOverLAN(bool enabled)
  202. {
  203. _config.shareOverLan = enabled;
  204. SaveConfig(_config);
  205. if (ShareOverLANStatusChanged != null)
  206. {
  207. ShareOverLANStatusChanged(this, new EventArgs());
  208. }
  209. }
  210. public void DisableProxy()
  211. {
  212. _config.proxy.useProxy = false;
  213. SaveConfig(_config);
  214. }
  215. public void EnableProxy(int type, string proxy, int port, int timeout)
  216. {
  217. _config.proxy.useProxy = true;
  218. _config.proxy.proxyType = type;
  219. _config.proxy.proxyServer = proxy;
  220. _config.proxy.proxyPort = port;
  221. _config.proxy.proxyTimeout = timeout;
  222. SaveConfig(_config);
  223. }
  224. public void ToggleVerboseLogging(bool enabled)
  225. {
  226. _config.isVerboseLogging = enabled;
  227. SaveConfig(_config);
  228. if ( VerboseLoggingStatusChanged != null ) {
  229. VerboseLoggingStatusChanged(this, new EventArgs());
  230. }
  231. }
  232. public void SelectServerIndex(int index)
  233. {
  234. _config.index = index;
  235. _config.strategy = null;
  236. SaveConfig(_config);
  237. }
  238. public void SelectStrategy(string strategyID)
  239. {
  240. _config.index = -1;
  241. _config.strategy = strategyID;
  242. SaveConfig(_config);
  243. }
  244. public void Stop()
  245. {
  246. if (stopped)
  247. {
  248. return;
  249. }
  250. stopped = true;
  251. if (_listener != null)
  252. {
  253. _listener.Stop();
  254. }
  255. StopPlugins();
  256. if (privoxyRunner != null)
  257. {
  258. privoxyRunner.Stop();
  259. }
  260. if (_config.enabled)
  261. {
  262. SystemProxy.Update(_config, true, null);
  263. }
  264. Encryption.RNG.Close();
  265. }
  266. private void StopPlugins()
  267. {
  268. foreach (var serverAndPlugin in _pluginsByServer)
  269. {
  270. serverAndPlugin.Value?.Dispose();
  271. }
  272. _pluginsByServer.Clear();
  273. }
  274. public void TouchPACFile()
  275. {
  276. string pacFilename = _pacServer.TouchPACFile();
  277. if (PACFileReadyToOpen != null)
  278. {
  279. PACFileReadyToOpen(this, new PathEventArgs() { Path = pacFilename });
  280. }
  281. }
  282. public void TouchUserRuleFile()
  283. {
  284. string userRuleFilename = _pacServer.TouchUserRuleFile();
  285. if (UserRuleFileReadyToOpen != null)
  286. {
  287. UserRuleFileReadyToOpen(this, new PathEventArgs() { Path = userRuleFilename });
  288. }
  289. }
  290. public string GetQRCodeForCurrentServer()
  291. {
  292. Server server = GetCurrentServer();
  293. return GetQRCode(server);
  294. }
  295. public static string GetQRCode(Server server)
  296. {
  297. string tag = string.Empty;
  298. string url = string.Empty;
  299. if (string.IsNullOrWhiteSpace(server.plugin))
  300. {
  301. // For backwards compatiblity, if no plugin, use old url format
  302. string parts = $"{server.method}:{server.password}@{server.server}:{server.server_port}";
  303. string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
  304. url = base64;
  305. }
  306. else
  307. {
  308. // SIP002
  309. string parts = $"{server.method}:{server.password}";
  310. string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
  311. string websafeBase64 = base64.Replace('+', '-').Replace('/', '_').TrimEnd('=');
  312. string pluginPart = server.plugin;
  313. if (!string.IsNullOrWhiteSpace(server.plugin_opts))
  314. {
  315. pluginPart += ";" + server.plugin_opts;
  316. }
  317. url = string.Format(
  318. "{0}@{1}:{2}/?plugin={3}",
  319. websafeBase64,
  320. HttpUtility.UrlEncode(server.server, Encoding.UTF8),
  321. server.server_port,
  322. HttpUtility.UrlEncode(pluginPart, Encoding.UTF8));
  323. }
  324. if (!server.remarks.IsNullOrEmpty())
  325. {
  326. tag = $"#{HttpUtility.UrlEncode(server.remarks, Encoding.UTF8)}";
  327. }
  328. return $"ss://{url}{tag}";
  329. }
  330. public void UpdatePACFromGFWList()
  331. {
  332. if (gfwListUpdater != null)
  333. {
  334. gfwListUpdater.UpdatePACFromGFWList(_config);
  335. }
  336. }
  337. public void UpdateStatisticsConfiguration(bool enabled)
  338. {
  339. if (availabilityStatistics == null) return;
  340. availabilityStatistics.UpdateConfiguration(this);
  341. _config.availabilityStatistics = enabled;
  342. SaveConfig(_config);
  343. }
  344. public void SavePACUrl(string pacUrl)
  345. {
  346. _config.pacUrl = pacUrl;
  347. SaveConfig(_config);
  348. if (ConfigChanged != null)
  349. {
  350. ConfigChanged(this, new EventArgs());
  351. }
  352. }
  353. public void UseOnlinePAC(bool useOnlinePac)
  354. {
  355. _config.useOnlinePac = useOnlinePac;
  356. SaveConfig(_config);
  357. if (ConfigChanged != null)
  358. {
  359. ConfigChanged(this, new EventArgs());
  360. }
  361. }
  362. public void ToggleSecureLocalPac(bool enabled)
  363. {
  364. _config.secureLocalPac = enabled;
  365. SaveConfig(_config);
  366. if (ConfigChanged != null)
  367. {
  368. ConfigChanged(this, new EventArgs());
  369. }
  370. }
  371. public void ToggleCheckingUpdate(bool enabled)
  372. {
  373. _config.autoCheckUpdate = enabled;
  374. Configuration.Save(_config);
  375. if (ConfigChanged != null)
  376. {
  377. ConfigChanged(this, new EventArgs());
  378. }
  379. }
  380. public void ToggleCheckingPreRelease(bool enabled)
  381. {
  382. _config.checkPreRelease = enabled;
  383. Configuration.Save(_config);
  384. if (ConfigChanged != null)
  385. {
  386. ConfigChanged(this, new EventArgs());
  387. }
  388. }
  389. public void SaveLogViewerConfig(LogViewerConfig newConfig)
  390. {
  391. _config.logViewer = newConfig;
  392. newConfig.SaveSize();
  393. Configuration.Save(_config);
  394. if (ConfigChanged != null)
  395. {
  396. ConfigChanged(this, new EventArgs());
  397. }
  398. }
  399. public void SaveHotkeyConfig(HotkeyConfig newConfig)
  400. {
  401. _config.hotkey = newConfig;
  402. SaveConfig(_config);
  403. if (ConfigChanged != null)
  404. {
  405. ConfigChanged(this, new EventArgs());
  406. }
  407. }
  408. public void UpdateLatency(Server server, TimeSpan latency)
  409. {
  410. if (_config.availabilityStatistics)
  411. {
  412. availabilityStatistics.UpdateLatency(server, (int)latency.TotalMilliseconds);
  413. }
  414. }
  415. public void UpdateInboundCounter(Server server, long n)
  416. {
  417. Interlocked.Add(ref _inboundCounter, n);
  418. if (_config.availabilityStatistics)
  419. {
  420. availabilityStatistics.UpdateInboundCounter(server, n);
  421. }
  422. }
  423. public void UpdateOutboundCounter(Server server, long n)
  424. {
  425. Interlocked.Add(ref _outboundCounter, n);
  426. if (_config.availabilityStatistics)
  427. {
  428. availabilityStatistics.UpdateOutboundCounter(server, n);
  429. }
  430. }
  431. protected void Reload()
  432. {
  433. StopPlugins();
  434. Encryption.RNG.Reload();
  435. // some logic in configuration updated the config when saving, we need to read it again
  436. _config = Configuration.Load();
  437. StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
  438. if (privoxyRunner == null)
  439. {
  440. privoxyRunner = new PrivoxyRunner();
  441. }
  442. if (_pacServer == null)
  443. {
  444. _pacServer = new PACServer();
  445. _pacServer.PACFileChanged += pacServer_PACFileChanged;
  446. _pacServer.UserRuleFileChanged += pacServer_UserRuleFileChanged;
  447. }
  448. _pacServer.UpdateConfiguration(_config);
  449. if (gfwListUpdater == null)
  450. {
  451. gfwListUpdater = new GFWListUpdater();
  452. gfwListUpdater.UpdateCompleted += pacServer_PACUpdateCompleted;
  453. gfwListUpdater.Error += pacServer_PACUpdateError;
  454. }
  455. availabilityStatistics.UpdateConfiguration(this);
  456. if (_listener != null)
  457. {
  458. _listener.Stop();
  459. }
  460. // don't put PrivoxyRunner.Start() before pacServer.Stop()
  461. // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
  462. // though UseShellExecute is set to true now
  463. // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
  464. privoxyRunner.Stop();
  465. try
  466. {
  467. var strategy = GetCurrentStrategy();
  468. if (strategy != null)
  469. {
  470. strategy.ReloadServers();
  471. }
  472. StartPlugins();
  473. privoxyRunner.Start(_config);
  474. TCPRelay tcpRelay = new TCPRelay(this, _config);
  475. UDPRelay udpRelay = new UDPRelay(this);
  476. List<Listener.IService> services = new List<Listener.IService>();
  477. services.Add(tcpRelay);
  478. services.Add(udpRelay);
  479. services.Add(_pacServer);
  480. services.Add(new PortForwarder(privoxyRunner.RunningPort));
  481. _listener = new Listener(services);
  482. _listener.Start(_config);
  483. }
  484. catch (Exception e)
  485. {
  486. // translate Microsoft language into human language
  487. // i.e. An attempt was made to access a socket in a way forbidden by its access permissions => Port already in use
  488. if (e is SocketException)
  489. {
  490. SocketException se = (SocketException)e;
  491. if (se.SocketErrorCode == SocketError.AccessDenied)
  492. {
  493. e = new Exception(I18N.GetString("Port already in use"), e);
  494. }
  495. }
  496. Logging.LogUsefulException(e);
  497. ReportError(e);
  498. }
  499. if (ConfigChanged != null)
  500. {
  501. ConfigChanged(this, new EventArgs());
  502. }
  503. UpdateSystemProxy();
  504. Utils.ReleaseMemory(true);
  505. }
  506. private void StartPlugins()
  507. {
  508. foreach (var server in _config.configs)
  509. {
  510. // Early start plugin processes
  511. GetPluginLocalEndPointIfConfigured(server);
  512. }
  513. }
  514. protected void SaveConfig(Configuration newConfig)
  515. {
  516. Configuration.Save(newConfig);
  517. Reload();
  518. }
  519. private void UpdateSystemProxy()
  520. {
  521. SystemProxy.Update(_config, false, _pacServer);
  522. }
  523. private void pacServer_PACFileChanged(object sender, EventArgs e)
  524. {
  525. UpdateSystemProxy();
  526. }
  527. private void pacServer_PACUpdateCompleted(object sender, GFWListUpdater.ResultEventArgs e)
  528. {
  529. if (UpdatePACFromGFWListCompleted != null)
  530. UpdatePACFromGFWListCompleted(this, e);
  531. }
  532. private void pacServer_PACUpdateError(object sender, ErrorEventArgs e)
  533. {
  534. if (UpdatePACFromGFWListError != null)
  535. UpdatePACFromGFWListError(this, e);
  536. }
  537. private static readonly IEnumerable<char> IgnoredLineBegins = new[] { '!', '[' };
  538. private void pacServer_UserRuleFileChanged(object sender, EventArgs e)
  539. {
  540. // TODO: this is a dirty hack. (from code GListUpdater.http_DownloadStringCompleted())
  541. if (!File.Exists(Utils.GetTempPath("gfwlist.txt")))
  542. {
  543. UpdatePACFromGFWList();
  544. return;
  545. }
  546. List<string> lines = GFWListUpdater.ParseResult(FileManager.NonExclusiveReadAllText(Utils.GetTempPath("gfwlist.txt")));
  547. if (File.Exists(PACServer.USER_RULE_FILE))
  548. {
  549. string local = FileManager.NonExclusiveReadAllText(PACServer.USER_RULE_FILE, Encoding.UTF8);
  550. using (var sr = new StringReader(local))
  551. {
  552. foreach (var rule in sr.NonWhiteSpaceLines())
  553. {
  554. if (rule.BeginWithAny(IgnoredLineBegins))
  555. continue;
  556. lines.Add(rule);
  557. }
  558. }
  559. }
  560. string abpContent;
  561. if (File.Exists(PACServer.USER_ABP_FILE))
  562. {
  563. abpContent = FileManager.NonExclusiveReadAllText(PACServer.USER_ABP_FILE, Encoding.UTF8);
  564. }
  565. else
  566. {
  567. abpContent = Utils.UnGzip(Resources.abp_js);
  568. }
  569. abpContent = abpContent.Replace("__RULES__", JsonConvert.SerializeObject(lines, Formatting.Indented));
  570. if (File.Exists(PACServer.PAC_FILE))
  571. {
  572. string original = FileManager.NonExclusiveReadAllText(PACServer.PAC_FILE, Encoding.UTF8);
  573. if (original == abpContent)
  574. {
  575. return;
  576. }
  577. }
  578. File.WriteAllText(PACServer.PAC_FILE, abpContent, Encoding.UTF8);
  579. }
  580. public void CopyPacUrl()
  581. {
  582. Clipboard.SetDataObject(_pacServer.PacUrl);
  583. }
  584. #region Memory Management
  585. private void StartReleasingMemory()
  586. {
  587. _ramThread = new Thread(new ThreadStart(ReleaseMemory));
  588. _ramThread.IsBackground = true;
  589. _ramThread.Start();
  590. }
  591. private void ReleaseMemory()
  592. {
  593. while (true)
  594. {
  595. Utils.ReleaseMemory(false);
  596. Thread.Sleep(30 * 1000);
  597. }
  598. }
  599. #endregion
  600. #region Traffic Statistics
  601. private void StartTrafficStatistics(int queueMaxSize)
  602. {
  603. trafficPerSecondQueue = new Queue<TrafficPerSecond>();
  604. for (int i = 0; i < queueMaxSize; i++)
  605. {
  606. trafficPerSecondQueue.Enqueue(new TrafficPerSecond());
  607. }
  608. _trafficThread = new Thread(new ThreadStart(() => TrafficStatistics(queueMaxSize)));
  609. _trafficThread.IsBackground = true;
  610. _trafficThread.Start();
  611. }
  612. private void TrafficStatistics(int queueMaxSize)
  613. {
  614. TrafficPerSecond previous, current;
  615. while (true)
  616. {
  617. previous = trafficPerSecondQueue.Last();
  618. current = new TrafficPerSecond();
  619. current.inboundCounter = InboundCounter;
  620. current.outboundCounter = OutboundCounter;
  621. current.inboundIncreasement = current.inboundCounter - previous.inboundCounter;
  622. current.outboundIncreasement = current.outboundCounter - previous.outboundCounter;
  623. trafficPerSecondQueue.Enqueue(current);
  624. if (trafficPerSecondQueue.Count > queueMaxSize)
  625. trafficPerSecondQueue.Dequeue();
  626. TrafficChanged?.Invoke(this, new EventArgs());
  627. Thread.Sleep(1000);
  628. }
  629. }
  630. #endregion
  631. }
  632. }