SsdpHandler.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. using MediaBrowser.Common;
  2. using MediaBrowser.Common.Configuration;
  3. using MediaBrowser.Common.Events;
  4. using MediaBrowser.Controller.Configuration;
  5. using MediaBrowser.Controller.Dlna;
  6. using MediaBrowser.Dlna.Server;
  7. using MediaBrowser.Model.Logging;
  8. using System;
  9. using System.Collections.Concurrent;
  10. using System.Collections.Generic;
  11. using System.Globalization;
  12. using System.Linq;
  13. using System.Net;
  14. using System.Net.Sockets;
  15. using System.Text;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. using Microsoft.Win32;
  19. namespace MediaBrowser.Dlna.Ssdp
  20. {
  21. public class SsdpHandler : IDisposable, ISsdpHandler
  22. {
  23. private Socket _multicastSocket;
  24. private readonly ILogger _logger;
  25. private readonly IServerConfigurationManager _config;
  26. const string SSDPAddr = "239.255.255.250";
  27. const int SSDPPort = 1900;
  28. private readonly string _serverSignature;
  29. private readonly IPAddress _ssdpIp = IPAddress.Parse(SSDPAddr);
  30. private readonly IPEndPoint _ssdpEndp = new IPEndPoint(IPAddress.Parse(SSDPAddr), SSDPPort);
  31. private Timer _notificationTimer;
  32. private bool _isDisposed;
  33. private readonly Dictionary<string, List<UpnpDevice>> _devices = new Dictionary<string, List<UpnpDevice>>();
  34. private readonly IApplicationHost _appHost;
  35. private readonly int _unicastPort = 1901;
  36. private UdpClient _unicastClient;
  37. public SsdpHandler(ILogger logger, IServerConfigurationManager config, IApplicationHost appHost)
  38. {
  39. _logger = logger;
  40. _config = config;
  41. _appHost = appHost;
  42. _config.NamedConfigurationUpdated += _config_ConfigurationUpdated;
  43. _serverSignature = GenerateServerSignature();
  44. }
  45. private string GenerateServerSignature()
  46. {
  47. var os = Environment.OSVersion;
  48. var pstring = os.Platform.ToString();
  49. switch (os.Platform)
  50. {
  51. case PlatformID.Win32NT:
  52. case PlatformID.Win32S:
  53. case PlatformID.Win32Windows:
  54. pstring = "WIN";
  55. break;
  56. }
  57. return String.Format(
  58. "{0}{1}/{2}.{3} UPnP/1.0 DLNADOC/1.5 Emby/{4}",
  59. pstring,
  60. IntPtr.Size * 8,
  61. os.Version.Major,
  62. os.Version.Minor,
  63. _appHost.ApplicationVersion
  64. );
  65. }
  66. void _config_ConfigurationUpdated(object sender, ConfigurationUpdateEventArgs e)
  67. {
  68. if (string.Equals(e.Key, "dlna", StringComparison.OrdinalIgnoreCase))
  69. {
  70. ReloadAliveNotifier();
  71. }
  72. }
  73. public event EventHandler<SsdpMessageEventArgs> MessageReceived;
  74. private async void OnMessageReceived(SsdpMessageEventArgs args, bool isMulticast)
  75. {
  76. if (IgnoreMessage(args, isMulticast))
  77. {
  78. return;
  79. }
  80. LogMessageReceived(args, isMulticast);
  81. var headers = args.Headers;
  82. string st;
  83. if (string.Equals(args.Method, "M-SEARCH", StringComparison.OrdinalIgnoreCase) && headers.TryGetValue("st", out st))
  84. {
  85. TimeSpan delay = GetSearchDelay(headers);
  86. if (_config.GetDlnaConfiguration().EnableDebugLog)
  87. {
  88. _logger.Debug("Delaying search response by {0} seconds", delay.TotalSeconds);
  89. }
  90. await Task.Delay(delay).ConfigureAwait(false);
  91. RespondToSearch(args.EndPoint, st);
  92. }
  93. EventHelper.FireEventIfNotNull(MessageReceived, this, args, _logger);
  94. }
  95. internal void LogMessageReceived(SsdpMessageEventArgs args, bool isMulticast)
  96. {
  97. var enableDebugLogging = _config.GetDlnaConfiguration().EnableDebugLog;
  98. if (enableDebugLogging)
  99. {
  100. var headerTexts = args.Headers.Select(i => string.Format("{0}={1}", i.Key, i.Value));
  101. var headerText = string.Join(",", headerTexts.ToArray());
  102. var protocol = isMulticast ? "Multicast" : "Unicast";
  103. var localEndPointString = args.LocalEndPoint == null ? "null" : args.LocalEndPoint.ToString();
  104. _logger.Debug("{0} message received from {1} on {3}. Protocol: {4} Headers: {2}", args.Method, args.EndPoint, headerText, localEndPointString, protocol);
  105. }
  106. }
  107. internal bool IgnoreMessage(SsdpMessageEventArgs args, bool isMulticast)
  108. {
  109. string usn;
  110. if (args.Headers.TryGetValue("USN", out usn))
  111. {
  112. // USN=uuid:b67df29b5c379445fde78c3774ab518d::urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1
  113. if (RegisteredDevices.Any(i => string.Equals(i.USN, usn, StringComparison.OrdinalIgnoreCase)))
  114. {
  115. //var headerTexts = args.Headers.Select(i => string.Format("{0}={1}", i.Key, i.Value));
  116. //var headerText = string.Join(",", headerTexts.ToArray());
  117. //var protocol = isMulticast ? "Multicast" : "Unicast";
  118. //var localEndPointString = args.LocalEndPoint == null ? "null" : args.LocalEndPoint.ToString();
  119. //_logger.Debug("IGNORING {0} message received from {1} on {3}. Protocol: {4} Headers: {2}", args.Method, args.EndPoint, headerText, localEndPointString, protocol);
  120. return true;
  121. }
  122. }
  123. string serverId;
  124. if (args.Headers.TryGetValue("X-EMBY-SERVERID", out serverId))
  125. {
  126. if (string.Equals(serverId, _appHost.SystemId, StringComparison.OrdinalIgnoreCase))
  127. {
  128. //var headerTexts = args.Headers.Select(i => string.Format("{0}={1}", i.Key, i.Value));
  129. //var headerText = string.Join(",", headerTexts.ToArray());
  130. //var protocol = isMulticast ? "Multicast" : "Unicast";
  131. //var localEndPointString = args.LocalEndPoint == null ? "null" : args.LocalEndPoint.ToString();
  132. //_logger.Debug("IGNORING {0} message received from {1} on {3}. Protocol: {4} Headers: {2}", args.Method, args.EndPoint, headerText, localEndPointString, protocol);
  133. return true;
  134. }
  135. }
  136. return false;
  137. }
  138. public IEnumerable<UpnpDevice> RegisteredDevices
  139. {
  140. get
  141. {
  142. lock (_devices)
  143. {
  144. var devices = _devices.ToList();
  145. return devices.SelectMany(i => i.Value).ToList();
  146. }
  147. }
  148. }
  149. public void Start()
  150. {
  151. DisposeSocket();
  152. StopAliveNotifier();
  153. RestartSocketListener();
  154. ReloadAliveNotifier();
  155. CreateUnicastClient();
  156. SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
  157. SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
  158. }
  159. void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
  160. {
  161. if (e.Mode == PowerModes.Resume)
  162. {
  163. Start();
  164. }
  165. }
  166. public void SendSearchMessage(EndPoint localIp)
  167. {
  168. var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  169. values["HOST"] = "239.255.255.250:1900";
  170. values["USER-AGENT"] = "UPnP/1.0 DLNADOC/1.50 Platinum/1.0.4.2";
  171. values["X-EMBY-SERVERID"] = _appHost.SystemId;
  172. values["MAN"] = "\"ssdp:discover\"";
  173. // Search target
  174. values["ST"] = "ssdp:all";
  175. // Seconds to delay response
  176. values["MX"] = "3";
  177. var header = "M-SEARCH * HTTP/1.1";
  178. var msg = new SsdpMessageBuilder().BuildMessage(header, values);
  179. // UDP is unreliable, so send 3 requests at a time (per Upnp spec, sec 1.1.2)
  180. SendDatagram(msg, _ssdpEndp, localIp, true);
  181. SendUnicastRequest(msg);
  182. }
  183. public async void SendDatagram(string msg,
  184. EndPoint endpoint,
  185. EndPoint localAddress,
  186. bool isBroadcast,
  187. int sendCount = 3)
  188. {
  189. var enableDebugLogging = _config.GetDlnaConfiguration().EnableDebugLog;
  190. for (var i = 0; i < sendCount; i++)
  191. {
  192. if (i > 0)
  193. {
  194. await Task.Delay(500).ConfigureAwait(false);
  195. }
  196. var dgram = new Datagram(endpoint, localAddress, _logger, msg, isBroadcast, enableDebugLogging);
  197. dgram.Send();
  198. }
  199. }
  200. /// <summary>
  201. /// According to the spec: http://www.upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.0-20080424.pdf
  202. /// Device responses should be delayed a random duration between 0 and this many seconds to balance
  203. /// load for the control point when it processes responses. In my testing kodi times out after mx
  204. /// so we will generate from mx - 1
  205. /// </summary>
  206. /// <param name="headers">The mx headers</param>
  207. /// <returns>A timepsan for the amount to delay before returning search result.</returns>
  208. private TimeSpan GetSearchDelay(Dictionary<string, string> headers)
  209. {
  210. string mx;
  211. headers.TryGetValue("mx", out mx);
  212. int delaySeconds = 0;
  213. if (!string.IsNullOrWhiteSpace(mx)
  214. && int.TryParse(mx, NumberStyles.Any, CultureInfo.InvariantCulture, out delaySeconds)
  215. && delaySeconds > 1)
  216. {
  217. delaySeconds = new Random().Next(delaySeconds - 1);
  218. }
  219. return TimeSpan.FromSeconds(delaySeconds);
  220. }
  221. private void RespondToSearch(EndPoint endpoint, string deviceType)
  222. {
  223. var enableDebugLogging = _config.GetDlnaConfiguration().EnableDebugLog;
  224. var isLogged = false;
  225. const string header = "HTTP/1.1 200 OK";
  226. foreach (var d in RegisteredDevices)
  227. {
  228. if (string.Equals(deviceType, "ssdp:all", StringComparison.OrdinalIgnoreCase) ||
  229. string.Equals(deviceType, d.Type, StringComparison.OrdinalIgnoreCase))
  230. {
  231. if (!isLogged)
  232. {
  233. if (enableDebugLogging)
  234. {
  235. _logger.Debug("Responding to search from {0} for {1}", endpoint, deviceType);
  236. }
  237. isLogged = true;
  238. }
  239. var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  240. values["CACHE-CONTROL"] = "max-age = 600";
  241. values["DATE"] = DateTime.Now.ToString("R");
  242. values["EXT"] = "";
  243. values["LOCATION"] = d.Descriptor.ToString();
  244. values["SERVER"] = _serverSignature;
  245. values["ST"] = d.Type;
  246. values["USN"] = d.USN;
  247. var msg = new SsdpMessageBuilder().BuildMessage(header, values);
  248. SendDatagram(msg, endpoint, null, false, 2);
  249. SendDatagram(msg, endpoint, new IPEndPoint(d.Address, 0), false, 2);
  250. //SendDatagram(header, values, endpoint, null, true);
  251. if (enableDebugLogging)
  252. {
  253. _logger.Debug("{1} - Responded to a {0} request to {2}", d.Type, endpoint, d.Address.ToString());
  254. }
  255. }
  256. }
  257. }
  258. private void RestartSocketListener()
  259. {
  260. if (_isDisposed)
  261. {
  262. return;
  263. }
  264. try
  265. {
  266. _multicastSocket = CreateMulticastSocket();
  267. _logger.Info("MultiCast socket created");
  268. Receive();
  269. }
  270. catch (Exception ex)
  271. {
  272. _logger.ErrorException("Error creating MultiCast socket", ex);
  273. //StartSocketRetryTimer();
  274. }
  275. }
  276. private void Receive()
  277. {
  278. try
  279. {
  280. var buffer = new byte[1024];
  281. EndPoint endpoint = new IPEndPoint(IPAddress.Any, SSDPPort);
  282. _multicastSocket.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref endpoint, ReceiveCallback, buffer);
  283. }
  284. catch (ObjectDisposedException)
  285. {
  286. if (!_isDisposed)
  287. {
  288. //StartSocketRetryTimer();
  289. }
  290. }
  291. catch (Exception ex)
  292. {
  293. _logger.Debug("Error in BeginReceiveFrom", ex);
  294. }
  295. }
  296. private void ReceiveCallback(IAsyncResult result)
  297. {
  298. if (_isDisposed)
  299. {
  300. return;
  301. }
  302. try
  303. {
  304. EndPoint endpoint = new IPEndPoint(IPAddress.Any, SSDPPort);
  305. var length = _multicastSocket.EndReceiveFrom(result, ref endpoint);
  306. var received = (byte[])result.AsyncState;
  307. var enableDebugLogging = _config.GetDlnaConfiguration().EnableDebugLog;
  308. if (enableDebugLogging)
  309. {
  310. _logger.Debug(Encoding.ASCII.GetString(received));
  311. }
  312. var args = SsdpHelper.ParseSsdpResponse(received);
  313. args.EndPoint = endpoint;
  314. OnMessageReceived(args, true);
  315. }
  316. catch (ObjectDisposedException)
  317. {
  318. if (!_isDisposed)
  319. {
  320. //StartSocketRetryTimer();
  321. }
  322. }
  323. catch (Exception ex)
  324. {
  325. _logger.ErrorException("Failed to read SSDP message", ex);
  326. }
  327. if (_multicastSocket != null)
  328. {
  329. Receive();
  330. }
  331. }
  332. public void Dispose()
  333. {
  334. _config.NamedConfigurationUpdated -= _config_ConfigurationUpdated;
  335. SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
  336. _isDisposed = true;
  337. DisposeUnicastClient();
  338. DisposeSocket();
  339. StopAliveNotifier();
  340. }
  341. private void DisposeSocket()
  342. {
  343. if (_multicastSocket != null)
  344. {
  345. _multicastSocket.Close();
  346. _multicastSocket.Dispose();
  347. _multicastSocket = null;
  348. }
  349. }
  350. private Socket CreateMulticastSocket()
  351. {
  352. var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  353. socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
  354. socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
  355. socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 4);
  356. socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(_ssdpIp, 0));
  357. socket.Bind(new IPEndPoint(IPAddress.Any, SSDPPort));
  358. return socket;
  359. }
  360. private void NotifyAll()
  361. {
  362. var enableDebugLogging = _config.GetDlnaConfiguration().EnableDebugLog;
  363. if (enableDebugLogging)
  364. {
  365. _logger.Debug("Sending alive notifications");
  366. }
  367. foreach (var d in RegisteredDevices)
  368. {
  369. NotifyDevice(d, "alive", enableDebugLogging);
  370. }
  371. }
  372. private void NotifyDevice(UpnpDevice dev, string type, bool logMessage)
  373. {
  374. const string header = "NOTIFY * HTTP/1.1";
  375. var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
  376. // If needed later for non-server devices, these headers will need to be dynamic
  377. values["HOST"] = "239.255.255.250:1900";
  378. values["CACHE-CONTROL"] = "max-age = 600";
  379. values["LOCATION"] = dev.Descriptor.ToString();
  380. values["SERVER"] = _serverSignature;
  381. values["NTS"] = "ssdp:" + type;
  382. values["NT"] = dev.Type;
  383. values["USN"] = dev.USN;
  384. if (logMessage)
  385. {
  386. _logger.Debug("{0} said {1}", dev.USN, type);
  387. }
  388. var msg = new SsdpMessageBuilder().BuildMessage(header, values);
  389. SendDatagram(msg, _ssdpEndp, new IPEndPoint(dev.Address, 0), true, 1);
  390. //SendUnicastRequest(msg, 1);
  391. }
  392. public void RegisterNotification(string uuid, Uri descriptionUri, IPAddress address, IEnumerable<string> services)
  393. {
  394. lock (_devices)
  395. {
  396. List<UpnpDevice> list;
  397. List<UpnpDevice> dl;
  398. if (_devices.TryGetValue(uuid, out dl))
  399. {
  400. list = dl;
  401. }
  402. else
  403. {
  404. list = new List<UpnpDevice>();
  405. _devices[uuid] = list;
  406. }
  407. list.AddRange(services.Select(i => new UpnpDevice(uuid, i, descriptionUri, address)));
  408. NotifyAll();
  409. _logger.Debug("Registered mount {0} at {1}", uuid, descriptionUri);
  410. }
  411. }
  412. public void UnregisterNotification(string uuid)
  413. {
  414. lock (_devices)
  415. {
  416. List<UpnpDevice> dl;
  417. if (_devices.TryGetValue(uuid, out dl))
  418. {
  419. _devices.Remove(uuid);
  420. foreach (var d in dl.ToList())
  421. {
  422. NotifyDevice(d, "byebye", true);
  423. }
  424. _logger.Debug("Unregistered mount {0}", uuid);
  425. }
  426. }
  427. }
  428. private void CreateUnicastClient()
  429. {
  430. if (_unicastClient == null)
  431. {
  432. try
  433. {
  434. _unicastClient = new UdpClient(_unicastPort);
  435. }
  436. catch (Exception ex)
  437. {
  438. _logger.ErrorException("Error creating unicast client", ex);
  439. }
  440. UnicastSetBeginReceive();
  441. }
  442. }
  443. private void DisposeUnicastClient()
  444. {
  445. if (_unicastClient != null)
  446. {
  447. try
  448. {
  449. _unicastClient.Close();
  450. }
  451. catch (Exception ex)
  452. {
  453. _logger.ErrorException("Error closing unicast client", ex);
  454. }
  455. _unicastClient = null;
  456. }
  457. }
  458. /// <summary>
  459. /// Listen for Unicast SSDP Responses
  460. /// </summary>
  461. private void UnicastSetBeginReceive()
  462. {
  463. try
  464. {
  465. var ipRxEnd = new IPEndPoint(IPAddress.Any, _unicastPort);
  466. var udpListener = new UdpState { EndPoint = ipRxEnd };
  467. udpListener.UdpClient = _unicastClient;
  468. _unicastClient.BeginReceive(UnicastReceiveCallback, udpListener);
  469. }
  470. catch (Exception ex)
  471. {
  472. _logger.ErrorException("Error in UnicastSetBeginReceive", ex);
  473. }
  474. }
  475. /// <summary>
  476. /// The UnicastReceiveCallback receives Http Responses
  477. /// and Fired the SatIpDeviceFound Event for adding the SatIpDevice
  478. /// </summary>
  479. /// <param name="ar"></param>
  480. private void UnicastReceiveCallback(IAsyncResult ar)
  481. {
  482. var udpClient = ((UdpState)(ar.AsyncState)).UdpClient;
  483. var endpoint = ((UdpState)(ar.AsyncState)).EndPoint;
  484. if (udpClient.Client != null)
  485. {
  486. try
  487. {
  488. var responseBytes = udpClient.EndReceive(ar, ref endpoint);
  489. var args = SsdpHelper.ParseSsdpResponse(responseBytes);
  490. args.EndPoint = endpoint;
  491. OnMessageReceived(args, false);
  492. UnicastSetBeginReceive();
  493. }
  494. catch (ObjectDisposedException)
  495. {
  496. }
  497. catch (SocketException)
  498. {
  499. }
  500. catch (Exception)
  501. {
  502. // If called while shutting down, seeing a NullReferenceException inside EndReceive
  503. }
  504. }
  505. }
  506. private void SendUnicastRequest(string request, int sendCount = 3)
  507. {
  508. if (_unicastClient == null)
  509. {
  510. return;
  511. }
  512. var ipSsdp = IPAddress.Parse(SSDPAddr);
  513. var ipTxEnd = new IPEndPoint(ipSsdp, SSDPPort);
  514. SendUnicastRequest(request, ipTxEnd, sendCount);
  515. }
  516. private async void SendUnicastRequest(string request, IPEndPoint toEndPoint, int sendCount = 3)
  517. {
  518. if (_unicastClient == null)
  519. {
  520. return;
  521. }
  522. //_logger.Debug("Sending unicast request");
  523. byte[] req = Encoding.ASCII.GetBytes(request);
  524. try
  525. {
  526. for (var i = 0; i < sendCount; i++)
  527. {
  528. if (i > 0)
  529. {
  530. await Task.Delay(50).ConfigureAwait(false);
  531. }
  532. _unicastClient.Send(req, req.Length, toEndPoint);
  533. }
  534. }
  535. catch (Exception ex)
  536. {
  537. _logger.ErrorException("Error in SendUnicastRequest", ex);
  538. }
  539. }
  540. private readonly object _notificationTimerSyncLock = new object();
  541. private int _aliveNotifierIntervalMs;
  542. private void ReloadAliveNotifier()
  543. {
  544. var config = _config.GetDlnaConfiguration();
  545. if (!config.BlastAliveMessages)
  546. {
  547. StopAliveNotifier();
  548. return;
  549. }
  550. var intervalMs = config.BlastAliveMessageIntervalSeconds * 1000;
  551. if (_notificationTimer == null || _aliveNotifierIntervalMs != intervalMs)
  552. {
  553. lock (_notificationTimerSyncLock)
  554. {
  555. if (_notificationTimer == null)
  556. {
  557. _logger.Debug("Starting alive notifier");
  558. const int initialDelayMs = 3000;
  559. _notificationTimer = new Timer(state => NotifyAll(), null, initialDelayMs, intervalMs);
  560. }
  561. else
  562. {
  563. _logger.Debug("Updating alive notifier");
  564. _notificationTimer.Change(intervalMs, intervalMs);
  565. }
  566. _aliveNotifierIntervalMs = intervalMs;
  567. }
  568. }
  569. }
  570. private void StopAliveNotifier()
  571. {
  572. lock (_notificationTimerSyncLock)
  573. {
  574. if (_notificationTimer != null)
  575. {
  576. _logger.Debug("Stopping alive notifier");
  577. _notificationTimer.Dispose();
  578. _notificationTimer = null;
  579. }
  580. }
  581. }
  582. public class UdpState
  583. {
  584. public UdpClient UdpClient;
  585. public IPEndPoint EndPoint;
  586. }
  587. }
  588. }