From e003bb8ad57e333d571da1c468725abfb70705a9 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 6 Jul 2005 00:58:23 +0000 Subject: [PATCH] added ip filters and fixed torrent_info::create_torrent() --- Jamfile | 7 +- docs/manual.html | 586 ++++++++++++++++++++-------- docs/manual.rst | 342 ++++++++++++++-- examples/client_test.cpp | 51 ++- examples/make_torrent.cpp | 2 +- include/libtorrent/ip_filter.hpp | 77 ++++ include/libtorrent/session.hpp | 7 +- include/libtorrent/socket.hpp | 2 + include/libtorrent/torrent_info.hpp | 4 +- src/session.cpp | 32 +- src/torrent.cpp | 62 ++- src/torrent_info.cpp | 9 +- 12 files changed, 934 insertions(+), 247 deletions(-) create mode 100644 include/libtorrent/ip_filter.hpp diff --git a/Jamfile b/Jamfile index f92e62222..25b683dbd 100755 --- a/Jamfile +++ b/Jamfile @@ -52,6 +52,7 @@ SOURCES = escape_string.cpp file.cpp identify_client.cpp + ip_filter.cpp peer_connection.cpp piece_picker.cpp policy.cpp @@ -93,8 +94,10 @@ LIBS = ; LIBS += wsock32 ; } -variant release_log : release : TORRENT_VERBOSE_LOGGING ; -variant debug_log : debug : TORRENT_VERBOSE_LOGGING ; +variant release_vlog : release : TORRENT_VERBOSE_LOGGING ; +variant release_log : release : TORRENT_LOGGING ; +variant debug_vlog : debug : TORRENT_VERBOSE_LOGGING ; +variant debug_log : debug : TORRENT_LOGGING ; lib torrent diff --git a/docs/manual.html b/docs/manual.html index 1505e11b8..7d564f802 100755 --- a/docs/manual.html +++ b/docs/manual.html @@ -22,115 +22,126 @@ +
+

set_comment() set_piece_size() set_creator() set_hash() add_tracker() add_file()

+
+
+void set_comment(char const* str);
+void set_piece_size(int size);
+void set_creator(char const* str);
+void set_hash(int index, sha1_hash const& h);
+void add_tracker(std::string const& url, int tier = 0);
+void add_file(boost::filesystem::path file, size_type size);
+
+
+

These files are used when creating a torrent file. set_comment() will simply set +the comment that belongs to this torrent. The comment can be retrieved with the +comment() member.

+

set_piece_size() will set the size of each piece in this torrent. The piece size must +be an even multiple of 2. i.e. usually something like 256 kB, 512 kB, 1024 kB etc. The +size is given in number of bytes.

+

set_creator() is an optional attribute that can be used to identify your application +that was used to create the torrent file.

+

set_hash() writes the hash for the piece with the given piece-index. You have to call +this function for every piece in the torrent. Usually the hasher is used to calculate +the sha1-hash for a piece.

+

add_tracker() adds a tracker to the announce-list. The tier determines the order in +which the trackers are to be tried. For more iformation see trackers().

+

add_file() adds a file to the torrent. The order in which you add files will determine +the order in which they are placed in the torrent file. You have to add at least one file +to the torrent. The path you give has to be a relative path from the root directory +of the torrent. The size is given in bytes.

+

When you have added all the files and hashes to your torrent, you can generate an entry +which then can be encoded as a .torrent file. You do this by calling create_torrent().

+

For a complete example of how to create a torrent from a file structure, see make_torrent.

+
+
+

create_torrent()

+
+
+entry create_torrent();
+
+
+

Returns an entry representing the bencoded tree of data that makes up a .torrent file. +You can save this data as a torrent file with bencode() (see bdecode() bencode()), for a +complete example, see make_torrent.

+

This function is not const because it will also set the info-hash of the torrent_info +object.

+

begin_files() end_files() rbegin_files() rend_files()

@@ -761,7 +872,7 @@ struct file_entry
 int num_files() const;
-const file_entry& file_at(int index) const;
+file_entry const& file_at(int index) const;
 

If you need index-access to files you can use the num_files() and file_at() @@ -781,7 +892,7 @@ the torrent file to the given outstream.

trackers()

-const std::vector<announce_entry>& trackers() const;
+std::vector<announce_entry> const& trackers() const;
 

The trackers() function will return a sorted vector of announce_entry. @@ -820,7 +931,7 @@ be smaller.

 size_type piece_size(unsigned int index) const;
-const sha1_hash& hash_for_piece(unsigned int index) const;
+sha1_hash const& hash_for_piece(unsigned int index) const;
 

hash_for_piece() takes a piece-index and returns the 20-bytes sha1-hash for that @@ -831,8 +942,8 @@ torrent file. For more information on the name() comment() creation_date()

-const std::stirng& name() const;
-const std::string& comment() const;
+std::string const& name() const;
+std::string const& comment() const;
 boost::optional<boost::posix_time::ptime> creation_date() const;
 
@@ -886,6 +997,8 @@ struct torrent_handle bool is_piece_filtered(int index) const; std::vector<bool> filtered_pieces() const; + void filter_files(std::vector<bool> const& files); + bool has_metadata() const; boost::filsystem::path save_path() const; @@ -893,17 +1006,16 @@ struct torrent_handle sha1_hash info_hash() const; - bool operator==(const torrent_handle&) const; - bool operator!=(const torrent_handle&) const; - bool operator<(const torrent_handle&) const; + bool operator==(torrent_handle const&) const; + bool operator!=(torrent_handle const&) const; + bool operator<(torrent_handle const&) const; };

The default constructor will initialize the handle to an invalid state. Which means you cannot perform any operation on it, unless you first assign it a valid handle. If you try to perform any operation on an uninitialized handle, it will throw invalid_handle.

TODO: document trackers() and replace_trackers()

-

TODO: document how to create a .torrent

-

TODO: document filter_piece(), filter_pieces(), is_piece_filtered() and filtered_pieces()

+

TODO: document filter_piece(), filter_pieces(), is_piece_filtered(), filtered_pieces() and filter_files()