the file pool has been moved to the session and its size can be controlled via session_settings. Added untested option to allow multiple connections from the same IP.
This commit is contained in:
@@ -180,6 +180,7 @@ int main(int argc, char* argv[])
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/storage.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
#include "libtorrent/file_pool.hpp"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
@@ -188,7 +189,10 @@ int main(int argc, char* argv[])
|
||||
using namespace boost::filesystem;
|
||||
using namespace libtorrent;
|
||||
|
||||
void add_files(torrent_info& t, path const& p, path const& l)
|
||||
void add_files(
|
||||
torrent_info& t
|
||||
, path const& p
|
||||
, path const& l)
|
||||
{
|
||||
path f(p / l);
|
||||
if (is_directory(f))
|
||||
@@ -199,10 +203,7 @@ void add_files(torrent_info& t, path const& p, path const& l)
|
||||
else
|
||||
{
|
||||
std::cerr << "adding \"" << l.string() << "\"\n";
|
||||
file fi(f, file::in);
|
||||
fi.seek(0, file::end);
|
||||
libtorrent::size_type size = fi.tell();
|
||||
t.add_file(l, size);
|
||||
t.add_file(l, file_size(f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,6 +212,8 @@ int main(int argc, char* argv[])
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
path::default_name_check(no_check);
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
std::cerr << "usage: make_torrent <output torrent-file> "
|
||||
@@ -218,13 +221,11 @@ int main(int argc, char* argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::filesystem::path::default_name_check(native);
|
||||
|
||||
try
|
||||
{
|
||||
torrent_info t;
|
||||
path full_path = initial_path() / path(argv[3]);
|
||||
ofstream out(initial_path() / path(argv[1]), std::ios_base::binary);
|
||||
path full_path = complete(path(argv[3]));
|
||||
ofstream out(complete(path(argv[1])), std::ios_base::binary);
|
||||
|
||||
int piece_size = 256 * 1024;
|
||||
char const* creator_str = "libtorrent";
|
||||
@@ -232,7 +233,8 @@ int main(int argc, char* argv[])
|
||||
add_files(t, full_path.branch_path(), full_path.leaf());
|
||||
t.set_piece_size(piece_size);
|
||||
|
||||
storage st(t, full_path.branch_path());
|
||||
file_pool fp;
|
||||
storage st(t, full_path.branch_path(), fp);
|
||||
t.add_tracker(argv[2]);
|
||||
|
||||
// calculate the hash for all pieces
|
||||
@@ -251,8 +253,8 @@ int main(int argc, char* argv[])
|
||||
// create the torrent and print it to out
|
||||
entry e = t.create_torrent();
|
||||
libtorrent::bencode(std::ostream_iterator<char>(out), e);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << "\n";
|
||||
}
|
||||
|
@@ -158,22 +158,26 @@ Shows how to create a torrent from a directory tree::
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
#include "libtorrent/entry.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/file.hpp"
|
||||
#include "libtorrent/storage.hpp"
|
||||
#include "libtorrent/hasher.hpp"
|
||||
|
||||
#include "libtorrent/file_pool.hpp"
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
|
||||
using namespace boost::filesystem;
|
||||
using namespace libtorrent;
|
||||
|
||||
void add_files(torrent_info& t, path const& p, path const& l)
|
||||
|
||||
void add_files(
|
||||
torrent_info& t
|
||||
, path const& p
|
||||
, path const& l)
|
||||
{
|
||||
path f(p / l);
|
||||
if (is_directory(f))
|
||||
@@ -184,42 +188,40 @@ Shows how to create a torrent from a directory tree::
|
||||
else
|
||||
{
|
||||
std::cerr << "adding \"" << l.string() << "\"\n";
|
||||
file fi(f, file::in);
|
||||
fi.seek(0, file::end);
|
||||
libtorrent::size_type size = fi.tell();
|
||||
t.add_file(l, size);
|
||||
t.add_file(l, file_size(f));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
using namespace libtorrent;
|
||||
using namespace boost::filesystem;
|
||||
|
||||
|
||||
path::default_name_check(no_check);
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
std::cerr << "usage: make_torrent <output torrent-file> "
|
||||
"<announce url> <file or directory to create torrent from>\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
boost::filesystem::path::default_name_check(native);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
torrent_info t;
|
||||
path full_path = initial_path() / path(argv[3]);
|
||||
ofstream out(initial_path() / path(argv[1]), std::ios_base::binary);
|
||||
|
||||
path full_path = complete(path(argv[3]));
|
||||
ofstream out(complete(path(argv[1])), std::ios_base::binary);
|
||||
|
||||
int piece_size = 256 * 1024;
|
||||
char const* creator_str = "libtorrent";
|
||||
|
||||
|
||||
add_files(t, full_path.branch_path(), full_path.leaf());
|
||||
t.set_piece_size(piece_size);
|
||||
|
||||
storage st(t, full_path.branch_path());
|
||||
|
||||
file_pool fp;
|
||||
storage st(t, full_path.branch_path(), fp);
|
||||
t.add_tracker(argv[2]);
|
||||
|
||||
|
||||
// calculate the hash for all pieces
|
||||
int num = t.num_pieces();
|
||||
std::vector<char> buf(piece_size);
|
||||
@@ -230,19 +232,19 @@ Shows how to create a torrent from a directory tree::
|
||||
t.set_hash(i, h.final());
|
||||
std::cerr << (i+1) << "/" << num << "\r";
|
||||
}
|
||||
|
||||
|
||||
t.set_creator(creator_str);
|
||||
|
||||
|
||||
// create the torrent and print it to out
|
||||
entry e = t.create_torrent();
|
||||
libtorrent::bencode(std::ostream_iterator<char>(out), e);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << "\n";
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -1913,6 +1913,8 @@ struct session_settings
|
||||
int peer_timeout;
|
||||
int urlseed_timeout;
|
||||
int urlseed_pipeline_size;
|
||||
int file_pool_size;
|
||||
bool allow_multiple_connections_per_ip;
|
||||
};
|
||||
</pre>
|
||||
<p><tt class="docutils literal"><span class="pre">proxy_ip</span></tt> may be a hostname or ip to a http proxy to use. If this is
|
||||
@@ -1973,6 +1975,20 @@ url seeds. This value defaults to 20 seconds.</p>
|
||||
using persistent connections to HTTP 1.1 servers, the client is allowed to
|
||||
send more requests before the first response is received. This number controls
|
||||
the number of outstanding requests to use with url-seeds. Default is 5.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">file_pool_size</span></tt> is the the upper limit on the total number of files this
|
||||
session will keep open. The reason why files are left open at all is that
|
||||
some anti virus software hooks on every file close, and scans the file for
|
||||
viruses. deferring the closing of the files will be the difference between
|
||||
a usable system and a completely hogged down system. Most operating systems
|
||||
also has a limit on the total number of file descriptors a process may have
|
||||
open. It is usually a good idea to find this limit and set the number of
|
||||
connections and the number of files limits so their sum is slightly below it.</p>
|
||||
<p><tt class="docutils literal"><span class="pre">allow_multiple_connections_per_ip</span></tt> determines if connections from the
|
||||
same IP address as existing connections should be rejected or not. Multiple
|
||||
connections from the same IP address is not allowed by default, to prevent
|
||||
abusive behavior by peers. It may be useful to allow such connections in
|
||||
cases where simulations are run on the same machie, and all peers in a
|
||||
swarm has the same IP address.</p>
|
||||
</div>
|
||||
<div class="section" id="ip-filter">
|
||||
<h1><a name="ip-filter">ip_filter</a></h1>
|
||||
|
@@ -1894,6 +1894,8 @@ that will be sent to the tracker. The user-agent is a good way to identify your
|
||||
int peer_timeout;
|
||||
int urlseed_timeout;
|
||||
int urlseed_pipeline_size;
|
||||
int file_pool_size;
|
||||
bool allow_multiple_connections_per_ip;
|
||||
};
|
||||
|
||||
``proxy_ip`` may be a hostname or ip to a http proxy to use. If this is
|
||||
@@ -1970,6 +1972,22 @@ using persistent connections to HTTP 1.1 servers, the client is allowed to
|
||||
send more requests before the first response is received. This number controls
|
||||
the number of outstanding requests to use with url-seeds. Default is 5.
|
||||
|
||||
``file_pool_size`` is the the upper limit on the total number of files this
|
||||
session will keep open. The reason why files are left open at all is that
|
||||
some anti virus software hooks on every file close, and scans the file for
|
||||
viruses. deferring the closing of the files will be the difference between
|
||||
a usable system and a completely hogged down system. Most operating systems
|
||||
also has a limit on the total number of file descriptors a process may have
|
||||
open. It is usually a good idea to find this limit and set the number of
|
||||
connections and the number of files limits so their sum is slightly below it.
|
||||
|
||||
``allow_multiple_connections_per_ip`` determines if connections from the
|
||||
same IP address as existing connections should be rejected or not. Multiple
|
||||
connections from the same IP address is not allowed by default, to prevent
|
||||
abusive behavior by peers. It may be useful to allow such connections in
|
||||
cases where simulations are run on the same machie, and all peers in a
|
||||
swarm has the same IP address.
|
||||
|
||||
ip_filter
|
||||
=========
|
||||
|
||||
|
Reference in New Issue
Block a user