From 24b9101075f233582e3dbd8e9da512cb2d60334e Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 12 Jul 2014 06:20:16 +0000 Subject: [PATCH] merged changes from RC_1_0 --- CMakeLists.txt | 39 +++++++++++-------- Jamfile | 4 +- Makefile.am | 16 ++------ ed25519/src/{add_scalar.c => add_scalar.cpp} | 2 +- ed25519/src/{ed25519.h => ed25519.hpp} | 14 ++----- ed25519/src/{fe.c => fe.cpp} | 0 ed25519/src/{ge.c => ge.cpp} | 0 .../src/{key_exchange.c => key_exchange.cpp} | 5 ++- ed25519/src/{keypair.c => keypair.cpp} | 2 +- ed25519/src/{sc.c => sc.cpp} | 0 ed25519/src/{seed.c => seed.cpp} | 2 +- ed25519/src/{sha512.c => sha512.cpp} | 0 ed25519/src/{sign.c => sign.cpp} | 2 +- ed25519/src/{verify.c => verify.cpp} | 2 +- examples/connection_tester.cpp | 12 ++++-- src/Makefile.am | 20 +++++----- src/kademlia/item.cpp | 2 +- test/Makefile.am | 12 +----- test/test_transfer.cpp | 4 +- 19 files changed, 63 insertions(+), 75 deletions(-) rename ed25519/src/{add_scalar.c => add_scalar.cpp} (98%) rename ed25519/src/{ed25519.h => ed25519.hpp} (90%) rename ed25519/src/{fe.c => fe.cpp} (100%) rename ed25519/src/{ge.c => ge.cpp} (100%) rename ed25519/src/{key_exchange.c => key_exchange.cpp} (91%) rename ed25519/src/{keypair.c => keypair.cpp} (93%) rename ed25519/src/{sc.c => sc.cpp} (100%) rename ed25519/src/{seed.c => seed.cpp} (96%) rename ed25519/src/{sha512.c => sha512.cpp} (100%) rename ed25519/src/{sign.c => sign.cpp} (97%) rename ed25519/src/{verify.c => verify.cpp} (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa9961386..c48a3a27f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,8 +162,22 @@ if(UNIX) set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}") endif() +if (build_tests) + # this will make some internal functions available in the + # DLL interface, for the tests to access + add_definitions(-DTORRENT_EXPORT_EXTRA) +endif (build_tests) + if (encryption) - list(APPEND sources pe_crypto) + list(APPEND sources pe_crypto asio_ssl) + if(NOT DEFINED OPENSSL_INCLUDE_DIR OR NOT DEFINED OPENSSL_LIBRARIES) + FIND_PACKAGE(OpenSSL REQUIRED) + endif() + add_definitions(-DTORRENT_USE_OPENSSL) + include_directories(${OPENSSL_INCLUDE_DIR}) +else() + add_definitions(-DTORRENT_DISABLE_ENCRYPTION) + list(APPEND sources sha1) endif (encryption) if (logging) @@ -239,16 +253,7 @@ if (WIN32) endif() if (encryption) - if(NOT DEFINED OPENSSL_INCLUDE_DIR OR NOT DEFINED OPENSSL_LIBRARIES) - FIND_PACKAGE(OpenSSL REQUIRED) - endif() - add_definitions(-DTORRENT_USE_OPENSSL) - list(APPEND sources asio_ssl) - include_directories(${OPENSSL_INCLUDE_DIR}) target_link_libraries(torrent-rasterbar ${OPENSSL_LIBRARIES}) -else() - add_definitions(-DTORRENT_DISABLE_ENCRYPTION) - list(APPEND sources sha1) endif() if (NOT pool-allocators) @@ -355,8 +360,10 @@ endif() # === build tests === if(build_tests) - FILE(GLOB tests RELATIVE "${PROJECT_SOURCE_DIR}" "tests/*.cpp") - add_library(test_common STATIC test/main.cpp test/setup_transfer.cpp) + FILE(GLOB tests RELATIVE "${PROJECT_SOURCE_DIR}" "test/test_*.cpp") + add_library(test_common STATIC test/main.cpp test/setup_transfer.cpp + test/dht_server.cpp test/udp_tracker.cpp test/peer_server.cpp + test/web_seed_suite.cpp) enable_testing() foreach(s ${tests}) @@ -366,9 +373,9 @@ if(build_tests) add_test(${sn} ${s}) endforeach(s) - add_executable(test_upnp test/test_upnp.cpp) - target_link_libraries(test_upnp torrent-rasterbar) +# add_executable(test_upnp test/test_upnp.cpp) +# target_link_libraries(test_upnp torrent-rasterbar) - add_executable(test_natpmp test/test_natpmp.cpp) - target_link_libraries(test_natpmp torrent-rasterbar) +# add_executable(test_natpmp test/test_natpmp.cpp) +# target_link_libraries(test_natpmp torrent-rasterbar) endif() diff --git a/Jamfile b/Jamfile index 120660020..236627c7e 100755 --- a/Jamfile +++ b/Jamfile @@ -713,8 +713,8 @@ lib torrent on:src/kademlia/$(KADEMLIA_SOURCES).cpp logging:src/kademlia/$(KADEMLIA_SOURCES).cpp - on:ed25519/src/$(ED25519_SOURCES).c - logging:ed25519/src/$(ED25519_SOURCES).c + on:ed25519/src/$(ED25519_SOURCES).cpp + logging:ed25519/src/$(ED25519_SOURCES).cpp @building system:$(CXXFLAGS) diff --git a/Makefile.am b/Makefile.am index 01fd6ff35..5a85716c1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -130,24 +130,14 @@ DOCS_PAGES = \ ED25519_SOURCE = \ ed25519/readme.md \ - ed25519/test.c \ - ed25519/src/ed25519.h \ + ed25519/test.cpp \ + ed25519/src/ed25519.hpp \ ed25519/src/fe.h \ ed25519/src/fixedint.h \ ed25519/src/ge.h \ ed25519/src/precomp_data.h \ ed25519/src/sc.h \ - ed25519/src/sha512.h \ - ed25519/src/add_scalar.c \ - ed25519/src/fe.c \ - ed25519/src/ge.c \ - ed25519/src/key_exchange.c \ - ed25519/src/keypair.c \ - ed25519/src/sc.c \ - ed25519/src/seed.c \ - ed25519/src/sha512.c \ - ed25519/src/sign.c \ - ed25519/src/verify.c + ed25519/src/sha512.h EXTRA_DIST = \ Jamfile \ diff --git a/ed25519/src/add_scalar.c b/ed25519/src/add_scalar.cpp similarity index 98% rename from ed25519/src/add_scalar.c rename to ed25519/src/add_scalar.cpp index 262ec7251..33ab71b7c 100644 --- a/ed25519/src/add_scalar.c +++ b/ed25519/src/add_scalar.cpp @@ -1,4 +1,4 @@ -#include "ed25519.h" +#include "ed25519.hpp" #include "ge.h" #include "sc.h" diff --git a/ed25519/src/ed25519.h b/ed25519/src/ed25519.hpp similarity index 90% rename from ed25519/src/ed25519.h rename to ed25519/src/ed25519.hpp index 08af9de93..435e5bda4 100644 --- a/ed25519/src/ed25519.h +++ b/ed25519/src/ed25519.hpp @@ -1,7 +1,5 @@ -#ifndef ED25519_H -#define ED25519_H - -#include +#ifndef ED25519_HPP +#define ED25519_HPP #include "libtorrent/config.hpp" // for TORRENT_EXPORT @@ -15,9 +13,7 @@ enum ed25519_shared_secret_size = 32 }; -#ifdef __cplusplus extern "C" { -#endif #ifndef ED25519_NO_SEED int TORRENT_EXPORT ed25519_create_seed(unsigned char *seed); @@ -29,9 +25,7 @@ int TORRENT_EXPORT ed25519_verify(const unsigned char *signature, const unsigned void TORRENT_EXPORT ed25519_add_scalar(unsigned char *public_key, unsigned char *private_key, const unsigned char *scalar); void TORRENT_EXPORT ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key); - -#ifdef __cplusplus } -#endif -#endif +#endif // ED25519_HPP + diff --git a/ed25519/src/fe.c b/ed25519/src/fe.cpp similarity index 100% rename from ed25519/src/fe.c rename to ed25519/src/fe.cpp diff --git a/ed25519/src/ge.c b/ed25519/src/ge.cpp similarity index 100% rename from ed25519/src/ge.c rename to ed25519/src/ge.cpp diff --git a/ed25519/src/key_exchange.c b/ed25519/src/key_exchange.cpp similarity index 91% rename from ed25519/src/key_exchange.c rename to ed25519/src/key_exchange.cpp index abd75da2c..dbcf50331 100644 --- a/ed25519/src/key_exchange.c +++ b/ed25519/src/key_exchange.cpp @@ -1,7 +1,8 @@ -#include "ed25519.h" +#include "ed25519.hpp" #include "fe.h" -void ed25519_key_exchange(unsigned char *shared_secret, const unsigned char *public_key, const unsigned char *private_key) { +void ed25519_key_exchange(unsigned char *shared_secret + , const unsigned char *public_key, const unsigned char *private_key) { unsigned char e[32]; unsigned int i; diff --git a/ed25519/src/keypair.c b/ed25519/src/keypair.cpp similarity index 93% rename from ed25519/src/keypair.c rename to ed25519/src/keypair.cpp index dc1b8eccc..b5c2cf201 100644 --- a/ed25519/src/keypair.c +++ b/ed25519/src/keypair.cpp @@ -1,4 +1,4 @@ -#include "ed25519.h" +#include "ed25519.hpp" #include "sha512.h" #include "ge.h" diff --git a/ed25519/src/sc.c b/ed25519/src/sc.cpp similarity index 100% rename from ed25519/src/sc.c rename to ed25519/src/sc.cpp diff --git a/ed25519/src/seed.c b/ed25519/src/seed.cpp similarity index 96% rename from ed25519/src/seed.c rename to ed25519/src/seed.cpp index d2ccb0800..5759f5184 100644 --- a/ed25519/src/seed.c +++ b/ed25519/src/seed.cpp @@ -1,4 +1,4 @@ -#include "ed25519.h" +#include "ed25519.hpp" #ifndef ED25519_NO_SEED diff --git a/ed25519/src/sha512.c b/ed25519/src/sha512.cpp similarity index 100% rename from ed25519/src/sha512.c rename to ed25519/src/sha512.cpp diff --git a/ed25519/src/sign.c b/ed25519/src/sign.cpp similarity index 97% rename from ed25519/src/sign.c rename to ed25519/src/sign.cpp index 199a8393b..9dbc4d001 100644 --- a/ed25519/src/sign.c +++ b/ed25519/src/sign.cpp @@ -1,4 +1,4 @@ -#include "ed25519.h" +#include "ed25519.hpp" #include "sha512.h" #include "ge.h" #include "sc.h" diff --git a/ed25519/src/verify.c b/ed25519/src/verify.cpp similarity index 98% rename from ed25519/src/verify.c rename to ed25519/src/verify.cpp index 32f988edc..c50c989ec 100644 --- a/ed25519/src/verify.c +++ b/ed25519/src/verify.cpp @@ -1,4 +1,4 @@ -#include "ed25519.h" +#include "ed25519.hpp" #include "sha512.h" #include "ge.h" #include "sc.h" diff --git a/examples/connection_tester.cpp b/examples/connection_tester.cpp index 5592a3fad..589ce2829 100644 --- a/examples/connection_tester.cpp +++ b/examples/connection_tester.cpp @@ -665,7 +665,9 @@ void print_usage() " options for this command:\n" " -s the size of the torrent in megabytes\n" " -n the number of files in the test torrent\n" - " -t the file to save the .torrent file to\n\n" + " -t the file to save the .torrent file to\n" + " -T the name of the torrent (and directory\n" + " its files are saved in)\n\n" " gen-data generate the data file(s) for the test torrent\n" " options for this command:\n" " -t the torrent file that was previously generated\n" @@ -712,7 +714,8 @@ void hasher_thread(libtorrent::create_torrent* t, int start_piece, int end_piece } // size is in megabytes -void generate_torrent(std::vector& buf, int size, int num_files, char const* name) +void generate_torrent(std::vector& buf, int size, int num_files + , char const* torrent_name) { file_storage fs; // 1 MiB piece size @@ -726,7 +729,7 @@ void generate_torrent(std::vector& buf, int size, int num_files, char cons while (s > 0) { char b[100]; - snprintf(b, sizeof(b), "%s/stress_test%d", name, i); + snprintf(b, sizeof(b), "%s/stress_test%d", torrent_name, i); ++i; fs.add_file(b, (std::min)(s, size_type(file_size))); s -= file_size; @@ -860,7 +863,8 @@ int main(int argc, char* argv[]) std::string name = filename(torrent_file); name = name.substr(0, name.find_last_of('.')); printf("generating torrent: %s\n", name.c_str()); - generate_torrent(tmp, size ? size : 1024, num_files ? num_files : 1, name.c_str()); + generate_torrent(tmp, size ? size : 1024, num_files ? num_files : 1 + , name.c_str()); FILE* output = stdout; if (strcmp("-", torrent_file) != 0) diff --git a/src/Makefile.am b/src/Makefile.am index 41d25c175..d50a26cb2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,16 +17,16 @@ KADEMLIA_SOURCES = \ kademlia/get_peers.cpp \ kademlia/get_item.cpp \ kademlia/item.cpp \ - ../ed25519/src/add_scalar.c \ - ../ed25519/src/fe.c \ - ../ed25519/src/ge.c \ - ../ed25519/src/key_exchange.c \ - ../ed25519/src/keypair.c \ - ../ed25519/src/sc.c \ - ../ed25519/src/seed.c \ - ../ed25519/src/sha512.c \ - ../ed25519/src/sign.c \ - ../ed25519/src/verify.c + ../ed25519/src/add_scalar.cpp \ + ../ed25519/src/fe.cpp \ + ../ed25519/src/ge.cpp \ + ../ed25519/src/key_exchange.cpp \ + ../ed25519/src/keypair.cpp \ + ../ed25519/src/sc.cpp \ + ../ed25519/src/seed.cpp \ + ../ed25519/src/sha512.cpp \ + ../ed25519/src/sign.cpp \ + ../ed25519/src/verify.cpp endif if WITH_SHIPPED_GEOIP diff --git a/src/kademlia/item.cpp b/src/kademlia/item.cpp index 974966fee..60733bcf9 100644 --- a/src/kademlia/item.cpp +++ b/src/kademlia/item.cpp @@ -34,7 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include "ed25519.h" +#include "ed25519.hpp" #ifdef TORRENT_DEBUG #include "libtorrent/lazy_entry.hpp" diff --git a/test/Makefile.am b/test/Makefile.am index 5024bea8a..2537ae8c2 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -128,17 +128,7 @@ libtest_la_SOURCES = main.cpp \ dht_server.cpp \ udp_tracker.cpp \ peer_server.cpp \ - web_seed_suite.cpp \ - ../ed25519/src/add_scalar.c \ - ../ed25519/src/fe.c \ - ../ed25519/src/ge.c \ - ../ed25519/src/key_exchange.c \ - ../ed25519/src/keypair.c \ - ../ed25519/src/sc.c \ - ../ed25519/src/seed.c \ - ../ed25519/src/sha512.c \ - ../ed25519/src/sign.c \ - ../ed25519/src/verify.c + web_seed_suite.cpp test_bitfield_SOURCES = test_bitfield.cpp test_connection_queue_SOURCES = test_connection_queue.cpp diff --git a/test/test_transfer.cpp b/test/test_transfer.cpp index 813030849..b08d59a8b 100644 --- a/test/test_transfer.cpp +++ b/test/test_transfer.cpp @@ -77,7 +77,9 @@ struct test_storage : default_storage , m_written(0) , m_limit(16 * 1024 * 2) {} - virtual void set_file_priority(std::vector const& p) {} + + virtual void set_file_priority(std::vector const& p + , storage_error& ec) {} void set_limit(int lim) {