/// <summary> /// Serves the file over BitTorrent. /// </summary> /// <param name="dhtKey">The DHT name to be used to put the torrent info</param> /// <param name="nameSpace">The name space.</param> /// <param name="path">The file or directory path.</param> /// <param name="unique">if set to <c>true</c>, the manager uses Create /// instead of Put to insert torrent to Dht.</param> void PublishDataInternal(string nameSpace, string name, bool unique) { byte[] dhtKey = ServiceUtil.GetDictKeyBytes(nameSpace, name); var dataPath = _bittorrentCache.GetPathOfItemInDownloads(nameSpace, name); var torrentSavePath = _bittorrentCache.GetTorrentFilePath(nameSpace, name); // Create torrent BEncodedDictionary bdict = _torrentHelper.CreateTorrent(dataPath); Torrent torrent = Torrent.Load(bdict); // Dump torrent to the torrent folder so that tracker could load it. byte[] torrentBytes = bdict.Encode(); TorrentHelper.WriteTorrent(torrentBytes, torrentSavePath); string torrentUrl = _torrentHelper.GetTorrentFileUrlToPublish(nameSpace, name); // Put the Url bytes to the dictionary. var torrentUrlBytes = Encoding.UTF8.GetBytes(torrentUrl); if (unique) { _dictProxy.CreateTorrent(dhtKey, torrentUrlBytes, TorrentTtl); CacheRegistry.AddPathToRegistry(dataPath, true); } else { _dictProxy.PutTorrent(dhtKey, torrentUrlBytes, TorrentTtl); CacheRegistry.UpdatePathInRegistry(dataPath, true); } Logger.WriteLineIf(LogLevel.Verbose, _log_props, string.Format("{0}: Succesfully registered torrent url to dictionary.", torrent.Name)); var saveDir = IOUtil.GetParent(dataPath, true).FullName; // Download without blocking. StartDownload(torrent, saveDir, null); }