Commit Graph

187 Commits

Author SHA1 Message Date
Charles Kerr b0ee4007ff
refactor: include cleanups (#2392)
* refactor: include <memory> when using shared_ptr or unique_ptr

* refactor: include <cstdio> iff we use it

* refactor: include <cstring> iff we use it

* refactor: include <cstdlib> iff we use it

* refactor: include <string_view> or <string> iff we use it

* refactor: include <array> iff we use it

* refactor: include <ctime> iff we use it

* refactor: include <cctype> iff we use it

* refactor: misc #include cleanups in libtransmission
2022-01-12 20:13:58 -06:00
Charles Kerr a5c6168805
refactor: make tr_buildPath() private (#2374) 2022-01-02 11:51:59 -06:00
Charles Kerr bd68d3a2fd
refactor: use tr_sha1_digest_t everywhere (#2330) 2021-12-21 16:14:15 -06:00
Charles Kerr b9406dfebb
refactor: even more torrent housekeeping (#2323) 2021-12-16 22:51:53 -06:00
Charles Kerr b93f3f0463
refactor: more tr_torrent housekeeping (#2320) 2021-12-16 03:43:51 -06:00
Charles Kerr 42b1362760
refactor: tidy libtransmission includes (#2316) 2021-12-15 15:25:42 -06:00
Charles Kerr 2977636d58
fix: sonarcloud warnings (#2260)
* fix: add-explicit-keyword-to-constructor warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuB-2farvsyMPiZl&open=AX1tyuB-2farvsyMPiZl

* fix: use a structured binding declaration

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuHH2farvsyMPiZm&open=AX1tyuHH2farvsyMPiZm

* Fix implicit-conversion-loses-precision warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuH22farvsyMPiZn&open=AX1tyuH22farvsyMPiZn

* fix use-init-statement warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuO42farvsyMPiZw&open=AX1tyuO42farvsyMPiZw

* fix implicit-conversion-loses-precision warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuO42farvsyMPiZs&open=AX1tyuO42farvsyMPiZs

* fix: implicit-conversion-loses-precision warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1tyuO42farvsyMPiZt&open=AX1tyuO42farvsyMPiZt

* fix handle-this-exceeption-or-do-not-catch-it warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1y7t12cIz3krp3mVpV&open=AX1y7t12cIz3krp3mVpV

* fix make-this-variable-a-reference-to-const warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1y7t12cIz3krp3mVpW&open=AX1y7t12cIz3krp3mVpW

* fix replace-redundant-type-with-auto warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1y7t12cIz3krp3mVpY&open=AX1y7t12cIz3krp3mVpY

* Fix use-try_emplace-instead-of-emplace warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0WPk3QwxvzFbF6whWN&open=AX0WPk3QwxvzFbF6whWN

* Fix: make-this-a-pointer-to-const warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0bZPUXjI_aUyxGBxB4&open=AX0bZPUXjI_aUyxGBxB4

* Fix use-std::make_unique warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0WPk0twxvzFbF6whWC&open=AX0WPk0twxvzFbF6whWC

* Fix: replace-push_back-with-emplace_back warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0BraL_0QLXO0pQ_Bfv&open=AX0BraL_0QLXO0pQ_Bfv

* Fix: use-init-statement warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0bZPXajI_aUyxGBxB8&open=AX0bZPXajI_aUyxGBxB8

* Fix: replace-redundant-type-with-auto warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0bZPXajI_aUyxGBxB9&open=AX0bZPXajI_aUyxGBxB9

* Fix: replace-emplace-with-try_emplace warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0bZPXajI_aUyxGBxB_&open=AX0bZPXajI_aUyxGBxB_

* Fix: extract-assignment-from-operation warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0bZPXajI_aUyxGBxCA&open=AX0bZPXajI_aUyxGBxCA

* Fix use-init-statement warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX1op6_hUBCnp-Grmra8&open=AX1op6_hUBCnp-Grmra8

* fix: use-init-statement warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0L8qgMUnpKTxYiu5CN&open=AX0L8qgMUnpKTxYiu5CN

* Revert "Fix use-std::make_unique warning"

This reverts commit 463a742f34.

* fix: make-parameter-a-pointer-to-const warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX06St241usi2gyYkPTZ&open=AX06St241usi2gyYkPTZ

* fix: make-parameter-a-pointer-to-const warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX06St241usi2gyYkPTa&open=AX06St241usi2gyYkPTa

* fix: use-init-statement warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX01Itn2f_SST5i7BN1o&open=AX01Itn2f_SST5i7BN1o

* fix: use-init-statement warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AXziv55-MuQoG-Y-NgLX&open=AXziv55-MuQoG-Y-NgLX

* fix: use-init-statement warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AX0_a_JGNJn7rAzml_68&open=AX0_a_JGNJn7rAzml_68

* fix: replace-redundant-type-with-auto warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AXzyMRYbK9dvryvWm8XA&open=AXzyMRYbK9dvryvWm8XA

* fix: use-init-statement warning

Xref: https://sonarcloud.io/project/issues?id=transmission_transmission&issues=AXziv52fMuQoG-Y-NgLW&open=AXziv52fMuQoG-Y-NgLW
2021-12-01 17:11:57 -06:00
Charles Kerr da855a7257
refactor: use std mutex/lock intead of bespoke (#2194)
* refactor: use std mutex/lock intead of bespoke
2021-11-20 15:20:45 -06:00
Charles Kerr b3e4fc64c5
perf: faster shutdown (#2193)
* perf: don't update queue positions during shutdown

When a torrent is being removed, we try to update the queue positions of
the other torrents. But it's (slightly) expensive and is irrelevant when
the session is closing, so skip it in that case.

* perf: torrentLoadResume shouldn't touch tor->dirty

Loading torrent settings from disk does call a lot of tr_torrentSetFoo()
functions, but since these are the saved settings, they shouldnt' affect
the torrent's 'is dirty' flag.
2021-11-18 12:19:55 -06:00
Charles Kerr 3bab6f02dc
refactor: rpc-server.cc (#2152)
* refactor: first baby steps towards C++ifying rpc_server
2021-11-14 15:14:37 -06:00
Charles Kerr 3d38e01a13
refactor: tr_session.congestion (#2151)
* refactor: tr_session.congestion
2021-11-14 00:41:44 -06:00
Charles Kerr d55474161e
refactor: rpc whitelist (#2150)
* refactor: make rpc-whitelist string_view-friendly
2021-11-14 00:02:45 -06:00
Charles Kerr 7ff6756ac5
refactor: tr session.blocklist (#2147)
* refactor: tr_session.blocklist
2021-11-13 19:09:33 -06:00
Charles Kerr 0be95b5074
refactor: tr_session.scripts (#2146)
* refactor: tr_session.scripts
2021-11-13 17:33:18 -06:00
Charles Kerr 903338af72
refactor: tr_session.incomplete_dir (#2145) 2021-11-13 14:49:10 -06:00
Charles Kerr a8f640c559
refactor: tr_dirSpace() (#2143)
* refactor/tr_dirSpace
2021-11-13 12:09:14 -06:00
Charles Kerr d8b57fe4dc
refactor: web_utils (#2121)
* chore: move web utils from web, utils to web-utils
2021-11-08 21:30:03 -06:00
Charles Kerr 4ecf74081c
refactor: remove tr_ctorSetMetainfoFromHash() (#2116)
* refactor: remove tr_ctorSetMetainfoFromHash()
2021-11-07 20:04:07 -06:00
Charles Kerr e5225ba8a2
refactor: tr_torrentFindFromHashString() takes a std::string_view (#2082)
* refactor: tr_torrentFindFromHashString() takes a string_view
2021-11-01 19:18:09 -05:00
Charles Kerr 9200d972c3
refactor: use a std::vector for tr_session.removed_torrents (#2062) 2021-10-29 18:49:15 -05:00
Charles Kerr 2b65b985cf
refactor: cppcoreguidelines-init-variables pt. 14 (#2049)
* refactor: fix uninit var warnings in ptrarray

* refactor: fix uninit var warnings in bitfield

* refactor: fix uninit var warnings in handshake

* refactor: fix uninit var warnings in tr-dht

* refactor: fix uninit var warnings in natpmp

* refactor: fix uninit var warnings in tr-dht

* refactor: fix uninit var warnings in crypto-utils-openssl

* refactor: fix uninit var warnings in handshake

* refactor: fix uninit var warnings in crypto-utils

* refactor: fix uninit var warnings in crypto

* Revert "refactor: fix uninit var warnings in handshake"

This reverts commit 5aaa9cc30a.

* refactor: fix uninit var warnings in crypto-utils-ccrypto

* refactor: fix uninit var warnings in crypto-utils-polarssl

* refactor: fix uninit var warnings in crypto-utils-cyassl

* fixup! refactor: fix uninit var warnings in crypto-utils-cyassl

* fixup! refactor: cppcoreguidelines-init-variables pt. 13 (#2043)
2021-10-26 19:16:56 -05:00
Charles Kerr 3008a992ca
fix: Bitfield.getRaw() regression (#2023)
* fix: Bitfield.getRaw() regression
2021-10-24 15:43:36 -05:00
Charles Kerr b491da0ce4
refactor: add tr_peer_id_t (#2004)
* refactor: move handshake_done args into a convenience struct

* refactor: move peer_id from peerIo to tr_handshake

tr_handshake is a short-term object and tr_peerIo is long-term, so this
effectively narrows the scope of this field.

* chore: remove unused field tr_peerIo.isEncrypted

* refactor: add tr_peer_id_t type to hold peer ids.

this is a 'using' alias to a std::array<> so that code passing peer-ids
around doesn't have to memcmp / memcpy PEER_ID_LEN anymore. Also removes
the now-unused PEER_ID_LEN macro.
2021-10-21 21:40:55 -05:00
Charles Kerr 98e16a178f
refactor: add an enumeration of the script types (#1934)
* refactor: add an enumeration of the script types

This simplifies the API by having a single set of functions that can be
used for getting/setting all the script types.
2021-10-12 22:46:12 -05:00
Charles Kerr ba6513ed4a
feat: add an option to run a script when a torrent is added (#1896)
Co-authored-by: cfpp2p <cfpp2p>
2021-10-12 16:32:32 -05:00
Dmytro Lytovchenko 39376f2105
Modernize/bitfield.cc: Make into C++ (#1917)
* Modernize bitfield.cc: Grouped member functions into the struct; C++ construction

* Modernize bitfield.cc: Naming style similar to qt/ C++ source

* Modernize bitfield.cc: Bitfield test updated to new API

* Modernize bitfield.cc: Renames for private functions

* Modernize bitfield.cc: Formatting

* Modernize bitfield.cc: Remove struct in 'struct Bitfield' and update commented code too

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-10-11 12:29:14 -05:00
Dmytro Lytovchenko a4d7e11a14
Bandwidth.cc bring naming closer to C++ style of code in qt/ (#1914)
* Modernize bitfield.cc: Rename tr_bandwidth to Bandwidth; Move dependent structs and consts into it

* Modernize bitfield.cc: Rename internal fields to lower_snake_case_ with suffix underscore

* Modernize bitfield.cc: Remove struct in 'struct Bandwidth' type usages

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-10-09 20:12:03 -05:00
Dmytro Lytovchenko c287b82c00
Modernize bandwidth.cc: Moved functions inside struct (#1895)
* Modernize bandwidth.cc: Move functions inside struct

* Modernize bandwidth.cc: Review notes - remove extraneous checks, move small functions into .H file, etc

* Modernize bandwidth.cc: Construction and destruction is now via C++ new/delete

* Modernize bandwidth.cc: Rename used() to notifyBandwidthConsumed()

* Modernize bandwidth.cc: Children is now unordered_set

* Modernize bandwidth.cc: Allocation functions for peer bandwidth are now using std::vector instead of ptrArrays

* Modernize bandwidth.cc: Code formatting

* Modernize bandwidth.cc: Private fields after public; Minor review notes

* Modernize bandwidth.cc: Ungroup enums into constants; Docs minor update

* Modernize bitfield.cc: Docs comments changes; Using constexpr instead of const

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-10-09 07:52:09 -05:00
Charles Kerr 83f21b8e0e
refactor: prefer constexpr functions over static inline ones (#1887)
* refactor: prefer constexpr functions over static inline ones
2021-10-06 17:24:04 -05:00
Charles Kerr cc204e0b2c
refactor: prefer "using" over "typedef" (#1883)
* refactor: prefer "using" over "typedef"
2021-10-06 09:26:07 -05:00
Charles Kerr 8983af7e46
refactor: make some tr_session methods private (#1879)
These public methods weren't used anywhere except in tr_session, so make
them private.

tr_sessionGetAltSpeed_Bps()
tr_sessionGetPieceSpeed_Bps()
tr_sessionGetRawSpeed_Bps()
tr_sessionSetAltSpeed_Bps()
tr_sessionSetSpeedLimit_Bps()
2021-10-05 13:54:02 -05:00
Charles Kerr 78e571d6f2
refactor: use std::set in tr_announcer.stops (#1859)
* refactor: use std::set for tr_announcer.stops
2021-09-29 18:42:50 -05:00
Charles Kerr 20b5a8c62b
refactor: use std::vector in tr_sessionGetNextQueuedTorrents (#1858) 2021-09-29 17:21:04 -05:00
Charles Kerr 12f052621d
refactor: replace tr_list with std::list in tr_session.blocklists (#1846) 2021-09-27 13:28:41 -05:00
Charles Kerr b92c609ed9
refactor: use std container for session torrents (#1832)
* refactor: use std container for session's torrents
2021-09-24 18:31:02 -05:00
Dmytro Lytovchenko 43d1ece562
C++ modernization: Replace NULLs with typesafe nullptrs (#1799)
Fixing CI errors and build errors
Reverted changes: NULL in EV_SET macro; Clang-formatting
Reverted changes: MacosX *.m files reverted from master
2021-09-14 19:18:09 -05:00
Charles Kerr c0ed82533c
perf: lookup tables for faster torrent searching. (#1778)
* perf: lookup tables for faster torrent searching.

tr_torrentFindFromId(), tr_torrentFindFromHashString(), and
tr_torrentFindFromHash() are now O(log N) instead of O(N) where
N is the number of torrents.

* build: fix clang-tidy warning

error: integer to pointer cast pessimizes optimization opportunities
[performance-no-int-to-ptr,-warnings-as-errors] from TR_BAD_SYS_FILE
which expands to INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)
2021-09-09 00:22:29 -05:00
Mike Gelfand db3d40d0ed Switch to clang-format for code formatting, include Mac client 2021-08-16 00:38:29 +03:00
Lucas Clemente Vella 1194b88258
Renaming variables to better reflect what they do. (#1660)
Because bound IPv4 is hardly ever a public address.

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2021-05-19 15:45:03 -05:00
Charles Kerr 677dc73eac
refactor: use GTest for running tests (#1383)
* refactor: use google-test on libtransmission tests
2020-08-11 13:11:55 -05:00
Mike Gelfand 5b29fe1556 Ensure include guard is the first non-comment line 2017-11-14 23:21:28 +03:00
Mike Gelfand 27b6884408 Move uTP timer to session struct 2017-07-02 13:31:33 +03:00
Mike Gelfand f701d501a8 Move generic macros to a separate tr-macros.h file 2017-06-18 17:11:20 +03:00
Mike Gelfand 82722476aa Fix some issues reported by Coverity 2017-05-20 23:31:56 +03:00
Mike Gelfand a762c770f2 Make conditional expressions explicitly boolean 2017-04-30 19:26:01 +03:00
Mike Gelfand dadffa2c0f Align type qualifiers to the right (code style)
This way all the qualifiers (`const`, `volatile`, `mutable`) are grouped
together, e.g. `T const* const x` vs. `const T* const x`. Also helps reading
types right-to-left, e.g. "constant pointer to constant T" vs. "constant
pointer to T which is constant".
2017-04-20 19:53:20 +03:00
Mike Gelfand d7930984ef Adjust uncrustify config, reformat all but Mac client
There're places where manual intervention is still required as uncrustify
is not ideal (unfortunately), but at least one may rely on it to do the
right thing most of the time (e.g. when sending in a patch).

The style itself is quite different from what we had before but making it
uniform across all the codebase is the key. I also hope that it'll make the
code more readable (YMMV) and less sensitive to further changes.
2017-04-20 10:01:22 +03:00
Mike Gelfand 26b0a041cc Factor out session ID into a standalone entity 2016-09-21 22:29:56 +03:00
Mike Gelfand 2248d3670f Get rid of $Id$ SVN keywords in source files 2016-09-02 23:10:15 +03:00
Jordan Lee 1af60ad6ad use '#pragma once' instead of #ifndef..#define..#endif guards 2016-03-29 16:37:21 +00:00