public void EnableAutoSearch(bool allowListener = true, bool allowClient = true)
        {
            if (announceResponseEnabled)
            {
                throw new InvalidOperationException("Already started.");
            }
            announceResponseEnabled = true;

            var announceMessage = new DiscoveryAnnounceMessage()
            {
                PeerId      = app.InstanceHash.Hash,
                Version     = app.Version,
                ServicePort = app.NetworkSettings.TcpServicePort
            };

            if (allowListener)
            {
                // enable announcer
                udpAnnouncer = new UdpPeerDiscoveryListener(app.LoggerFactory, app.CompatibilityChecker, peerRegistry, app.NetworkSettings, announceMessage);
                udpAnnouncer.Start();
            }

            if (allowClient)
            {
                // timer discovery
                udpDiscovery      = new UdpPeerDiscoveryClient(app.LoggerFactory, app.CompatibilityChecker, app.NetworkSettings, announceMessage, peerRegistry);
                udpDiscoveryTimer = new Timer(DiscoveryTimerCallback, null, TimeSpan.Zero, Timeout.InfiniteTimeSpan);
            }
        }
        public void Dispose()
        {
            if (udpAnnouncer != null)
            {
                udpAnnouncer.Dispose();
                udpAnnouncer = null;
            }

            if (udpDiscoveryTimer != null)
            {
                udpDiscoveryTimer.Dispose();
                udpDiscoveryTimer = null;
            }
        }