public void Disconnect()
        {
            allTrackers.Remove(this);

            OnTrackerDelete?.Invoke(this, new EventArgs());

            if (Status == TrackerStatus.Connected)
            {
                var message = new PeerDisconnectMessage(CommonHelpers.GetLocalEndPoint(CommonHelpers.PeerPort, true));
                try
                {
                    Connection.SendObject(message.GetType().Name, message);
                }
                catch { }
            }

            Task.Run(() =>
            {
                try
                {
                    Connection?.Dispose();
                    Connection = null;
                }
                catch { }
            });

            Status = TrackerStatus.Disconnected;

            CommonHelpers.LogTrackers(allTrackers);
        }
        public void Connect()
        {
            if (Status == TrackerStatus.Disconnected)
            {
                try
                {
                    ConnectionInfo connInfo   = new ConnectionInfo(Address);
                    Connection     newTCPConn = TCPConnection.GetConnection(connInfo);

                    Status     = TrackerStatus.Connected;
                    Connection = newTCPConn;

                    if (!Connection.IncomingPacketHandlerExists(typeof(ToPeerMessage).Name))
                    {
                        Connection.AppendIncomingPacketHandler <ToPeerMessage>(typeof(ToPeerMessage).Name, OnToPeerMessage);
                    }

                    if (!Connection.IncomingPacketHandlerExists(typeof(PeerHashMessage).Name))
                    {
                        Connection.AppendIncomingPacketHandler <PeerHashMessage>(typeof(PeerHashMessage).Name, OnPeerHashMessageFromTracker);
                    }

                    if (!Connection.IncomingPacketHandlerExists(typeof(PeersMessage).Name))
                    {
                        Connection.AppendIncomingPacketHandler <PeersMessage>(typeof(PeersMessage).Name,
                                                                              (p, c, m) =>
                        {
                            OnPeersMessageFromTracker?.Invoke(this, new MessageEventArgs(m, null, Address));
                        });
                    }

                    if (!Connection.IncomingPacketHandlerExists(typeof(ConnectToPeerWithTrackerMessage).Name))
                    {
                        Connection.AppendIncomingPacketHandler <ConnectToPeerWithTrackerMessage>(typeof(ConnectToPeerWithTrackerMessage).Name,
                                                                                                 (p, c, m) =>
                        {
                            OnConnectToPeerWithTrackerMessage?.Invoke(this, new MessageEventArgs(m, null, Address));
                        });
                    }

                    if (!Connection.IncomingPacketHandlerExists(typeof(PeerDisconnectMessage).Name))
                    {
                        Connection.AppendIncomingPacketHandler <PeerDisconnectMessage>(typeof(PeerDisconnectMessage).Name,
                                                                                       (p, c, m) =>
                        {
                            OnDisconnectPeer?.Invoke(this, new MessageEventArgs(m, null, Address));
                        });
                    }

                    Thread.Sleep(CommonHelpers.MessagesInterval);
                }
                catch
                {
                    ErrorsCount++;
                    Status = TrackerStatus.Disconnected;

                    if (ErrorsCount >= 3)
                    {
                        allTrackers.Remove(this);

                        OnTrackerDelete?.Invoke(this, new EventArgs());
                    }
                }


                CommonHelpers.LogTrackers(allTrackers);
            }
        }