/// <summary> /// Converts the torrent to a <see cref="BDictionary"/>. /// </summary> /// <returns></returns> public virtual BDictionary ToBDictionary() { var torrent = new BDictionary(); var trackerCount = Trackers.Flatten().Count(); if (trackerCount > 0) { torrent[TorrentFields.Announce] = new BList(Trackers.First().Select(x => new BString(x, Encoding))); } if (trackerCount > 1) { torrent[TorrentFields.AnnounceList] = new BList(Trackers.Select(x => new BList(x, Encoding))); } if (Encoding != null) { torrent[TorrentFields.Encoding] = new BString(Encoding.WebName.ToUpper(), Encoding); } if (Comment != null) { torrent[TorrentFields.Comment] = new BString(Comment, Encoding); } if (CreatedBy != null) { torrent[TorrentFields.CreatedBy] = new BString(CreatedBy, Encoding); } if (CreationDate != null) { torrent[TorrentFields.CreationDate] = (BNumber)CreationDate; } var info = CreateInfoDictionary(Encoding); if (info.Any()) { torrent[TorrentFields.Info] = info; } if (ExtraFields != null) { torrent.MergeWith(ExtraFields, ExistingKeyAction.Merge); } return(torrent); }
public void Disconnect() { while (Peers.Count > 0) { Peers.First().DisconnectAny(); } while (Trackers.Count > 0) { Trackers.First().Disconnect(); } t.Stop(); PeerDiscovery.DisableDiscoverable(); Connection.StopListening(); NetworkComms.CloseAllConnections(); NetworkComms.Shutdown(); NetworkComms.Logger.Warn("===== Client stopped ====="); Started = false; }