Example #1
0
// this function should either be removed, or return
// reference counted handle to the torrent_info which
// forces the torrent to stay loaded while the client holds it
torrent_info const& torrent_handle::get_torrent_info() const
{
    static boost::shared_ptr<const torrent_info> holder[4];
    static int cursor = 0;
    static std::mutex holder_mutex;

    boost::shared_ptr<const torrent_info> r = torrent_file();

    std::lock_guard<std::mutex> l(holder_mutex);
    holder[cursor++] = r;
    cursor = cursor % (sizeof(holder) / sizeof(holder[0]));
    return *r;
}
Example #2
0
PartialArchive *PartialArchive::restoreArchive(QSettings &settings, QObject *parent)
{
    QStringList groupParts(settings.group().split('_'));
    if (groupParts.length() < 3) return 0;

    QString dir(settings.value("data_directory").toString());
    if (!QDir(dir).exists()) return 0;

    QString torrent_file(settings.value("torrent_file").toString());
    if (!QDir(dir).exists(torrent_file)) return 0;

    return new PartialArchive(groupParts[1], groupParts[2],
                              settings.value("download_size", "0").toString(),
                              torrent_file, dir, parent);
}
bool picotorrent::core::is_valid_torrent_file(const std::string &path)
{
    std::ifstream torrent_file(path, std::ios::binary);
    if (!torrent_file) { return false; }

    std::stringstream ss;
    ss << torrent_file.rdbuf();
    std::string buf = ss.str();

    lt::error_code ec;
    lt::bdecode_node node;
    lt::bdecode(&buf[0], &buf[0] + buf.size(), node, ec);

    return ec ? false : true;
}
Example #4
0
	sha1_hash torrent_handle::info_hash() const
	{
		INVARIANT_CHECK;
		const static sha1_hash empty;
		TORRENT_FORWARD_RETURN(torrent_file().info_hash(), empty);
	}