2008-05-14 07:29:42 +02:00
|
|
|
/*
|
|
|
|
|
2016-01-18 00:57:46 +01:00
|
|
|
Copyright (c) 2008-2016, Arvid Norberg
|
2008-05-14 07:29:42 +02:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in
|
|
|
|
the documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the author nor the names of its
|
|
|
|
contributors may be used to endorse or promote products derived
|
|
|
|
from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libtorrent/create_torrent.hpp"
|
2016-04-22 19:51:06 +02:00
|
|
|
#include "libtorrent/utf8.hpp"
|
2015-03-15 00:10:20 +01:00
|
|
|
#include "libtorrent/aux_/escape_string.hpp" // for convert_to_wstring
|
2014-07-06 21:18:00 +02:00
|
|
|
#include "libtorrent/disk_io_thread.hpp"
|
2015-04-24 08:06:41 +02:00
|
|
|
#include "libtorrent/aux_/merkle.hpp" // for merkle_*()
|
|
|
|
#include "libtorrent/torrent_info.hpp"
|
2015-09-18 06:23:45 +02:00
|
|
|
#include "libtorrent/announce_entry.hpp"
|
2014-08-01 08:07:48 +02:00
|
|
|
#include "libtorrent/performance_counters.hpp" // for counters
|
2015-04-03 22:15:48 +02:00
|
|
|
#include "libtorrent/alert_manager.hpp"
|
2016-09-22 04:59:43 +02:00
|
|
|
#include "libtorrent/file.hpp" // for combine_path etc.
|
2008-05-14 07:29:42 +02:00
|
|
|
|
2009-01-11 23:27:43 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2016-05-25 06:31:52 +02:00
|
|
|
#include <functional>
|
2016-09-01 03:42:18 +02:00
|
|
|
#include <memory>
|
2016-05-25 06:31:52 +02:00
|
|
|
|
|
|
|
using namespace std::placeholders;
|
|
|
|
|
2008-05-14 07:29:42 +02:00
|
|
|
namespace libtorrent
|
|
|
|
{
|
2015-04-20 06:52:49 +02:00
|
|
|
namespace
|
2009-01-11 23:27:43 +01:00
|
|
|
{
|
2015-01-01 21:25:39 +01:00
|
|
|
inline bool default_pred(std::string const&) { return true; }
|
|
|
|
|
|
|
|
inline bool ignore_subdir(std::string const& leaf)
|
|
|
|
{ return leaf == ".." || leaf == "."; }
|
|
|
|
|
2016-12-05 16:40:05 +01:00
|
|
|
int get_file_attributes(std::string const& p)
|
2009-01-11 23:27:43 +01:00
|
|
|
{
|
|
|
|
#ifdef TORRENT_WINDOWS
|
2015-03-09 23:39:30 +01:00
|
|
|
WIN32_FILE_ATTRIBUTE_DATA attr;
|
2010-02-15 06:49:10 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
2016-12-05 16:40:05 +01:00
|
|
|
std::wstring path = convert_to_wstring(p);
|
2015-03-09 23:39:30 +01:00
|
|
|
GetFileAttributesExW(path.c_str(), GetFileExInfoStandard, &attr);
|
2009-01-11 23:27:43 +01:00
|
|
|
#else
|
2016-12-05 16:40:05 +01:00
|
|
|
std::string path = convert_to_native(p);
|
2015-03-09 23:39:30 +01:00
|
|
|
GetFileAttributesExA(path.c_str(), GetFileExInfoStandard, &attr);
|
2010-02-15 06:49:10 +01:00
|
|
|
#endif // TORRENT_USE_WSTRING
|
2015-03-09 23:39:30 +01:00
|
|
|
if (attr.dwFileAttributes == INVALID_FILE_ATTRIBUTES) return 0;
|
|
|
|
if (attr.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) return file_storage::attribute_hidden;
|
2009-01-11 23:27:43 +01:00
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
struct stat s;
|
2016-12-05 16:40:05 +01:00
|
|
|
if (lstat(convert_to_native(p).c_str(), &s) < 0) return 0;
|
2009-07-01 10:35:45 +02:00
|
|
|
int file_attr = 0;
|
2016-04-28 23:14:41 +02:00
|
|
|
if (s.st_mode & S_IXUSR)
|
2009-07-01 10:35:45 +02:00
|
|
|
file_attr += file_storage::attribute_executable;
|
|
|
|
if (S_ISLNK(s.st_mode))
|
|
|
|
file_attr += file_storage::attribute_symlink;
|
|
|
|
return file_attr;
|
2009-06-23 04:50:41 +02:00
|
|
|
#endif
|
|
|
|
}
|
2016-04-28 23:14:41 +02:00
|
|
|
|
2009-07-20 04:07:32 +02:00
|
|
|
#ifndef TORRENT_WINDOWS
|
2009-10-26 02:29:39 +01:00
|
|
|
std::string get_symlink_path_impl(char const* path)
|
2009-07-01 10:35:45 +02:00
|
|
|
{
|
2016-06-04 16:03:13 +02:00
|
|
|
constexpr int MAX_SYMLINK_PATH = 200;
|
|
|
|
|
2009-07-01 10:35:45 +02:00
|
|
|
char buf[MAX_SYMLINK_PATH];
|
2009-10-26 02:29:39 +01:00
|
|
|
std::string f = convert_to_native(path);
|
2016-12-09 14:23:54 +01:00
|
|
|
int char_read = int(readlink(f.c_str(), buf, MAX_SYMLINK_PATH));
|
2009-07-01 10:35:45 +02:00
|
|
|
if (char_read < 0) return "";
|
|
|
|
if (char_read < MAX_SYMLINK_PATH) buf[char_read] = 0;
|
|
|
|
else buf[0] = 0;
|
2009-10-26 02:29:39 +01:00
|
|
|
return convert_from_native(buf);
|
2009-07-01 10:35:45 +02:00
|
|
|
}
|
2009-07-20 04:07:32 +02:00
|
|
|
#endif
|
2009-07-01 10:35:45 +02:00
|
|
|
|
2012-03-23 09:22:52 +01:00
|
|
|
std::string get_symlink_path(std::string const& p)
|
2009-07-01 10:35:45 +02:00
|
|
|
{
|
2009-10-26 02:29:39 +01:00
|
|
|
#if defined TORRENT_WINDOWS
|
2015-11-20 05:37:45 +01:00
|
|
|
TORRENT_UNUSED(p);
|
2009-07-20 04:07:32 +02:00
|
|
|
return "";
|
2009-07-01 10:35:45 +02:00
|
|
|
#else
|
2009-10-26 02:29:39 +01:00
|
|
|
return get_symlink_path_impl(p.c_str());
|
2009-07-01 10:35:45 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-19 00:31:04 +01:00
|
|
|
void add_files_impl(file_storage& fs, std::string const& p
|
2016-11-15 18:03:11 +01:00
|
|
|
, std::string const& l, std::function<bool(std::string)> pred
|
|
|
|
, std::uint32_t const flags)
|
2012-03-19 00:31:04 +01:00
|
|
|
{
|
|
|
|
std::string f = combine_path(p, l);
|
|
|
|
if (!pred(f)) return;
|
|
|
|
error_code ec;
|
|
|
|
file_status s;
|
|
|
|
stat_file(f, &s, ec, (flags & create_torrent::symlinks) ? dont_follow_links : 0);
|
|
|
|
if (ec) return;
|
|
|
|
|
|
|
|
// recurse into directories
|
|
|
|
bool recurse = (s.mode & file_status::directory) != 0;
|
|
|
|
|
|
|
|
// if the file is not a link or we're following links, and it's a directory
|
|
|
|
// only then should we recurse
|
|
|
|
#ifndef TORRENT_WINDOWS
|
|
|
|
if ((s.mode & file_status::link) && (flags & create_torrent::symlinks))
|
|
|
|
recurse = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (recurse)
|
|
|
|
{
|
|
|
|
for (directory i(f, ec); !i.done(); i.next(ec))
|
|
|
|
{
|
|
|
|
std::string leaf = i.file();
|
|
|
|
if (ignore_subdir(leaf)) continue;
|
|
|
|
add_files_impl(fs, p, combine_path(l, leaf), pred, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// #error use the fields from s
|
|
|
|
int file_flags = get_file_attributes(f);
|
|
|
|
|
|
|
|
// mask all bits to check if the file is a symlink
|
|
|
|
if ((file_flags & file_storage::attribute_symlink)
|
2016-04-28 23:14:41 +02:00
|
|
|
&& (flags & create_torrent::symlinks))
|
2012-03-19 00:31:04 +01:00
|
|
|
{
|
|
|
|
std::string sym_path = get_symlink_path(f);
|
|
|
|
fs.add_file(l, 0, file_flags, s.mtime, sym_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fs.add_file(l, s.file_size, file_flags, s.mtime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-20 06:52:49 +02:00
|
|
|
|
2016-11-21 05:58:48 +01:00
|
|
|
struct hash_state
|
2015-04-20 06:52:49 +02:00
|
|
|
{
|
2016-11-21 05:58:48 +01:00
|
|
|
create_torrent& ct;
|
|
|
|
std::shared_ptr<storage_interface> storage;
|
|
|
|
disk_io_thread& iothread;
|
|
|
|
int piece_counter;
|
|
|
|
int completed_piece;
|
|
|
|
std::function<void(int)> const& f;
|
|
|
|
error_code& ec;
|
|
|
|
};
|
|
|
|
|
2016-11-26 07:51:47 +01:00
|
|
|
void on_hash(int const piece, sha1_hash const& piece_hash
|
2016-11-21 05:58:48 +01:00
|
|
|
, storage_error const& error, hash_state* st)
|
|
|
|
{
|
2016-11-26 07:51:47 +01:00
|
|
|
if (error)
|
2015-04-20 06:52:49 +02:00
|
|
|
{
|
|
|
|
// on error
|
2016-11-21 05:58:48 +01:00
|
|
|
st->ec = error.ec;
|
|
|
|
st->iothread.abort(true);
|
2015-04-20 06:52:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-11-21 05:58:48 +01:00
|
|
|
st->ct.set_hash(piece, sha1_hash(piece_hash));
|
|
|
|
st->f(st->completed_piece);
|
|
|
|
++st->completed_piece;
|
|
|
|
if (st->piece_counter < st->ct.num_pieces())
|
2015-04-20 06:52:49 +02:00
|
|
|
{
|
2016-11-21 05:58:48 +01:00
|
|
|
st->iothread.async_hash(st->storage.get(), st->piece_counter
|
2016-11-26 07:51:47 +01:00
|
|
|
, disk_interface::sequential_access
|
|
|
|
, std::bind(&on_hash, _1, _2, _3, st), nullptr);
|
2016-11-21 05:58:48 +01:00
|
|
|
++st->piece_counter;
|
2015-04-20 06:52:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-21 05:58:48 +01:00
|
|
|
st->iothread.abort(true);
|
2015-04-20 06:52:49 +02:00
|
|
|
}
|
2016-11-21 05:58:48 +01:00
|
|
|
st->iothread.submit_jobs();
|
2015-04-20 06:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
2012-03-19 00:31:04 +01:00
|
|
|
|
2015-01-01 21:25:39 +01:00
|
|
|
#if TORRENT_USE_WSTRING
|
|
|
|
#ifndef TORRENT_NO_DEPRECATE
|
|
|
|
|
|
|
|
void add_files(file_storage& fs, std::wstring const& wfile
|
2016-08-13 03:31:55 +02:00
|
|
|
, std::function<bool(std::string)> p, std::uint32_t flags)
|
2015-01-01 21:25:39 +01:00
|
|
|
{
|
2016-09-25 04:16:10 +02:00
|
|
|
std::string utf8 = wchar_utf8(wfile);
|
2015-04-20 06:52:49 +02:00
|
|
|
add_files_impl(fs, parent_path(complete(utf8))
|
2015-01-01 21:25:39 +01:00
|
|
|
, filename(utf8), p, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void add_files(file_storage& fs
|
2016-06-18 20:01:38 +02:00
|
|
|
, std::wstring const& wfile, std::uint32_t flags)
|
2015-01-01 21:25:39 +01:00
|
|
|
{
|
2016-09-25 04:16:10 +02:00
|
|
|
std::string utf8 = wchar_utf8(wfile);
|
2015-04-20 06:52:49 +02:00
|
|
|
add_files_impl(fs, parent_path(complete(utf8))
|
|
|
|
, filename(utf8), default_pred, flags);
|
2015-01-01 21:25:39 +01:00
|
|
|
}
|
2015-06-14 22:00:04 +02:00
|
|
|
|
2015-01-01 21:25:39 +01:00
|
|
|
void set_piece_hashes(create_torrent& t, std::wstring const& p
|
2016-08-13 03:31:55 +02:00
|
|
|
, std::function<void(int)> f, error_code& ec)
|
2015-01-01 21:25:39 +01:00
|
|
|
{
|
2016-09-25 04:16:10 +02:00
|
|
|
std::string utf8 = wchar_utf8(p);
|
2015-01-01 21:25:39 +01:00
|
|
|
set_piece_hashes(t, utf8, f, ec);
|
|
|
|
}
|
2015-04-26 02:51:44 +02:00
|
|
|
|
|
|
|
void set_piece_hashes_deprecated(create_torrent& t, std::wstring const& p
|
2016-08-13 03:31:55 +02:00
|
|
|
, std::function<void(int)> f, error_code& ec)
|
2015-04-26 02:51:44 +02:00
|
|
|
{
|
2016-09-25 04:16:10 +02:00
|
|
|
std::string utf8 = wchar_utf8(p);
|
2015-04-26 02:51:44 +02:00
|
|
|
set_piece_hashes(t, utf8, f, ec);
|
|
|
|
}
|
2015-01-01 21:25:39 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void add_files(file_storage& fs, std::string const& file
|
2016-08-13 03:31:55 +02:00
|
|
|
, std::function<bool(std::string)> p, std::uint32_t flags)
|
2015-01-01 21:25:39 +01:00
|
|
|
{
|
2015-04-20 06:52:49 +02:00
|
|
|
add_files_impl(fs, parent_path(complete(file)), filename(file), p, flags);
|
2015-01-01 21:25:39 +01:00
|
|
|
}
|
|
|
|
|
2016-06-18 20:01:38 +02:00
|
|
|
void add_files(file_storage& fs, std::string const& file, std::uint32_t flags)
|
2015-01-01 21:25:39 +01:00
|
|
|
{
|
2015-04-20 06:52:49 +02:00
|
|
|
add_files_impl(fs, parent_path(complete(file)), filename(file)
|
|
|
|
, default_pred, flags);
|
2012-03-20 04:53:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_piece_hashes(create_torrent& t, std::string const& p
|
2016-08-13 03:31:55 +02:00
|
|
|
, std::function<void(int)> const& f, error_code& ec)
|
2012-03-19 00:31:04 +01:00
|
|
|
{
|
2014-07-06 21:18:00 +02:00
|
|
|
// optimized path
|
|
|
|
io_service ios;
|
|
|
|
|
2012-04-28 23:13:55 +02:00
|
|
|
#if TORRENT_USE_UNC_PATHS
|
2013-05-12 00:57:08 +02:00
|
|
|
std::string path = canonicalize_path(p);
|
|
|
|
#else
|
|
|
|
std::string const& path = p;
|
2012-04-28 23:13:55 +02:00
|
|
|
#endif
|
2013-05-12 00:57:08 +02:00
|
|
|
|
2013-11-07 06:17:09 +01:00
|
|
|
if (t.files().num_files() == 0)
|
|
|
|
{
|
2016-10-02 21:27:50 +02:00
|
|
|
ec = errors::no_files_in_torrent;
|
2013-11-07 06:17:09 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-22 19:51:06 +02:00
|
|
|
if (t.files().total_size() == 0)
|
|
|
|
{
|
2016-10-02 21:27:50 +02:00
|
|
|
ec = errors::torrent_invalid_length;
|
2016-04-22 19:51:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-01 08:07:48 +02:00
|
|
|
counters cnt;
|
2016-10-30 23:21:07 +01:00
|
|
|
disk_io_thread disk_thread(ios, cnt);
|
2012-03-19 00:31:04 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
storage_params params;
|
|
|
|
params.files = &t.files();
|
2016-06-20 17:32:06 +02:00
|
|
|
params.mapped_files = nullptr;
|
2014-07-06 21:18:00 +02:00
|
|
|
params.path = path;
|
|
|
|
params.pool = &disk_thread.files();
|
|
|
|
params.mode = storage_mode_sparse;
|
2012-03-19 00:31:04 +01:00
|
|
|
|
2014-07-06 21:18:00 +02:00
|
|
|
|
2016-11-13 03:45:30 +01:00
|
|
|
std::shared_ptr<storage_interface> storage(default_storage_constructor(params));
|
|
|
|
storage->set_files(&t.files());
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
settings_pack sett;
|
|
|
|
sett.set_int(settings_pack::cache_size, 0);
|
2016-11-06 19:39:09 +01:00
|
|
|
sett.set_int(settings_pack::aio_threads, 1);
|
2012-03-19 00:31:04 +01:00
|
|
|
|
2015-04-03 22:15:48 +02:00
|
|
|
// TODO: this should probably be optional
|
|
|
|
alert_manager dummy2(0, 0);
|
|
|
|
disk_thread.set_settings(&sett, dummy2);
|
2014-07-06 21:18:00 +02:00
|
|
|
|
|
|
|
int piece_read_ahead = 15 * 1024 * 1024 / t.piece_length();
|
|
|
|
if (piece_read_ahead < 1) piece_read_ahead = 1;
|
|
|
|
|
2016-11-21 05:58:48 +01:00
|
|
|
hash_state st = { t, storage, disk_thread, 0, 0, f, ec };
|
2014-07-06 21:18:00 +02:00
|
|
|
for (int i = 0; i < piece_read_ahead; ++i)
|
|
|
|
{
|
2016-11-26 07:51:47 +01:00
|
|
|
disk_thread.async_hash(storage.get(), i, disk_interface::sequential_access
|
|
|
|
, std::bind(&on_hash, _1, _2, _3, &st), nullptr);
|
2016-11-21 05:58:48 +01:00
|
|
|
++st.piece_counter;
|
|
|
|
if (st.piece_counter >= t.num_pieces()) break;
|
2012-03-19 00:31:04 +01:00
|
|
|
}
|
2014-07-06 21:18:00 +02:00
|
|
|
disk_thread.submit_jobs();
|
|
|
|
ios.run(ec);
|
2009-01-11 23:27:43 +01:00
|
|
|
}
|
|
|
|
|
2016-07-10 13:34:45 +02:00
|
|
|
create_torrent::~create_torrent() = default;
|
2012-03-19 07:06:52 +01:00
|
|
|
|
2014-06-18 08:22:01 +02:00
|
|
|
create_torrent::create_torrent(file_storage& fs, int piece_size
|
|
|
|
, int pad_file_limit, int flags, int alignment)
|
2008-05-28 10:44:40 +02:00
|
|
|
: m_files(fs)
|
2016-07-09 22:26:26 +02:00
|
|
|
, m_creation_date(time(nullptr))
|
2008-05-28 10:44:40 +02:00
|
|
|
, m_multifile(fs.num_files() > 1)
|
2008-05-14 07:29:42 +02:00
|
|
|
, m_private(false)
|
2010-10-16 17:24:45 +02:00
|
|
|
, m_merkle_torrent((flags & merkle) != 0)
|
|
|
|
, m_include_mtime((flags & modification_time) != 0)
|
|
|
|
, m_include_symlinks((flags & symlinks) != 0)
|
2008-05-28 10:44:40 +02:00
|
|
|
{
|
2010-01-19 02:58:03 +01:00
|
|
|
// return instead of crash in release mode
|
2016-04-26 06:37:47 +02:00
|
|
|
if (fs.num_files() == 0 || fs.total_size() == 0) return;
|
2010-01-19 02:58:03 +01:00
|
|
|
|
2013-08-12 09:30:57 +02:00
|
|
|
if (!m_multifile && has_parent_path(m_files.file_path(0))) m_multifile = true;
|
2008-05-14 07:29:42 +02:00
|
|
|
|
2009-01-11 11:32:57 +01:00
|
|
|
// a piece_size of 0 means automatic
|
2009-03-13 07:09:39 +01:00
|
|
|
if (piece_size == 0 && !m_merkle_torrent)
|
2009-01-11 11:32:57 +01:00
|
|
|
{
|
|
|
|
const int target_size = 40 * 1024;
|
2011-02-21 06:24:41 +01:00
|
|
|
piece_size = int(fs.total_size() / (target_size / 20));
|
2015-08-07 06:30:29 +02:00
|
|
|
|
2009-01-11 23:27:43 +01:00
|
|
|
int i = 16*1024;
|
|
|
|
for (; i < 2*1024*1024; i *= 2)
|
2009-01-11 11:32:57 +01:00
|
|
|
{
|
2009-01-11 23:27:43 +01:00
|
|
|
if (piece_size > i) continue;
|
2009-01-11 11:32:57 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-01-11 23:27:43 +01:00
|
|
|
piece_size = i;
|
2009-01-11 11:32:57 +01:00
|
|
|
}
|
2009-03-13 07:09:39 +01:00
|
|
|
else if (piece_size == 0 && m_merkle_torrent)
|
|
|
|
{
|
2009-06-24 23:39:15 +02:00
|
|
|
piece_size = 64*1024;
|
2009-03-13 07:09:39 +01:00
|
|
|
}
|
2009-01-11 11:32:57 +01:00
|
|
|
|
2015-03-21 01:12:40 +01:00
|
|
|
// to support mutable torrents, alignment always has to be the piece size,
|
|
|
|
// because piece hashes are compared to determine whether files are
|
|
|
|
// identical
|
|
|
|
if (flags & mutable_torrent_support)
|
|
|
|
alignment = piece_size;
|
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
// make sure the size is an even power of 2
|
|
|
|
#ifndef NDEBUG
|
|
|
|
for (int i = 0; i < 32; ++i)
|
|
|
|
{
|
2009-01-11 11:32:57 +01:00
|
|
|
if (piece_size & (1 << i))
|
2008-05-28 10:44:40 +02:00
|
|
|
{
|
2009-01-11 11:32:57 +01:00
|
|
|
TORRENT_ASSERT((piece_size & ~(1 << i)) == 0);
|
2008-05-28 10:44:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-01-11 11:32:57 +01:00
|
|
|
m_files.set_piece_length(piece_size);
|
2015-03-21 01:12:40 +01:00
|
|
|
if (flags & (optimize_alignment | mutable_torrent_support))
|
2015-11-20 05:37:45 +01:00
|
|
|
m_files.optimize(pad_file_limit, alignment, (flags & mutable_torrent_support) != 0);
|
2015-03-21 01:12:40 +01:00
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
m_files.set_num_pieces(static_cast<int>(
|
|
|
|
(m_files.total_size() + m_files.piece_length() - 1) / m_files.piece_length()));
|
|
|
|
m_piece_hash.resize(m_files.num_pieces());
|
|
|
|
}
|
2008-09-24 19:05:12 +02:00
|
|
|
|
|
|
|
create_torrent::create_torrent(torrent_info const& ti)
|
|
|
|
: m_files(const_cast<file_storage&>(ti.files()))
|
2016-07-09 22:26:26 +02:00
|
|
|
, m_creation_date(time(nullptr))
|
2008-09-24 19:05:12 +02:00
|
|
|
, m_multifile(ti.num_files() > 1)
|
|
|
|
, m_private(ti.priv())
|
2009-03-13 07:09:39 +01:00
|
|
|
, m_merkle_torrent(ti.is_merkle_torrent())
|
2010-03-20 08:30:34 +01:00
|
|
|
, m_include_mtime(false)
|
|
|
|
, m_include_symlinks(false)
|
2008-09-24 19:05:12 +02:00
|
|
|
{
|
|
|
|
TORRENT_ASSERT(ti.is_valid());
|
2016-04-26 06:37:47 +02:00
|
|
|
TORRENT_ASSERT(ti.num_pieces() > 0);
|
|
|
|
TORRENT_ASSERT(ti.num_files() > 0);
|
|
|
|
TORRENT_ASSERT(ti.total_size() > 0);
|
|
|
|
|
2016-08-22 17:02:51 +02:00
|
|
|
if (ti.creation_date() > 0) m_creation_date = ti.creation_date();
|
2008-09-24 19:05:12 +02:00
|
|
|
|
|
|
|
if (!ti.creator().empty()) set_creator(ti.creator().c_str());
|
|
|
|
if (!ti.comment().empty()) set_comment(ti.comment().c_str());
|
|
|
|
|
2016-08-20 17:29:31 +02:00
|
|
|
for (auto const& n : ti.nodes())
|
|
|
|
add_node(n);
|
2008-09-24 19:05:12 +02:00
|
|
|
|
2016-08-22 17:02:51 +02:00
|
|
|
for (auto const& t : ti.trackers())
|
|
|
|
add_tracker(t.url, t.tier);
|
2008-09-24 19:05:12 +02:00
|
|
|
|
2016-08-22 17:02:51 +02:00
|
|
|
for (auto const& s : ti.web_seeds())
|
2010-10-10 23:06:35 +02:00
|
|
|
{
|
2016-08-22 17:02:51 +02:00
|
|
|
if (s.type == web_seed_entry::url_seed)
|
|
|
|
add_url_seed(s.url);
|
|
|
|
else if (s.type == web_seed_entry::http_seed)
|
|
|
|
add_http_seed(s.url);
|
2010-10-10 23:06:35 +02:00
|
|
|
}
|
2008-09-24 19:05:12 +02:00
|
|
|
|
|
|
|
m_piece_hash.resize(m_files.num_pieces());
|
|
|
|
for (int i = 0; i < num_pieces(); ++i) set_hash(i, ti.hash_for_piece(i));
|
|
|
|
|
2016-05-06 03:38:57 +02:00
|
|
|
boost::shared_array<char> const info = ti.metadata();
|
|
|
|
int const size = ti.metadata_size();
|
|
|
|
m_info_dict.preformatted().assign(&info[0], &info[0] + size);
|
2008-09-24 19:05:12 +02:00
|
|
|
m_info_hash = ti.info_hash();
|
|
|
|
}
|
|
|
|
|
2008-05-14 07:29:42 +02:00
|
|
|
entry create_torrent::generate() const
|
|
|
|
{
|
|
|
|
entry dict;
|
|
|
|
|
2016-04-30 05:34:25 +02:00
|
|
|
if (m_files.num_files() == 0 || m_files.total_size() == 0)
|
2009-02-23 02:21:19 +01:00
|
|
|
return dict;
|
|
|
|
|
2016-04-30 05:34:25 +02:00
|
|
|
TORRENT_ASSERT(m_files.piece_length() > 0);
|
|
|
|
|
2008-05-14 07:29:42 +02:00
|
|
|
if (!m_urls.empty()) dict["announce"] = m_urls.front().first;
|
2016-04-28 23:14:41 +02:00
|
|
|
|
2008-05-14 07:29:42 +02:00
|
|
|
if (!m_nodes.empty())
|
|
|
|
{
|
|
|
|
entry& nodes = dict["nodes"];
|
|
|
|
entry::list_type& nodes_list = nodes.list();
|
2016-11-15 18:03:11 +01:00
|
|
|
for (auto const& n : m_nodes)
|
2008-05-14 07:29:42 +02:00
|
|
|
{
|
|
|
|
entry::list_type node;
|
2016-11-15 18:03:11 +01:00
|
|
|
node.push_back(entry(n.first));
|
|
|
|
node.push_back(entry(n.second));
|
2008-05-14 07:29:42 +02:00
|
|
|
nodes_list.push_back(entry(node));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_urls.size() > 1)
|
|
|
|
{
|
|
|
|
entry trackers(entry::list_t);
|
|
|
|
entry tier(entry::list_t);
|
|
|
|
int current_tier = m_urls.front().second;
|
2016-11-15 18:03:11 +01:00
|
|
|
for (auto const& url : m_urls)
|
2008-05-14 07:29:42 +02:00
|
|
|
{
|
2016-11-15 18:03:11 +01:00
|
|
|
if (url.second != current_tier)
|
2008-05-14 07:29:42 +02:00
|
|
|
{
|
2016-11-15 18:03:11 +01:00
|
|
|
current_tier = url.second;
|
2008-05-14 07:29:42 +02:00
|
|
|
trackers.list().push_back(tier);
|
|
|
|
tier.list().clear();
|
|
|
|
}
|
2016-11-15 18:03:11 +01:00
|
|
|
tier.list().push_back(entry(url.first));
|
2008-05-14 07:29:42 +02:00
|
|
|
}
|
|
|
|
trackers.list().push_back(tier);
|
|
|
|
dict["announce-list"] = trackers;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_comment.empty())
|
|
|
|
dict["comment"] = m_comment;
|
|
|
|
|
2010-08-22 00:10:16 +02:00
|
|
|
dict["creation date"] = m_creation_date;
|
2008-05-14 07:29:42 +02:00
|
|
|
|
|
|
|
if (!m_created_by.empty())
|
|
|
|
dict["created by"] = m_created_by;
|
2016-04-28 23:14:41 +02:00
|
|
|
|
2008-05-14 07:29:42 +02:00
|
|
|
if (!m_url_seeds.empty())
|
|
|
|
{
|
|
|
|
if (m_url_seeds.size() == 1)
|
|
|
|
{
|
|
|
|
dict["url-list"] = m_url_seeds.front();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
entry& list = dict["url-list"];
|
2016-11-15 18:03:11 +01:00
|
|
|
for (auto const& url : m_url_seeds)
|
2008-05-14 07:29:42 +02:00
|
|
|
{
|
2016-11-15 18:03:11 +01:00
|
|
|
list.list().push_back(entry(url));
|
2008-05-14 07:29:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-10 23:06:35 +02:00
|
|
|
if (!m_http_seeds.empty())
|
|
|
|
{
|
|
|
|
if (m_http_seeds.size() == 1)
|
|
|
|
{
|
|
|
|
dict["httpseeds"] = m_http_seeds.front();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
entry& list = dict["httpseeds"];
|
2016-11-15 18:03:11 +01:00
|
|
|
for (auto const& url : m_http_seeds)
|
2010-10-10 23:06:35 +02:00
|
|
|
{
|
2016-11-15 18:03:11 +01:00
|
|
|
list.list().push_back(entry(url));
|
2010-10-10 23:06:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-14 07:29:42 +02:00
|
|
|
entry& info = dict["info"];
|
2016-05-06 03:38:57 +02:00
|
|
|
if (m_info_dict.type() == entry::dictionary_t
|
|
|
|
|| m_info_dict.type() == entry::preformatted_t)
|
2008-09-24 19:05:12 +02:00
|
|
|
{
|
|
|
|
info = m_info_dict;
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
2015-03-21 01:12:40 +01:00
|
|
|
if (!m_collections.empty())
|
|
|
|
{
|
|
|
|
entry& list = info["collections"];
|
2016-11-15 18:03:11 +01:00
|
|
|
for (auto const& c : m_collections)
|
2015-03-21 01:12:40 +01:00
|
|
|
{
|
2016-11-15 18:03:11 +01:00
|
|
|
list.list().push_back(entry(c));
|
2015-03-21 01:12:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_similar.empty())
|
|
|
|
{
|
|
|
|
entry& list = info["similar"];
|
2016-11-15 18:03:11 +01:00
|
|
|
for (auto const& ih : m_similar)
|
2015-03-21 01:12:40 +01:00
|
|
|
{
|
2016-11-15 18:03:11 +01:00
|
|
|
list.list().push_back(entry(ih.to_string()));
|
2015-03-21 01:12:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
info["name"] = m_files.name();
|
2008-05-14 07:29:42 +02:00
|
|
|
|
2011-08-28 23:06:15 +02:00
|
|
|
if (!m_root_cert.empty())
|
|
|
|
info["ssl-cert"] = m_root_cert;
|
|
|
|
|
2008-05-14 07:29:42 +02:00
|
|
|
if (m_private) info["private"] = 1;
|
|
|
|
|
|
|
|
if (!m_multifile)
|
|
|
|
{
|
2015-01-21 16:46:12 +01:00
|
|
|
if (m_include_mtime) info["mtime"] = m_files.mtime(0);
|
|
|
|
info["length"] = m_files.file_size(0);
|
2016-08-08 04:37:10 +02:00
|
|
|
int const flags = m_files.file_flags(0);
|
2015-01-21 16:46:12 +01:00
|
|
|
if (flags & (file_storage::flag_pad_file
|
|
|
|
| file_storage::flag_hidden
|
|
|
|
| file_storage::flag_executable
|
|
|
|
| file_storage::flag_symlink))
|
2009-06-23 04:50:41 +02:00
|
|
|
{
|
|
|
|
std::string& attr = info["attr"].string();
|
2015-01-21 16:46:12 +01:00
|
|
|
if (flags & file_storage::flag_pad_file) attr += 'p';
|
|
|
|
if (flags & file_storage::flag_hidden) attr += 'h';
|
|
|
|
if (flags & file_storage::flag_executable) attr += 'x';
|
|
|
|
if (m_include_symlinks && (flags & file_storage::flag_symlink)) attr += 'l';
|
2009-07-01 10:35:45 +02:00
|
|
|
}
|
2010-11-15 06:10:36 +01:00
|
|
|
if (m_include_symlinks
|
2015-01-21 16:46:12 +01:00
|
|
|
&& (flags & file_storage::flag_symlink))
|
2009-07-01 10:35:45 +02:00
|
|
|
{
|
|
|
|
entry& sympath_e = info["symlink path"];
|
2015-08-07 06:30:29 +02:00
|
|
|
|
2015-01-21 16:46:12 +01:00
|
|
|
std::string split = split_path(m_files.symlink(0));
|
2016-07-09 22:26:26 +02:00
|
|
|
for (char const* e = split.c_str(); e != nullptr; e = next_path_element(e))
|
2016-07-24 00:57:04 +02:00
|
|
|
sympath_e.list().push_back(e);
|
2009-06-23 04:50:41 +02:00
|
|
|
}
|
2010-03-27 16:51:30 +01:00
|
|
|
if (!m_filehashes.empty())
|
|
|
|
{
|
|
|
|
info["sha1"] = m_filehashes[0].to_string();
|
|
|
|
}
|
2008-05-14 07:29:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!info.find_key("files"))
|
|
|
|
{
|
|
|
|
entry& files = info["files"];
|
|
|
|
|
2013-08-12 09:30:57 +02:00
|
|
|
for (int i = 0; i < m_files.num_files(); ++i)
|
2008-05-14 07:29:42 +02:00
|
|
|
{
|
|
|
|
files.list().push_back(entry());
|
|
|
|
entry& file_e = files.list().back();
|
2015-08-07 06:30:29 +02:00
|
|
|
if (m_include_mtime && m_files.mtime(i)) file_e["mtime"] = m_files.mtime(i);
|
2013-08-12 09:30:57 +02:00
|
|
|
file_e["length"] = m_files.file_size(i);
|
2008-05-14 07:29:42 +02:00
|
|
|
entry& path_e = file_e["path"];
|
|
|
|
|
2013-08-12 09:30:57 +02:00
|
|
|
TORRENT_ASSERT(has_parent_path(m_files.file_path(i)));
|
2008-05-14 07:29:42 +02:00
|
|
|
|
2015-08-07 06:30:29 +02:00
|
|
|
{
|
|
|
|
std::string split = split_path(m_files.file_path(i));
|
|
|
|
TORRENT_ASSERT(split.c_str() == m_files.name());
|
2009-10-26 02:29:39 +01:00
|
|
|
|
2015-08-07 06:30:29 +02:00
|
|
|
for (char const* e = next_path_element(split.c_str());
|
2016-07-09 22:26:26 +02:00
|
|
|
e != nullptr; e = next_path_element(e))
|
2015-08-07 06:30:29 +02:00
|
|
|
path_e.list().push_back(entry(e));
|
|
|
|
}
|
2009-10-26 02:29:39 +01:00
|
|
|
|
2016-11-15 18:03:11 +01:00
|
|
|
int const flags = m_files.file_flags(i);
|
2013-08-12 09:30:57 +02:00
|
|
|
if (flags != 0)
|
2009-01-11 23:27:43 +01:00
|
|
|
{
|
|
|
|
std::string& attr = file_e["attr"].string();
|
2013-08-12 09:30:57 +02:00
|
|
|
if (flags & file_storage::flag_pad_file) attr += 'p';
|
|
|
|
if (flags & file_storage::flag_hidden) attr += 'h';
|
|
|
|
if (flags & file_storage::flag_executable) attr += 'x';
|
|
|
|
if (m_include_symlinks && (flags & file_storage::flag_symlink)) attr += 'l';
|
2009-07-01 10:35:45 +02:00
|
|
|
}
|
2013-08-12 09:30:57 +02:00
|
|
|
|
2010-11-15 06:10:36 +01:00
|
|
|
if (m_include_symlinks
|
2013-08-12 09:30:57 +02:00
|
|
|
&& (flags & file_storage::flag_symlink))
|
2009-07-01 10:35:45 +02:00
|
|
|
{
|
|
|
|
entry& sympath_e = file_e["symlink path"];
|
|
|
|
|
2013-08-12 09:30:57 +02:00
|
|
|
std::string split = split_path(m_files.symlink(i));
|
2016-07-09 22:26:26 +02:00
|
|
|
for (char const* e = split.c_str(); e != nullptr; e = next_path_element(e))
|
2009-10-26 02:29:39 +01:00
|
|
|
sympath_e.list().push_back(entry(e));
|
2009-01-11 23:27:43 +01:00
|
|
|
}
|
2013-08-12 09:30:57 +02:00
|
|
|
if (!m_filehashes.empty() && m_filehashes[i] != sha1_hash())
|
2010-03-27 16:51:30 +01:00
|
|
|
{
|
2013-08-12 09:30:57 +02:00
|
|
|
file_e["sha1"] = m_filehashes[i].to_string();
|
2010-03-27 16:51:30 +01:00
|
|
|
}
|
2008-05-14 07:29:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-28 10:44:40 +02:00
|
|
|
info["piece length"] = m_files.piece_length();
|
2009-03-13 07:09:39 +01:00
|
|
|
if (m_merkle_torrent)
|
2008-05-14 07:29:42 +02:00
|
|
|
{
|
2016-11-15 18:03:11 +01:00
|
|
|
int const num_leafs = merkle_num_leafs(m_files.num_pieces());
|
|
|
|
int const num_nodes = merkle_num_nodes(num_leafs);
|
|
|
|
int const first_leaf = num_nodes - num_leafs;
|
2011-07-30 19:35:22 +02:00
|
|
|
m_merkle_tree.resize(num_nodes);
|
2016-11-15 18:03:11 +01:00
|
|
|
int const num_pieces = int(m_piece_hash.size());
|
2009-03-13 07:09:39 +01:00
|
|
|
for (int i = 0; i < num_pieces; ++i)
|
2011-07-30 19:35:22 +02:00
|
|
|
m_merkle_tree[first_leaf + i] = m_piece_hash[i];
|
2009-03-13 07:09:39 +01:00
|
|
|
for (int i = num_pieces; i < num_leafs; ++i)
|
2016-11-15 18:03:11 +01:00
|
|
|
m_merkle_tree[first_leaf + i].clear();
|
2009-03-13 07:09:39 +01:00
|
|
|
|
|
|
|
// now that we have initialized all leaves, build
|
|
|
|
// each level bottom-up
|
|
|
|
int level_start = first_leaf;
|
|
|
|
int level_size = num_leafs;
|
|
|
|
while (level_start > 0)
|
|
|
|
{
|
|
|
|
int parent = merkle_get_parent(level_start);
|
|
|
|
for (int i = level_start; i < level_start + level_size; i += 2, ++parent)
|
|
|
|
{
|
|
|
|
hasher h;
|
2016-07-22 16:29:39 +02:00
|
|
|
h.update(m_merkle_tree[i]);
|
2016-11-15 18:03:11 +01:00
|
|
|
h.update(m_merkle_tree[i + 1]);
|
2011-07-30 19:35:22 +02:00
|
|
|
m_merkle_tree[parent] = h.final();
|
2009-03-13 07:09:39 +01:00
|
|
|
}
|
|
|
|
level_start = merkle_get_parent(level_start);
|
|
|
|
level_size /= 2;
|
|
|
|
}
|
|
|
|
TORRENT_ASSERT(level_size == 1);
|
2016-07-22 16:29:39 +02:00
|
|
|
info["root hash"] = m_merkle_tree[0];
|
2009-03-13 07:09:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string& p = info["pieces"].string();
|
|
|
|
|
2016-07-22 16:29:39 +02:00
|
|
|
for (sha1_hash const& h : m_piece_hash)
|
|
|
|
p.append(h.data(), h.size());
|
2008-05-14 07:29:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<char> buf;
|
|
|
|
bencode(std::back_inserter(buf), info);
|
2016-07-22 16:29:39 +02:00
|
|
|
m_info_hash = hasher(buf).final();
|
2008-05-14 07:29:42 +02:00
|
|
|
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
|
2016-09-22 04:59:43 +02:00
|
|
|
void create_torrent::add_tracker(string_view url, int const tier)
|
2008-05-14 07:29:42 +02:00
|
|
|
{
|
2016-11-15 18:03:11 +01:00
|
|
|
using announce_entry = std::pair<std::string, int>;
|
2016-10-19 23:28:35 +02:00
|
|
|
auto i = std::find_if(m_urls.begin(), m_urls.end()
|
2016-12-05 16:40:05 +01:00
|
|
|
, [&url](announce_entry const& ae) { return ae.first == url; });
|
2016-10-19 23:28:35 +02:00
|
|
|
if (i != m_urls.end()) return;
|
2016-12-05 16:40:05 +01:00
|
|
|
m_urls.emplace_back(url.to_string(), tier);
|
2008-05-14 07:29:42 +02:00
|
|
|
|
|
|
|
std::sort(m_urls.begin(), m_urls.end()
|
2016-12-05 16:40:05 +01:00
|
|
|
, [](announce_entry const& lhs, announce_entry const& rhs)
|
|
|
|
{ return lhs.second < rhs.second; });
|
2008-05-14 07:29:42 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 04:59:43 +02:00
|
|
|
void create_torrent::set_root_cert(string_view cert)
|
2011-08-28 23:06:15 +02:00
|
|
|
{
|
2016-09-22 04:59:43 +02:00
|
|
|
m_root_cert.assign(cert.data(), cert.size());
|
2011-08-28 23:06:15 +02:00
|
|
|
}
|
|
|
|
|
2015-03-21 01:12:40 +01:00
|
|
|
void create_torrent::add_similar_torrent(sha1_hash ih)
|
|
|
|
{
|
|
|
|
m_similar.push_back(ih);
|
|
|
|
}
|
|
|
|
|
2016-09-22 04:59:43 +02:00
|
|
|
void create_torrent::add_collection(string_view c)
|
2015-03-21 01:12:40 +01:00
|
|
|
{
|
2016-09-22 04:59:43 +02:00
|
|
|
m_collections.emplace_back(c);
|
2015-03-21 01:12:40 +01:00
|
|
|
}
|
|
|
|
|
2008-05-14 07:29:42 +02:00
|
|
|
void create_torrent::set_hash(int index, sha1_hash const& h)
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0);
|
2015-08-07 06:30:29 +02:00
|
|
|
TORRENT_ASSERT(index < int(m_piece_hash.size()));
|
2008-05-14 07:29:42 +02:00
|
|
|
m_piece_hash[index] = h;
|
|
|
|
}
|
|
|
|
|
2010-03-27 16:51:30 +01:00
|
|
|
void create_torrent::set_file_hash(int index, sha1_hash const& h)
|
|
|
|
{
|
|
|
|
TORRENT_ASSERT(index >= 0);
|
2015-08-07 06:30:29 +02:00
|
|
|
TORRENT_ASSERT(index < int(m_files.num_files()));
|
2010-03-27 16:51:30 +01:00
|
|
|
if (m_filehashes.empty()) m_filehashes.resize(m_files.num_files());
|
|
|
|
m_filehashes[index] = h;
|
|
|
|
}
|
|
|
|
|
2016-09-24 15:10:54 +02:00
|
|
|
void create_torrent::add_node(std::pair<std::string, int> node)
|
2008-05-14 07:29:42 +02:00
|
|
|
{
|
2016-09-24 15:10:54 +02:00
|
|
|
m_nodes.emplace_back(std::move(node));
|
2008-05-14 07:29:42 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 04:59:43 +02:00
|
|
|
void create_torrent::add_url_seed(string_view url)
|
2008-05-14 07:29:42 +02:00
|
|
|
{
|
2016-09-22 04:59:43 +02:00
|
|
|
m_url_seeds.emplace_back(url);
|
2008-05-14 07:29:42 +02:00
|
|
|
}
|
|
|
|
|
2016-09-22 04:59:43 +02:00
|
|
|
void create_torrent::add_http_seed(string_view url)
|
2010-10-10 23:06:35 +02:00
|
|
|
{
|
2016-09-22 04:59:43 +02:00
|
|
|
m_http_seeds.emplace_back(url);
|
2010-10-10 23:06:35 +02:00
|
|
|
}
|
|
|
|
|
2008-05-14 07:29:42 +02:00
|
|
|
void create_torrent::set_comment(char const* str)
|
|
|
|
{
|
2016-07-09 22:26:26 +02:00
|
|
|
if (str == nullptr) m_comment.clear();
|
2011-09-22 23:24:50 +02:00
|
|
|
else m_comment = str;
|
2008-05-14 07:29:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void create_torrent::set_creator(char const* str)
|
|
|
|
{
|
2016-07-09 22:26:26 +02:00
|
|
|
if (str == nullptr) m_created_by.clear();
|
2011-09-22 23:24:50 +02:00
|
|
|
else m_created_by = str;
|
2008-05-14 07:29:42 +02:00
|
|
|
}
|
|
|
|
}
|