transmission/libtransmission
Charles Kerr bcf5e4636a
fix: calculate seed ratio by torrent size. (#2424)
Previously was calculated by number of bytes downloaded, which caused
edge cases when those two numbers were not the same, e.g. if the user
already had part of the torrent from another source and only downloaded
a small part. When this happened, the ratio could be very large and use
of seedratio would behave in a way that most people would not expect.

Note, the old behavior has been around for a VERY LONG TIME. Even though
this is a bugfix, it does change semantics. I don't think there is any
third-party code that depends on the old behavior but this is arguably
a breaking change.
2022-01-17 17:16:37 -06:00
..
.clang-tidy build: enable more .clang-tidy checks (#2088) 2021-11-03 08:59:39 -05:00
CMakeLists.txt refactor: use libdeflate instead of zlib's deflate() (#2405) 2022-01-17 10:20:12 -06:00
README.md
announce-list.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
announce-list.h refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
announcer-common.h refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
announcer-http.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
announcer-udp.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
announcer.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
announcer.h refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
bandwidth.cc fix: sonarcloud (#2322) 2021-12-16 16:58:58 -06:00
bandwidth.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
bitfield.cc fix: more sonarcloud warnings (#2324) 2021-12-16 23:47:51 -06:00
bitfield.h refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
block-info.cc fix: sonarcloud (#2322) 2021-12-16 16:58:58 -06:00
block-info.h refactor: make tr_torrent aggregates tr_block_info instead of subclassing (#2376) 2022-01-07 13:13:37 -06:00
blocklist.cc refactor: fix uninit var warnings in blocklist.cc (#2087) 2021-11-02 22:55:43 -05:00
blocklist.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
cache.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
cache.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
clients.cc fix: parse utorrent peer-id version components as hex (#2411) 2022-01-16 10:27:23 -06:00
clients.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
completion.cc Fix another integer overflow bug on 32-bit platforms with torrents > 4GB (#2391) 2022-01-12 22:52:36 -06:00
completion.h refactor: remove tr_file.offset (#2347) 2021-12-26 12:43:27 -06:00
crypto-utils-ccrypto.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
crypto-utils-cyassl.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
crypto-utils-fallback.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
crypto-utils-openssl.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
crypto-utils-polarssl.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
crypto-utils.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
crypto-utils.h refactor: base64 utils (#2381) 2022-01-08 06:46:25 -06:00
crypto.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
crypto.h refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
error-types.h
error.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
error.h refactor: don't use varargs in tr_error (#2352) 2021-12-27 20:32:22 -06:00
fdlimit.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
fdlimit.h
file-piece-map.cc refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
file-piece-map.h refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
file-posix.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
file-win32.cc refactor: don't use varargs in tr_error (#2352) 2021-12-27 20:32:22 -06:00
file.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
file.h refactor: remove varargs code in tr_sys_file (#2354) 2021-12-28 09:08:04 -06:00
foo refactor: add tr_interned_string (#2332) 2021-12-23 11:16:05 -06:00
handshake.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
handshake.h
history.h
inout.cc fix: potential out-of-range error in io's readOrWritePiece() (#2413) 2022-01-16 12:02:47 -06:00
inout.h refactor: move tr_ioFindFileLocation() to tr_file_piece_manager (#2334) 2021-12-24 00:39:55 -06:00
interned-string.h fix: clang warnings (#2339) 2021-12-25 11:22:12 -06:00
jsonsl.c
jsonsl.h
libt.dox
log.cc refactor: remove varargs code in tr_sys_file (#2354) 2021-12-28 09:08:04 -06:00
log.h refactor: web_utils (#2121) 2021-11-08 21:30:03 -06:00
magnet-metainfo.cc refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
magnet-metainfo.h refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
makemeta.cc Make some utility functions return std::string to simplify code (#2368) 2021-12-31 03:30:21 +03:00
makemeta.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
mime-types.h refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
mime-types.js
natpmp.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
natpmp_local.h
net.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
net.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
peer-common.h refactor: use std::vector in tr_info (#2386) 2022-01-09 10:55:09 -06:00
peer-io.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
peer-io.h fix: clang warnings (#2339) 2021-12-25 11:22:12 -06:00
peer-mgr-active-requests.cc refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
peer-mgr-active-requests.h refactor: swarm (#2103) 2021-11-19 12:37:38 -06:00
peer-mgr-wishlist.cc refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
peer-mgr-wishlist.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
peer-mgr.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
peer-mgr.h refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
peer-msgs.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
peer-msgs.h refactor: more tr_torrent housekeeping (#2320) 2021-12-16 03:43:51 -06:00
peer-socket.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
platform-quota.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
platform-quota.h refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
platform.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
platform.h refactor: make tr_buildPath() private (#2374) 2022-01-02 11:51:59 -06:00
port-forwarding.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
port-forwarding.h
ptrarray.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
ptrarray.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
quark.cc refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
quark.h refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
resume.cc refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
resume.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
rpc-server.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
rpc-server.h refactor: use libdeflate instead of zlib's deflate() (#2405) 2022-01-17 10:20:12 -06:00
rpcimpl.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
rpcimpl.h refactor: prefer tr_strv*() funcs (#2317) 2021-12-15 20:09:46 -06:00
session-id.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
session-id.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
session.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
session.h refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
stats.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
stats.h
subprocess-posix.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
subprocess-win32.cc refactor: don't use varargs in tr_error (#2352) 2021-12-27 20:32:22 -06:00
subprocess.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
torrent-ctor.cc refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
torrent-magnet.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
torrent-magnet.h fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
torrent-metainfo.cc explicitly use unsigned chars (#2423) 2022-01-17 15:13:22 -06:00
torrent-metainfo.h fix: potential out-of-range error in io's readOrWritePiece() (#2413) 2022-01-16 12:02:47 -06:00
torrent.cc fix: calculate seed ratio by torrent size. (#2424) 2022-01-17 17:16:37 -06:00
torrent.h refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
tr-assert.cc
tr-assert.h
tr-dht.cc refactor: make tr_buildPath() private (#2374) 2022-01-02 11:51:59 -06:00
tr-dht.h
tr-getopt.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
tr-getopt.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
tr-lpd.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
tr-lpd.h
tr-macros.h refactor: use tr_sha1_digest_t everywhere (#2330) 2021-12-21 16:14:15 -06:00
tr-udp.cc refactor: tr_session.congestion (#2151) 2021-11-14 00:41:44 -06:00
tr-udp.h refactor: more tr_torrent housekeeping (#2320) 2021-12-16 03:43:51 -06:00
tr-utp.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
tr-utp.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
transmission.h fix: calculate seed ratio by torrent size. (#2424) 2022-01-17 17:16:37 -06:00
trevent.cc fixup! refactor: use std mutex/lock intead of bespoke (#2194) (#2211) 2021-11-24 10:39:09 -06:00
trevent.h
upnp.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
upnp.h
utils.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
utils.h refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
variant-benc.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
variant-common.h refactor: make tr_variantFromBuf() public (#2187) 2021-11-17 23:37:35 -06:00
variant-json.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
variant.cc refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
variant.h refactor: replace tr_info with tr_torrent_metainfo (#2397) 2022-01-15 13:33:57 -06:00
verify.cc refactor: avoid referencing tr_file struct directly (#2373) 2022-01-01 19:25:25 -06:00
verify.h
version.h.in
watchdir-common.h
watchdir-generic.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
watchdir-inotify.cc fix: sonarcloud code smells (#2421) 2022-01-17 12:39:50 -06:00
watchdir-kqueue.cc
watchdir-win32.cc
watchdir.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
watchdir.h refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
web-utils.cc fix: allow malformed magnet links to be added (#2410) 2022-01-16 09:28:18 -06:00
web-utils.h refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
web.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
web.h refactor: tr_web's callback now uses std::string_view (#2172) 2021-11-15 12:10:18 -06:00
webseed.cc refactor: include cleanups (#2392) 2022-01-12 20:13:58 -06:00
webseed.h refactor: add tr_torrentWebseed(), tr_torrentWebseedCount() (#2277) 2021-12-07 12:11:28 -06:00
wildmat.c

README.md

Notes on the C-to-C++ Conversion

  • libtransmission was written in C for fifteen years, so eliminating all Cisms is nearly impossible. Modernization patches are welcomed but it won't all happen overnight. tr_strdup() and constexpr wil exist side-by-side in the codebase for the forseeable future.

  • It's so tempting to refactor all the things! Please keep modernization patches reasonably focused so that they will be easy to review.

  • Prefer std:: tools over bespoke ones. For example, use std::vector instead of tr_ptrArray. Redundant bespoke code should be removed.

  • Consider ripple effects before adding C++ into public headers. Will it break C code that #includes that header? If you think it might, consult with downstream projects to see if this is a problem for them.

Checklist for modernization of a module

NOTE:
The version in libtransmission/CMakeLists.txt is C++17.
See https://github.com/AnthonyCalandra/modern-cpp-features

This can be done in multiple smaller passes:

  1. Satisfy clang-tidy. libtransmission/.clang-tidy's list of rules should eventually be expanded to a list similar to the one in qt/.clang-tidy.
  2. Group member functions and their parent structs
    • Use namespace libtransmission
    • Split large modules into smaller groups of files in a libtransmission/<name> subdirectories, with own sub-namespace.
  3. Enums replaced with new enum class syntax. Numeric #define constants replaced with C++ const/constexpr.
  4. Memory - promote init and free functions to C++ ctors and dtors, and ensure it is only managed with new/delete
  5. Owned memory - promote simple pointer fields owning their data to smart pointers (unique_ptr, shared_ptr, vector, string)

Detailed Steps

  1. Satisfy clang-tidy warnings

    • Change C includes to C++ wraps, example: <string.h> becomes and update calls to standard library to use std:: namespace prefix. This clearly delineates the border between std library and transmission. Headers must be sorted alphabetically.
    • Headers which are used conditionally based on some #ifdef in the code, should also have same #ifdef in the include section.
    • Revisit type warnings, int vs unsigned int. Sizes and counts should use size_t type where this does not break external API declarations. Ideally change that too.
  2. Move and group code together.

    • Move member functions into structs. To minimize code churn, create function forward declarations inside structs, and give struct_name:: prefixes to the functions.
      typedef struct {
          int field;
      } foo;
      int foo_blep(struct foo *f) {
          return f->field;
      }
      
      becomes:
      struct foo {
          int field;
          void blep(); 
      };
      int foo::blep() {
          return this->field; 
      }
      
    • For functions taking const pointer, add const after the function prototype: int blep() const like so.
    • For structs used by other modules, struct definitions should relocate to internal *-common.h header files.
    • Split large files into sub-modules sharing own separate sub-namespace and sitting in a subdirectory under libtransmission/.
    • Some externally invoked functions must either not move OR have extern "C" adapter functions.
  3. Enums promoted to enum class and given a type:

    enum { A, B, C };
    

    becomes

    enum: int { A, B, C };        // unscoped, use A, B, C
    enum MyEnum: int { A, B, C }; // unscoped, use A, B, C
    // OR wrap into a scope -
    enum struct MyEnum: int { A, B, C }; // scoped, use MyEnum::A
    enum class MyEnum: int { A, B, C };  // scoped, use MyEnum::A
    

    this will make all values of enum to have that numeric type.

  4. Numeric/bool #define constants should be replaced with C++ const/constexpr.

  5. Memory management:

    • Prefer constructors and destructors vs manual construction and destruction. But when doing so must ensure that the struct is never constructed using C malloc/free, but must use C++ new/delete.
    • Avoid using std::memset on a new struct. It is allowed in C, and C++ struct but will destroy virtual table on a C++ class. Use field initializers in C++.
  6. Owned memory:

    • If destructor deletes something, it means it was owned. Promote that field to owning type (vector, unique_ptr, shared_ptr or string).