From 00a36608b9fce42ba6da886f6402eafb4fbee4e6 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 28 Dec 2017 22:12:40 +0100 Subject: [PATCH 1/7] fix some typos --- include/libtorrent/session_handle.hpp | 2 +- include/libtorrent/torrent.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/session_handle.hpp b/include/libtorrent/session_handle.hpp index e11d28ff1..0f726113f 100644 --- a/include/libtorrent/session_handle.hpp +++ b/include/libtorrent/session_handle.hpp @@ -678,7 +678,7 @@ namespace libtorrent // class and returns a unique identifier. // // Identifiers are assigned from low numbers to higher. So if you plan on - // using certain peer classes in a call to `set_peer_class_filter()`_, + // using certain peer classes in a call to set_peer_class_filter(), // make sure to create those early on, to get low identifiers. // // For more information on peer classes, see peer-classes_. diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 857792591..965eab326 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -1610,7 +1610,7 @@ namespace libtorrent // the number of bytes of padding files boost::uint32_t m_padding:24; - // TODO: 8 bits available here + // TODO: gap of 8 bits available here // ---- From edb5674d5cd850b933792582ab2cbb09671a6b47 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 28 Dec 2017 23:55:06 +0100 Subject: [PATCH 2/7] Revert "Autotools: Check if std::chrono and std::random are available." This reverts commit d93869ff3bfc0fd659b11cb66b21ad540f34c43b. --- configure.ac | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/configure.ac b/configure.ac index 8ba99812e..0a8defa40 100644 --- a/configure.ac +++ b/configure.ac @@ -123,27 +123,17 @@ AX_BOOST_SYSTEM() AS_IF([test -z "$BOOST_SYSTEM_LIB"], [AC_MSG_ERROR(Boost.System library not found. Try using --with-boost-system=lib)]) -AC_LANG_PUSH([C++]) -AC_CHECK_HEADERS([chrono]) -AC_CHECK_HEADERS([random]) -AC_LANG_POP +AX_BOOST_CHRONO() +AS_IF([test -z "$BOOST_CHRONO_LIB"], + [AC_MSG_ERROR(Boost.Chrono library not found. Try using --with-boost-chrono=lib)]) -AS_IF([test "x$ac_cv_header_chrono" = "xno"], - [AX_BOOST_CHRONO() - AS_IF([test -z "$BOOST_CHRONO_LIB"], - [AC_MSG_ERROR(Boost.Chrono library not found. Try using --with-boost-chrono=lib)]) - LIBS="$BOOST_CHRONO_LIB $LIBS" - ]) - -AS_IF([test "x$ac_cv_header_random" = "xno"], - [AX_BOOST_RANDOM() - AS_IF([test -z "$BOOST_RANDOM_LIB"], - [AC_MSG_ERROR(Boost.Random library not found. Try using --with-boost-random=lib)]) - LIBS="$BOOST_RANDOM_LIB $LIBS" - ]) +AX_BOOST_RANDOM() +AS_IF([test -z "$BOOST_RANDOM_LIB"], + [AC_MSG_ERROR(Boost.Random library not found. Try using --with-boost-random=lib)]) CPPFLAGS="$BOOST_CPPFLAGS $CPPFLAGS" LDFLAGS="$BOOST_LDFLAGS $LDFLAGS" +LIBS="$BOOST_CHRONO_LIB $BOOST_RANDOM_LIB $LIBS" ############################################################################### # Checking for functions and other stuffs @@ -652,19 +642,9 @@ Boost libraries: CPPFlags: ${BOOST_CPPFLAGS} LDFlags: ${BOOST_LDFLAGS} boost.system: ${BOOST_SYSTEM_LIB} -END - -AS_IF([test "x$ac_cv_header_chrono" = "xno"], [ -cat >> config.report << END boost.chrono: ${BOOST_CHRONO_LIB} -END -]) - -AS_IF([test "x$ac_cv_header_random" = "xno"], [ -cat >> config.report << END boost.random: ${BOOST_RANDOM_LIB} END -]) AS_IF([test "x$ARG_ENABLE_PYTHON_BINDING" = "xyes"], [ cat >> config.report << END From a46bd839f0a31a5c521131183376be0a72233bd3 Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 28 Dec 2017 23:56:17 +0100 Subject: [PATCH 3/7] clean makefile dependency directory in clean.py script --- tools/clean.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/clean.py b/tools/clean.py index 4d97c51b4..83df9d346 100755 --- a/tools/clean.py +++ b/tools/clean.py @@ -13,6 +13,7 @@ def clean(): 'upnp.log', 'natpmp.log', 'bin', + '.deps', 'test_tmp_*', 'bjam_build.*.xml' '*.exe', From 473b86a8e621c5f22f4e5b6afd8c733cb5300fb1 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 29 Dec 2017 10:50:48 +0100 Subject: [PATCH 4/7] cleanup tarball build script --- build_dist.sh | 20 +++++--------------- tools/clean.py | 6 ++++++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/build_dist.sh b/build_dist.sh index 8269755c4..a03cbe4e2 100755 --- a/build_dist.sh +++ b/build_dist.sh @@ -1,25 +1,15 @@ #!/bin/sh -make clean +set -e +set -x + +python tools/clean.py cd docs -make clean -make RST2HTML=rst2html.py +make RST2HTML=rst2html-2.7.py cd .. -#clear out any extended attributes that Finder may add -sudo xattr -r -d com.apple.FinderInfo * - -rm -f config.log config.report configure rm -f m4/libtool.m4 m4/lt~obsolete.m4 m4/ltsugar.m4 m4/ltversion.m4 m4/ltoptions.m4 -rm -fr autom4te.cache build-aux -rm -f Makefile Makefile.in -rm -f src/Makefile src/Makefile.in -rm -f include/libtorrent/Makefile include/libtorrent/Makefile.in -rm -f examples/Makefile examples/Makefile.in examples/.dep examples/.libs -rm -rf test/Makefile test/Makefile.in test/.dep test/.lib -rm -rf bindings/Makefile bindings/Makefile.in bindings/.dep bindings/.libs -rm -f bindings/python/Makefile bindings/python/Makefile.in chmod a-x docs/*.rst docs/*.htm* src/*.cpp include/libtorrent/*.hpp ./autotool.sh diff --git a/tools/clean.py b/tools/clean.py index 83df9d346..33677da11 100755 --- a/tools/clean.py +++ b/tools/clean.py @@ -13,6 +13,7 @@ def clean(): 'upnp.log', 'natpmp.log', 'bin', + 'build-aux', '.deps', 'test_tmp_*', 'bjam_build.*.xml' @@ -33,6 +34,11 @@ def clean(): 'lib*.a', 'Jamfile.rej', 'Jamfile.orig', + 'autom4te.cache', + 'configure', + 'config.report', + 'config.log', + '.lib', ] directories = [ From c8bf782bd002a039b362eecea14d1f4389bba714 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 29 Dec 2017 10:51:58 +0100 Subject: [PATCH 5/7] bump version number to 1.1.6 --- CMakeLists.txt | 2 +- ChangeLog | 2 ++ Jamfile | 2 +- bindings/python/setup.py | 2 +- configure.ac | 2 +- docs/building.rst | 2 +- docs/contributing.rst | 2 +- docs/dht_rss.rst | 2 +- docs/dht_sec.rst | 2 +- docs/dht_store.rst | 2 +- docs/examples.rst | 2 +- docs/features.rst | 2 +- docs/gen_reference_doc.py | 2 +- docs/hacking.rst | 2 +- docs/index.rst | 2 +- docs/manual.rst | 2 +- docs/troubleshooting.rst | 2 +- docs/tuning.rst | 2 +- docs/tutorial.rst | 2 +- docs/utp.rst | 2 +- include/libtorrent/version.hpp | 6 +++--- src/settings_pack.cpp | 2 +- 22 files changed, 25 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7548e8e80..ad95c5277 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 2.6) project(libtorrent) set (SOVERSION "8") -set (VERSION "1.1.5") +set (VERSION "1.1.6") set(sources web_connection_base diff --git a/ChangeLog b/ChangeLog index 3d0f991e6..c2bd5c25b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ +1.1.6 release + * deprecate save_encryption_settings (they are part of the normal settings) * add getters for peer_class_filter and peer_class_type_filter * make torrent_handler::set_priority() to use peer_classes diff --git a/Jamfile b/Jamfile index bf7b595d7..ceeda7d9e 100644 --- a/Jamfile +++ b/Jamfile @@ -57,7 +57,7 @@ else : : $(boost-include-path) ; } -VERSION = 1.1.5 ; +VERSION = 1.1.6 ; rule linking ( properties * ) { diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 049215c04..482776ecf 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -133,7 +133,7 @@ else: libraries = ['torrent-rasterbar'] + flags.libraries)] setup(name = 'python-libtorrent', - version = '1.1.5', + version = '1.1.6', author = 'Arvid Norberg', author_email = 'arvid@libtorrent.org', description = 'Python bindings for libtorrent-rasterbar', diff --git a/configure.ac b/configure.ac index 0a8defa40..a64d21b63 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ AC_PREREQ([2.63]) -AC_INIT([libtorrent-rasterbar],[1.1.5],[arvid@libtorrent.org], +AC_INIT([libtorrent-rasterbar],[1.1.6],[arvid@libtorrent.org], [libtorrent-rasterbar],[http://www.libtorrent.org]) AC_CONFIG_SRCDIR([src/torrent.cpp]) AC_CONFIG_AUX_DIR([build-aux]) diff --git a/docs/building.rst b/docs/building.rst index 820eeabb8..c2a3e7549 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -3,7 +3,7 @@ libtorrent manual ================= :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/contributing.rst b/docs/contributing.rst index 5999c775d..ad4f446ee 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -3,7 +3,7 @@ libtorrent manual ================= :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/dht_rss.rst b/docs/dht_rss.rst index ef10897af..e82715691 100644 --- a/docs/dht_rss.rst +++ b/docs/dht_rss.rst @@ -3,7 +3,7 @@ BitTorrent extension for DHT RSS feeds ====================================== :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/dht_sec.rst b/docs/dht_sec.rst index 019fe07f2..86e858e94 100644 --- a/docs/dht_sec.rst +++ b/docs/dht_sec.rst @@ -3,7 +3,7 @@ BitTorrent DHT security extension ================================= :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/dht_store.rst b/docs/dht_store.rst index 264a7fe35..bae89928a 100644 --- a/docs/dht_store.rst +++ b/docs/dht_store.rst @@ -3,7 +3,7 @@ BitTorrent extension for arbitrary DHT store ============================================ :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/examples.rst b/docs/examples.rst index 3e3dcefc9..9b7764a3d 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -3,7 +3,7 @@ libtorrent Examples =================== :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/features.rst b/docs/features.rst index 67e49a8e2..de504e1a7 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -3,7 +3,7 @@ libtorrent manual ================= :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/gen_reference_doc.py b/docs/gen_reference_doc.py index 3f48a10ef..45063f6cc 100644 --- a/docs/gen_reference_doc.py +++ b/docs/gen_reference_doc.py @@ -1027,7 +1027,7 @@ for cat in categories: out.write(''' :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 `home`__ diff --git a/docs/hacking.rst b/docs/hacking.rst index bea76b780..ffde08d56 100644 --- a/docs/hacking.rst +++ b/docs/hacking.rst @@ -3,7 +3,7 @@ libtorrent hacking ================== :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/index.rst b/docs/index.rst index b80f41637..aa76a2005 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,5 +1,5 @@ :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. raw:: html diff --git a/docs/manual.rst b/docs/manual.rst index 282850f17..a1e82afcf 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3,7 +3,7 @@ libtorrent API Documentation ============================ :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 1 diff --git a/docs/troubleshooting.rst b/docs/troubleshooting.rst index bc975bbd0..29f5469cb 100644 --- a/docs/troubleshooting.rst +++ b/docs/troubleshooting.rst @@ -3,7 +3,7 @@ libtorrent manual ================= :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/tuning.rst b/docs/tuning.rst index 8c4f52b0d..c4aabf8f7 100644 --- a/docs/tuning.rst +++ b/docs/tuning.rst @@ -3,7 +3,7 @@ libtorrent manual ================= :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/tutorial.rst b/docs/tutorial.rst index 535865ce9..d18a5c757 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -3,7 +3,7 @@ libtorrent manual ================= :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/docs/utp.rst b/docs/utp.rst index 656c1f812..d8b6649ee 100644 --- a/docs/utp.rst +++ b/docs/utp.rst @@ -3,7 +3,7 @@ libtorrent manual ================= :Author: Arvid Norberg, arvid@libtorrent.org -:Version: 1.1.5 +:Version: 1.1.6 .. contents:: Table of contents :depth: 2 diff --git a/include/libtorrent/version.hpp b/include/libtorrent/version.hpp index c2cea0b1c..e386311ca 100644 --- a/include/libtorrent/version.hpp +++ b/include/libtorrent/version.hpp @@ -37,14 +37,14 @@ POSSIBILITY OF SUCH DAMAGE. #define LIBTORRENT_VERSION_MAJOR 1 #define LIBTORRENT_VERSION_MINOR 1 -#define LIBTORRENT_VERSION_TINY 5 +#define LIBTORRENT_VERSION_TINY 6 // the format of this version is: MMmmtt // M = Major version, m = minor version, t = tiny version #define LIBTORRENT_VERSION_NUM ((LIBTORRENT_VERSION_MAJOR * 10000) + (LIBTORRENT_VERSION_MINOR * 100) + LIBTORRENT_VERSION_TINY) -#define LIBTORRENT_VERSION "1.1.5.0" -#define LIBTORRENT_REVISION "37ffe99a1" +#define LIBTORRENT_VERSION "1.1.6.0" +#define LIBTORRENT_REVISION "473b86a" namespace libtorrent { diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 036da6665..0b2a28ec9 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -148,7 +148,7 @@ namespace libtorrent SET_NOPREV(proxy_username, "", &session_impl::update_proxy), SET_NOPREV(proxy_password, "", &session_impl::update_proxy), SET_NOPREV(i2p_hostname, "", &session_impl::update_i2p_bridge), - SET_NOPREV(peer_fingerprint, "-LT1150-", &session_impl::update_peer_fingerprint), + SET_NOPREV(peer_fingerprint, "-LT1160-", &session_impl::update_peer_fingerprint), SET_NOPREV(dht_bootstrap_nodes, "dht.libtorrent.org:25401", &session_impl::update_dht_bootstrap_nodes) }; From 4565a2f3752446bcc9ec07c82e42154d16668488 Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 29 Dec 2017 20:03:40 +0100 Subject: [PATCH 6/7] update documentation --- docs/features.rst | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/features.rst b/docs/features.rst index de504e1a7..472807413 100644 --- a/docs/features.rst +++ b/docs/features.rst @@ -290,11 +290,8 @@ code to implement a simple bittorrent client:: // usage a.out [torrent-file] int main(int argc, char* argv[]) try { - using namespace libtorrent; - - session s; - s.listen_on(std::make_pair(6881, 6889)); - add_torrent_params p; + lt::session s; + lt::add_torrent_params p; p.save_path = "./"; p.ti = new torrent_info(argv[1]); s.add_torrent(p); @@ -322,10 +319,10 @@ portability libtorrent runs on most major operating systems, including Windows, MacOS X, Linux, BSD and Solaris. -It uses Boost.Thread, Boost.Filesystem, Boost.Date_time and various other -boost libraries. At least version 1.46.1 of boost is required. +It uses Boost.Thread, Boost.Asio, Boost.Chrono, Boost.Random, Boost.Date_time +and various other boost libraries. At least version 1.49 of boost is required. -libtorrent uses asio, hence it will take full advantage of high performance +Since libtorrent uses Boost.Asio it will take full advantage of high performance network APIs on the most popular platforms. I/O completion ports on windows, epoll on linux and kqueue on MacOS X and BSD. From d427572247f2e252a4de236bbb0c971ea75e234b Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 29 Dec 2017 21:36:22 +0100 Subject: [PATCH 7/7] cleanup examples a bit --- examples/dump_torrent.cpp | 147 +++++---------- examples/make_torrent.cpp | 361 +++++++++++++++++-------------------- examples/simple_client.cpp | 37 ++-- 3 files changed, 219 insertions(+), 326 deletions(-) diff --git a/examples/dump_torrent.cpp b/examples/dump_torrent.cpp index fa1b155d0..4f67c83ad 100644 --- a/examples/dump_torrent.cpp +++ b/examples/dump_torrent.cpp @@ -1,6 +1,6 @@ /* -Copyright (c) 2003, Arvid Norberg +Copyright (c) 2003-2017, Arvid Norberg All rights reserved. Redistribution and use in source and binary forms, with or without @@ -37,74 +37,25 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/bdecode.hpp" #include "libtorrent/magnet_uri.hpp" -int load_file(std::string const& filename, std::vector& v - , libtorrent::error_code& ec, int limit = 8000000) +#include + +std::vector load_file(std::string const& filename) { - ec.clear(); - FILE* f = fopen(filename.c_str(), "rb"); - if (f == NULL) - { - ec.assign(errno, boost::system::system_category()); - return -1; - } - - int r = fseek(f, 0, SEEK_END); - if (r != 0) - { - ec.assign(errno, boost::system::system_category()); - fclose(f); - return -1; - } - long s = ftell(f); - if (s < 0) - { - ec.assign(errno, boost::system::system_category()); - fclose(f); - return -1; - } - - if (s > limit) - { - fclose(f); - return -2; - } - - r = fseek(f, 0, SEEK_SET); - if (r != 0) - { - ec.assign(errno, boost::system::system_category()); - fclose(f); - return -1; - } - - v.resize(s); - if (s == 0) - { - fclose(f); - return 0; - } - - r = fread(&v[0], 1, v.size(), f); - if (r < 0) - { - ec.assign(errno, boost::system::system_category()); - fclose(f); - return -1; - } - - fclose(f); - - if (r != s) return -3; - - return 0; + std::vector ret; + std::fstream in; + in.exceptions(std::ifstream::failbit); + in.open(filename.c_str(), std::ios_base::in | std::ios_base::binary); + in.seekg(0, std::ios_base::end); + size_t const size = in.tellg(); + in.seekg(0, std::ios_base::beg); + ret.resize(size); + in.read(ret.data(), ret.size()); + return ret; } -int main(int argc, char* argv[]) +int main(int argc, char* argv[]) try { - using namespace libtorrent; - - if (argc < 2 || argc > 4) - { + if (argc < 2 || argc > 4) { fputs("usage: dump_torrent torrent-file [total-items-limit] [recursion-limit]\n", stderr); return 1; } @@ -115,41 +66,23 @@ int main(int argc, char* argv[]) if (argc > 2) item_limit = atoi(argv[2]); if (argc > 3) depth_limit = atoi(argv[3]); - std::vector buf; - error_code ec; - int ret = load_file(argv[1], buf, ec, 40 * 1000000); - if (ret == -1) - { - fprintf(stderr, "file too big, aborting\n"); - return 1; - } - - if (ret != 0) - { - fprintf(stderr, "failed to load file: %s\n", ec.message().c_str()); - return 1; - } - bdecode_node e; + std::vector buf = load_file(argv[1]); + lt::bdecode_node e; int pos = -1; - printf("decoding. recursion limit: %d total item count limit: %d\n" - , depth_limit, item_limit); - ret = bdecode(&buf[0], &buf[0] + buf.size(), e, ec, &pos + lt::error_code ec; + std::cout << "decoding. recursion limit: " << depth_limit + << " total item count limit: " << item_limit << "\n"; + int const ret = lt::bdecode(&buf[0], &buf[0] + buf.size(), e, ec, &pos , depth_limit, item_limit); printf("\n\n----- raw info -----\n\n%s\n", print_entry(e).c_str()); - if (ret != 0) - { - fprintf(stderr, "failed to decode: '%s' at character: %d\n", ec.message().c_str(), pos); + if (ret != 0) { + std::cerr << "failed to decode: '" << ec.message() << "' at character: " << pos<< "\n"; return 1; } - torrent_info t(e, ec); - if (ec) - { - fprintf(stderr, "%s\n", ec.message().c_str()); - return 1; - } + lt::torrent_info const t(e); e.clear(); std::vector().swap(buf); @@ -165,14 +98,14 @@ int main(int argc, char* argv[]) printf("%s: %d\n", i->first.c_str(), i->second); } puts("trackers:\n"); - for (std::vector::const_iterator i = t.trackers().begin(); + for (std::vector::const_iterator i = t.trackers().begin(); i != t.trackers().end(); ++i) { printf("%2d: %s\n", i->tier, i->url.c_str()); } char ih[41]; - to_hex((char const*)&t.info_hash()[0], 20, ih); + lt::to_hex(t.info_hash().data(), 20, ih); printf("number of pieces: %d\n" "piece length: %d\n" "info hash: %s\n" @@ -190,27 +123,31 @@ int main(int argc, char* argv[]) , make_magnet_uri(t).c_str() , t.name().c_str() , t.num_files()); - file_storage const& st = t.files(); + lt::file_storage const& st = t.files(); for (int i = 0; i < st.num_files(); ++i) { - int first = st.map_file(i, 0, 0).piece; - int last = st.map_file(i, (std::max)(boost::int64_t(st.file_size(i))-1, boost::int64_t(0)), 0).piece; - int flags = st.file_flags(i); + int const first = st.map_file(i, 0, 0).piece; + int const last = st.map_file(i, (std::max)(boost::int64_t(st.file_size(i))-1, boost::int64_t(0)), 0).piece; + int const flags = st.file_flags(i); printf(" %8" PRIx64 " %11" PRId64 " %c%c%c%c [ %5d, %5d ] %7u %s %s %s%s\n" , st.file_offset(i) , st.file_size(i) - , ((flags & file_storage::flag_pad_file)?'p':'-') - , ((flags & file_storage::flag_executable)?'x':'-') - , ((flags & file_storage::flag_hidden)?'h':'-') - , ((flags & file_storage::flag_symlink)?'l':'-') + , ((flags & lt::file_storage::flag_pad_file)?'p':'-') + , ((flags & lt::file_storage::flag_executable)?'x':'-') + , ((flags & lt::file_storage::flag_hidden)?'h':'-') + , ((flags & lt::file_storage::flag_symlink)?'l':'-') , first, last , boost::uint32_t(st.mtime(i)) - , st.hash(i) != sha1_hash(0) ? to_hex(st.hash(i).to_string()).c_str() : "" + , st.hash(i) != lt::sha1_hash(0) ? lt::to_hex(st.hash(i).to_string()).c_str() : "" , st.file_path(i).c_str() - , (flags & file_storage::flag_symlink) ? "-> " : "" - , (flags & file_storage::flag_symlink) ? st.symlink(i).c_str() : ""); + , (flags & lt::file_storage::flag_symlink) ? "-> " : "" + , (flags & lt::file_storage::flag_symlink) ? st.symlink(i).c_str() : ""); } return 0; } +catch (std::exception const& e) +{ + std::cerr << "ERROR: " << e.what() << "\n"; +} diff --git a/examples/make_torrent.cpp b/examples/make_torrent.cpp index d7c8aac9b..44a54e6de 100644 --- a/examples/make_torrent.cpp +++ b/examples/make_torrent.cpp @@ -1,6 +1,6 @@ /* -Copyright (c) 2006, Arvid Norberg +Copyright (c) 2006-2017, Arvid Norberg All rights reserved. Redistribution and use in source and binary forms, with or without @@ -48,8 +48,6 @@ POSSIBILITY OF SUCH DAMAGE. #include // for _getcwd #endif -using namespace libtorrent; - std::vector load_file(std::string const& filename) { std::vector ret; @@ -159,219 +157,188 @@ void print_usage() , stderr); } -int main(int argc, char* argv[]) +int main(int argc, char* argv[]) try { - using namespace libtorrent; - std::string creator_str = "libtorrent"; std::string comment_str; - if (argc < 2) - { + if (argc < 2) { print_usage(); return 1; } -#ifndef BOOST_NO_EXCEPTIONS - try - { -#endif - std::vector web_seeds; - std::vector trackers; - std::vector collections; - std::vector similar; - int pad_file_limit = -1; - int piece_size = 0; - int flags = 0; - std::string root_cert; + std::vector web_seeds; + std::vector trackers; + std::vector collections; + std::vector similar; + int pad_file_limit = -1; + int piece_size = 0; + int flags = 0; + std::string root_cert; - std::string outfile; - std::string merklefile; + std::string outfile; + std::string merklefile; #ifdef TORRENT_WINDOWS - // don't ever write binary data to the console on windows - // it will just be interpreted as text and corrupted - outfile = "a.torrent"; + // don't ever write binary data to the console on windows + // it will just be interpreted as text and corrupted + outfile = "a.torrent"; #endif - for (int i = 2; i < argc; ++i) - { - if (argv[i][0] != '-') - { - print_usage(); - return 1; - } + std::string full_path = argv[1]; + argv += 2; + argc -= 2; - switch (argv[i][1]) - { - case 'w': - ++i; - web_seeds.push_back(argv[i]); - break; - case 't': - ++i; - trackers.push_back(argv[i]); - break; - case 'M': - flags |= create_torrent::mutable_torrent_support; - pad_file_limit = 0x4000; - break; - case 'p': - ++i; - pad_file_limit = atoi(argv[i]); - flags |= create_torrent::optimize_alignment; - break; - case 's': - ++i; - piece_size = atoi(argv[i]); - break; - case 'm': - ++i; - merklefile = argv[i]; - flags |= create_torrent::merkle; - break; - case 'o': - ++i; - outfile = argv[i]; - break; - case 'l': - flags |= create_torrent::symlinks; - break; - case 'C': - ++i; - creator_str = argv[i]; - break; - case 'c': - ++i; - comment_str = argv[i]; - break; - case 'r': - ++i; - root_cert = argv[i]; - break; - case 'S': - { - ++i; - if (strlen(argv[i]) != 40) - { - fprintf(stderr, "invalid info-hash for -S. " - "Expected 40 hex characters\n"); - print_usage(); - return 1; - } - sha1_hash ih; - if (!from_hex(argv[i], 40, (char*)&ih[0])) - { - fprintf(stderr, "invalid info-hash for -S\n"); - print_usage(); - return 1; - } - similar.push_back(ih); - } - break; - case 'L': - ++i; - collections.push_back(argv[i]); - break; - default: + for (; argc > 0; --argc, ++argv) { + if (argv[0][0] != '-') { + print_usage(); + return 1; + } + + char const flag = argv[0][1]; + + switch (flag) + { + case 'M': + flags |= lt::create_torrent::mutable_torrent_support; + pad_file_limit = 0x4000; + continue; + case 'l': + flags |= lt::create_torrent::symlinks; + continue; + } + + if (argc < 2) { + print_usage(); + return 1; + } + + switch (flag) + { + case 'w': web_seeds.push_back(argv[1]); break; + case 't': trackers.push_back(argv[1]); break; + case 's': piece_size = atoi(argv[1]); break; + case 'o': outfile = argv[1]; break; + case 'C': creator_str = argv[1]; break; + case 'c': comment_str = argv[1]; break; + case 'r': root_cert = argv[1]; break; + case 'L': collections.push_back(argv[1]); break; + case 'p': + pad_file_limit = atoi(argv[1]); + flags |= lt::create_torrent::optimize_alignment; + break; + case 'm': + merklefile = argv[1]; + flags |= lt::create_torrent::merkle; + break; + case 'S': + { + if (strlen(argv[1]) != 40) + { + std::cerr << "invalid info-hash for -S. " + "Expected 40 hex characters\n"; print_usage(); return 1; - } + } + lt::sha1_hash ih; + if (!lt::from_hex(argv[1], 40, ih.data())) + { + std::cerr << "invalid info-hash for -S\n"; + print_usage(); + return 1; + } + similar.push_back(ih); + } + break; + default: + print_usage(); + return 1; } - - file_storage fs; - std::string full_path = argv[1]; -#ifdef TORRENT_WINDOWS - if (full_path[1] != ':') -#else - if (full_path[0] != '/') -#endif - { - char cwd[TORRENT_MAX_PATH]; -#ifdef TORRENT_WINDOWS - _getcwd(cwd, sizeof(cwd)); - full_path = cwd + ("\\" + full_path); -#else - getcwd(cwd, sizeof(cwd)); - full_path = cwd + ("/" + full_path); -#endif - } - - add_files(fs, full_path, file_filter, flags); - if (fs.num_files() == 0) - { - fputs("no files specified.\n", stderr); - return 1; - } - - create_torrent t(fs, piece_size, pad_file_limit, flags); - int tier = 0; - for (std::vector::iterator i = trackers.begin() - , end(trackers.end()); i != end; ++i, ++tier) - t.add_tracker(*i, tier); - - for (std::vector::iterator i = web_seeds.begin() - , end(web_seeds.end()); i != end; ++i) - t.add_url_seed(*i); - - for (std::vector::iterator i = collections.begin() - , end(collections.end()); i != end; ++i) - t.add_collection(*i); - - for (std::vector::iterator i = similar.begin() - , end(similar.end()); i != end; ++i) - t.add_similar_torrent(*i); - - error_code ec; - set_piece_hashes(t, branch_path(full_path) - , boost::bind(&print_progress, _1, t.num_pieces()), ec); - if (ec) - { - fprintf(stderr, "%s\n", ec.message().c_str()); - return 1; - } - - fprintf(stderr, "\n"); - t.set_creator(creator_str.c_str()); - if (!comment_str.empty()) - t.set_comment(comment_str.c_str()); - - if (!root_cert.empty()) - { - std::vector pem = load_file(root_cert); - t.set_root_cert(std::string(&pem[0], pem.size())); - } - - // create the torrent and print it to stdout - std::vector torrent; - bencode(back_inserter(torrent), t.generate()); - if (!outfile.empty()) - { - std::fstream out; - out.exceptions(std::ifstream::failbit); - out.open(outfile.c_str(), std::ios_base::out | std::ios_base::binary); - out.write(&torrent[0], torrent.size()); - } - else - { - fwrite(&torrent[0], 1, torrent.size(), stdout); - } - - if (!merklefile.empty()) - { - std::fstream merkle; - merkle.exceptions(std::ifstream::failbit); - merkle.open(merklefile.c_str(), std::ios_base::out | std::ios_base::binary); - merkle.write(reinterpret_cast(&t.merkle_tree()[0]), t.merkle_tree().size() * 20); - } - -#ifndef BOOST_NO_EXCEPTIONS + ++argv; + --argc; } - catch (std::exception& e) + + lt::file_storage fs; +#ifdef TORRENT_WINDOWS + if (full_path[1] != ':') +#else + if (full_path[0] != '/') +#endif { - fprintf(stderr, "%s\n", e.what()); - } + char cwd[TORRENT_MAX_PATH]; +#ifdef TORRENT_WINDOWS + _getcwd(cwd, sizeof(cwd)); + full_path = cwd + ("\\" + full_path); +#else + getcwd(cwd, sizeof(cwd)); + full_path = cwd + ("/" + full_path); #endif + } + lt::add_files(fs, full_path, file_filter, flags); + if (fs.num_files() == 0) { + std::cerr << "no files specified.\n"; + return 1; + } + + lt::create_torrent t(fs, piece_size, pad_file_limit, flags); + int tier = 0; + for (std::vector::iterator i = trackers.begin() + , end(trackers.end()); i != end; ++i, ++tier) + t.add_tracker(*i, tier); + + for (std::vector::iterator i = web_seeds.begin() + , end(web_seeds.end()); i != end; ++i) + t.add_url_seed(*i); + + for (std::vector::iterator i = collections.begin() + , end(collections.end()); i != end; ++i) + t.add_collection(*i); + + for (std::vector::iterator i = similar.begin() + , end(similar.end()); i != end; ++i) + t.add_similar_torrent(*i); + + lt::error_code ec; + set_piece_hashes(t, branch_path(full_path) + , boost::bind(&print_progress, _1, t.num_pieces()), ec); + if (ec) { + std::cerr << ec.message() << "\n"; + return 1; + } + + fprintf(stderr, "\n"); + t.set_creator(creator_str.c_str()); + if (!comment_str.empty()) { + t.set_comment(comment_str.c_str()); + } + + if (!root_cert.empty()) { + std::vector const pem = load_file(root_cert); + t.set_root_cert(std::string(&pem[0], pem.size())); + } + + // create the torrent and print it to stdout + std::vector torrent; + lt::bencode(back_inserter(torrent), t.generate()); + if (!outfile.empty()) { + std::fstream out; + out.exceptions(std::ifstream::failbit); + out.open(outfile.c_str(), std::ios_base::out | std::ios_base::binary); + out.write(&torrent[0], torrent.size()); + } + else { + std::cout.write(&torrent[0], torrent.size()); + } + + if (!merklefile.empty()) { + std::fstream merkle; + merkle.exceptions(std::ifstream::failbit); + merkle.open(merklefile.c_str(), std::ios_base::out | std::ios_base::binary); + merkle.write(reinterpret_cast(&t.merkle_tree()[0]), t.merkle_tree().size() * 20); + } return 0; } - +catch (std::exception& e) { + std::cerr << "ERROR: " << e.what() << "\n"; + return 1; +} diff --git a/examples/simple_client.cpp b/examples/simple_client.cpp index 9cb5466de..d7a3c7c03 100644 --- a/examples/simple_client.cpp +++ b/examples/simple_client.cpp @@ -1,6 +1,6 @@ /* -Copyright (c) 2003, Arvid Norberg +Copyright (c) 2003-2017, Arvid Norberg All rights reserved. Redistribution and use in source and binary forms, with or without @@ -37,40 +37,29 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/session.hpp" #include "libtorrent/torrent_info.hpp" -int main(int argc, char* argv[]) +int main(int argc, char* argv[]) try { - using namespace libtorrent; - namespace lt = libtorrent; - if (argc != 2) { - fputs("usage: ./simple_client torrent-file\n" - "to stop the client, press return.\n", stderr); + std::cerr << "usage: ./simple_client torrent-file\n" + "to stop the client, press return.\n"; return 1; } - settings_pack sett; - sett.set_str(settings_pack::listen_interfaces, "0.0.0.0:6881"); - lt::session s(sett); - add_torrent_params p; + lt::session s; + lt::add_torrent_params p; p.save_path = "./"; - error_code ec; - p.ti = boost::make_shared(std::string(argv[1]), boost::ref(ec), 0); - if (ec) - { - fprintf(stderr, "%s\n", ec.message().c_str()); - return 1; - } - s.add_torrent(p, ec); - if (ec) - { - fprintf(stderr, "%s\n", ec.message().c_str()); - return 1; - } + lt::error_code ec; + p.ti = boost::make_shared(std::string(argv[1]), 0); + s.add_torrent(p); // wait for the user to end char a; scanf("%c\n", &a); return 0; } +catch (std::exception const& e) +{ + std::cerr << "ERROR: " << e.what() << "\n"; +}