* Minor BSD portability fixes.

* Added torrent::TrackerList::{set_,}key() and made rtorrent save the
key between sessions.

* Added import option to the man page.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@665 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2006-04-06 16:40:25 +00:00
parent 8a8cfe5e3d
commit dc1f6d4f23
4 changed files with 141 additions and 182 deletions
+125 -63
View File
@@ -221,14 +221,18 @@
<varlistentry>
<term>i</term>
<listitem><para>
Display chunk rarity.
</para></listitem>
</varlistentry>
<varlistentry>
<term>o</term>
<listitem><para>
Display the tracker list. Cycle the trackers in a group
Display the tracker list. Cycle the trackers in a group
with the space-bar.
</para></listitem>
</varlistentry>
@@ -236,29 +240,37 @@ Display chunk rarity.
<varlistentry>
<term>p</term>
<listitem><para>
View peer and torrent information.
View peer and torrent information.
</para></listitem>
</varlistentry>
<varlistentry>
<term>t | T</term>
<listitem><para>
Initiate tracker request. Use capital T to force the
request, ignoring the "min interval" set by the tracker.
Initiate tracker request. Use capital T to force the request, ignoring
the "min interval" set by the tracker.
</para></listitem>
</varlistentry>
<varlistentry>
<term>k</term>
<listitem><para>
Disconnect peer.
</para></listitem>
</varlistentry>
<varlistentry>
<term>*</term>
<listitem><para>
Choke/Snubb peer.
</para></listitem>
</varlistentry>
@@ -277,29 +289,37 @@ Choke/Snubb peer.
<varlistentry>
<term>-b <replaceable>a.b.c.d</replaceable></term>
<listitem><para>
Bind listening socket and outgoing connections to this
network interface address.
Bind listening socket and outgoing connections to this network
interface address.
</para></listitem>
</varlistentry>
<varlistentry>
<term>-d <replaceable>directory</replaceable></term>
<listitem><para>
Set the default download directory. Defaults to "./".
Set the default download directory. Defaults to "./".
</para></listitem>
</varlistentry>
<varlistentry>
<term>-h</term>
<listitem><para>
Display help and exit.
Display help and exit.
</para></listitem>
</varlistentry>
<varlistentry>
<term>-i <replaceable>a.b.c.d</replaceable></term>
<listitem><para>
Set the address reported to the tracker.
Set the address reported to the tracker.
</para></listitem>
</varlistentry>
@@ -318,20 +338,23 @@ to allow comma in the option.
<varlistentry>
<term>-p <replaceable>a-b</replaceable></term>
<listitem><para>
Try to open a listening port in the range
<emphasis>a</emphasis> up to and including
<emphasis>b</emphasis>.
Try to open a listening port in the range <emphasis>a</emphasis> up to
and including <emphasis>b</emphasis>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>-s <replaceable>directory</replaceable></term>
<listitem><para>
Session management will be enabled and the torrent files for
all open downloads will be stored in this directory. Only
one instance of rtorrent should be used with each session
directory, though at the moment no locking is done. An empty
string will disable the session directory.
Session management will be enabled and the torrent files for all open
downloads will be stored in this directory. Only one instance of
rtorrent should be used with each session directory, though at the
moment no locking is done. An empty string will disable the session
directory.
</para></listitem>
</varlistentry>
@@ -350,81 +373,101 @@ to allow comma in the option.
<varlistentry>
<term>max_peers = <replaceable>value</replaceable></term>
<listitem><para>
Set the maximum number of peers to allow in each download.
Set the maximum number of peers to allow in each download.
</para></listitem>
</varlistentry>
<varlistentry>
<term>min_peers = <replaceable>value</replaceable></term>
<listitem><para>
Set the minimum number of peers to try to connect to in each
download.
Set the minimum number of peers to try to connect to in each download.
</para></listitem>
</varlistentry>
<varlistentry>
<term>max_uploads = <replaceable>value</replaceable></term>
<listitem><para>
Set the maximum number of simultaneous uploads per download.
Set the maximum number of simultaneous uploads per download.
</para></listitem>
</varlistentry>
<varlistentry>
<term>download_rate = <replaceable>KB</replaceable></term>
<listitem><para>
Set the maximum global download rate.
Set the maximum global download rate.
</para></listitem>
</varlistentry>
<varlistentry>
<term>upload_rate = <replaceable>KB</replaceable></term>
<listitem><para>
Set the maximum global upload rate.
Set the maximum global upload rate.
</para></listitem>
</varlistentry>
<varlistentry>
<term>bind = <replaceable>a.b.c.d</replaceable></term>
<listitem><para>
Bind listening socket and outgoing connections to this
network interface address.
Bind listening socket and outgoing connections to this network
interface address.
</para></listitem>
</varlistentry>
<varlistentry>
<term>ip = <replaceable>a.b.c.d</replaceable></term>
<listitem><para>
Set the address reported to the tracker.
Set the address reported to the tracker.
</para></listitem>
</varlistentry>
<varlistentry>
<term>port_range = <replaceable>a-b</replaceable></term>
<listitem><para>
Try to open a listening port in the range
<emphasis>a</emphasis> up to and including
<emphasis>b</emphasis>.
Try to open a listening port in the range <emphasis>a</emphasis> up to
and including <emphasis>b</emphasis>.
</para></listitem>
</varlistentry>
<varlistentry>
<term>port_random = <replaceable>yes | no</replaceable></term>
<listitem><para>
Open the listening port at a random position in the port range.
Open the listening port at a random position in the port range.
</para></listitem>
</varlistentry>
<varlistentry>
<term>check_hash = <replaceable>yes | no</replaceable></term>
<listitem><para>
Perform hash check on finished downloads.
Perform hash check on finished downloads.
</para></listitem>
</varlistentry>
<varlistentry>
<term>directory = <replaceable>directory</replaceable></term>
<listitem><para>
Set the default download directory. Defaults to "./".
Set the default download directory. Defaults to "./".
</para></listitem>
</varlistentry>
@@ -432,11 +475,11 @@ to allow comma in the option.
<term>session = <replaceable>directory</replaceable></term>
<listitem><para>
Session management will be enabled and the torrent files for
all open downloads will be stored in this directory. Only
one instance of rtorrent should be used with each session
directory, though at the moment no locking is done. An empty
string will disable the session directory.
Session management will be enabled and the torrent files for all open
downloads will be stored in this directory. Only one instance of
rtorrent should be used with each session directory, though at the
moment no locking is done. An empty string will disable the session
directory.
</para></listitem>
</varlistentry>
@@ -445,7 +488,7 @@ to allow comma in the option.
<term>http_proxy = <replaceable>url</replaceable></term>
<listitem><para>
Use a http proxy. Use an empty string to disable.
Use a http proxy. Use an empty string to disable.
</para></listitem>
</varlistentry>
@@ -454,9 +497,9 @@ to allow comma in the option.
<term>encoding_list = <replaceable>encoding</replaceable></term>
<listitem><para>
Add a preferred filename encoding to the list. The encodings
are attempted in the order they are inserted, if none match
the torrent default is used.
Add a preferred filename encoding to the list. The encodings are
attempted in the order they are inserted, if none match the torrent
default is used.
</para></listitem>
</varlistentry>
@@ -483,7 +526,18 @@ start a task every day at <emphasis>18:00</emphasis>, use
<term>schedule_remove = <replaceable>id</replaceable></term>
<listitem><para>
Delete <emphasis>id</emphasis> from the scheduler.
Delete <emphasis>id</emphasis> from the scheduler.
</para></listitem>
</varlistentry>
<varlistentry>
<term>stop_untied =</term>
<term>remove_untied =</term>
<listitem><para>
Stop or remove the torrents that are tied to filenames that have been
deleted, the association is then cleared.
</para></listitem>
</varlistentry>
@@ -503,12 +557,12 @@ to the filename provided.
</varlistentry>
<varlistentry>
<term>stop_untied =</term>
<term>remove_untied =</term>
<term>import = <replaceable>file</replaceable></term>
<term>try_import = <replaceable>file</replaceable></term>
<listitem><para>
Stop or remove the torrents that are tied to filenames that have been
deleted, the association is then cleared.
Load a resource file. <emphasis>try_import</emphasis> does not throw
torrent::input_error exception on bad input.
</para></listitem>
</varlistentry>
@@ -529,45 +583,53 @@ deleted, the association is then cleared.
<varlistentry>
<term>hash_read_ahead = <replaceable>MB</replaceable></term>
<listitem><para>
Configure how far ahead we ask the kernel to read when doing
hash checking. The hash checker uses madvise(...,
MADV_WILLNEED) for the requests.
Configure how far ahead we ask the kernel to read when doing hash
checking. The hash checker uses madvise(..., MADV_WILLNEED) for the
requests.
</para></listitem>
</varlistentry>
<varlistentry>
<term>hash_interval = <replaceable>ms</replaceable></term>
<listitem><para>
Interval between attempts to check the hash when the chunk
is not in memory, in milliseconds.
Interval between attempts to check the hash when the chunk is not in
memory, in milliseconds.
</para></listitem>
</varlistentry>
<varlistentry>
<term>hash_max_tries = <replaceable>tries</replaceable></term>
<listitem><para>
Number of attempts to check the hash while using the mincore
status, before forcing. Overworked systems might need lower
values to get a decent hash checking rate.
Number of attempts to check the hash while using the mincore status,
before forcing. Overworked systems might need lower values to get a
decent hash checking rate.
</para></listitem>
</varlistentry>
<varlistentry>
<term>max_open_files = <replaceable>value</replaceable></term>
<listitem><para>
Number of files to simultaneously keep open. Libtorrent
dynamically opens and closes files when mapping files to
memory. Defaults to 128.
Number of files to simultaneously keep open. Libtorrent dynamically
opens and closes files when mapping files to memory. Defaults to 128.
</para></listitem>
</varlistentry>
<varlistentry>
<term>max_open_sockets = <replaceable>value</replaceable></term>
<listitem><para>
Number of sockets to simultaneously keep open. This value is
set to be <emphasis>sysconf(_SC_OPEN_MAX) - 256</emphasis>
at startup. This gives the client 128 sockets to use as it
wishes.
Number of sockets to simultaneously keep open. This value is set to be
<emphasis>sysconf(_SC_OPEN_MAX) - 256</emphasis> at startup. This
gives the client 128 sockets to use as it wishes.
</para></listitem>
</varlistentry>
@@ -575,8 +637,8 @@ deleted, the association is then cleared.
<term>umask = <replaceable>0644</replaceable></term>
<listitem><para>
Set the umask for this process, which is applied to all
files created by the program.
Set the umask for this process, which is applied to all files created
by the program.
</para></listitem>
</varlistentry>
-110
View File
@@ -108,113 +108,3 @@ regex::operator () (const std::string& text) const {
}
#endif
// rak - Rakshasa's toolbox
// Copyright (C) 2005-2006, Jari Sundell
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// In addition, as a special exception, the copyright holders give
// permission to link the code of portions of this program with the
// OpenSSL library under certain conditions as described in each
// individual source file, and distribute linked combinations
// including the two.
//
// You must obey the GNU General Public License in all respects for
// all of the code used other than OpenSSL. If you modify file(s)
// with this exception, you may extend this exception to your version
// of the file(s), but you are not obligated to do so. If you do not
// wish to do so, delete this exception statement from your version.
// If you delete this exception statement from all source files in the
// program, then also delete it here.
//
// Contact: Jari Sundell <jaris@ifi.uio.no>
//
// Skomakerveien 33
// 3185 Skoppum, NORWAY
// This is a hacked up whole string pattern matching. Replace with
// TR1's regex when that becomes widely available. It is intended for
// small strings.
#ifndef RAK_REGEX_H
#define RAK_REGEX_H
#include <sys/types.h>
#include <functional>
#include <string>
#include <list>
namespace rak {
class regex : public std::unary_function<std::string, bool> {
public:
regex() {}
regex(const std::string& p) : m_pattern(p) {}
const std::string& pattern() const { return m_pattern; }
bool operator () (const std::string& p) const;
private:
std::string m_pattern;
};
// This isn't optimized, or very clean. A simple hack that should work.
bool
regex::operator () (const std::string& text) const {
if (m_pattern.empty() ||
text.empty() ||
(m_pattern[0] != '*' && m_pattern[0] != text[0]))
return false;
// Replace with unordered_vector?
std::list<unsigned int> paths;
paths.push_front(0);
for (std::string::const_iterator itrText = ++text.begin(), lastText = text.end(); itrText != lastText; ++itrText) {
for (std::list<unsigned int>::iterator itrPaths = paths.begin(), lastPaths = paths.end(); itrPaths != lastPaths; ) {
unsigned int next = *itrPaths + 1;
if (m_pattern[*itrPaths] != '*')
itrPaths = paths.erase(itrPaths);
else
itrPaths++;
// When we reach the end of 'm_pattern', we don't have a whole
// match of 'text'.
if (next == m_pattern.size())
continue;
// Push to the back so that '*' will match zero length strings.
if (m_pattern[next] == '*')
paths.push_back(next);
if (m_pattern[next] == *itrText)
paths.push_front(next);
}
if (paths.empty())
return false;
}
return std::find(paths.begin(), paths.end(), m_pattern.size() - 1) != paths.end();
}
}
#endif
+9
View File
@@ -36,6 +36,7 @@
#include "config.h"
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <stdexcept>
@@ -183,6 +184,14 @@ DownloadFactory::receive_success() {
(*itr)->variable()->set("max_peers", control->variable()->get("max_peers"));
(*itr)->variable()->set("max_uploads", control->variable()->get("max_uploads"));
if (rtorrent->has_key_value("key")) {
(*itr)->tracker_list()->set_key(rtorrent->get_key("key").as_value());
} else {
(*itr)->tracker_list()->set_key(rand() % (std::numeric_limits<uint32_t>::max() - 1) + 1);
rtorrent->insert_key("key", (*itr)->tracker_list()->key());
}
if (control->variable()->get_string("use_udp_trackers") == "no")
(*itr)->enable_udp_trackers(false);
+7 -9
View File
@@ -61,25 +61,23 @@ WindowTrackerList::redraw() {
m_canvas->erase();
int pos = 0;
torrent::TrackerList* tl = m_download->tracker_list();
m_canvas->print( 2, pos, "Trackers:");
m_canvas->print(2, pos, "Trackers: [Key: %08x]", tl->key());
++pos;
torrent::TrackerList tl = m_download->download()->tracker_list();
if (tl.size() == 0)
if (tl->size() == 0)
return;
if (*m_focus >= tl.size())
if (*m_focus >= tl->size())
throw std::logic_error("WindowTrackerList::redraw() called on an object with a bad focus value.");
typedef std::pair<unsigned int, unsigned int> Range;
Range range = rak::advance_bidirectional<unsigned int>(0, *m_focus, tl.size(), (m_canvas->get_height() + 1) / 2);
Range range = rak::advance_bidirectional<unsigned int>(0, *m_focus, tl->size(), (m_canvas->get_height() + 1) / 2);
while (range.first != range.second) {
torrent::Tracker t = tl.get(range.first);
torrent::Tracker t = tl->get(range.first);
m_canvas->print(0, pos++, "%c %s",
range.first == *m_focus ? '*' : ' ',
@@ -89,7 +87,7 @@ WindowTrackerList::redraw() {
range.first == *m_focus ? '*' : ' ',
t.group(),
rak::copy_escape_html(t.tracker_id()).c_str(),
range.first == tl.focus() ? "yes" : " no",
range.first == tl->focus() ? "yes" : " no",
t.is_enabled() ? "yes" : " no",
t.is_open() ? "yes" : " no",
t.scrape_complete(),