Commit Graph

650 Commits

Author SHA1 Message Date
Charles Kerr e14c7f38e5
feat: use libpsl (#2575)
Use libpsl to calculate public and private parts of URL hosts.
2022-02-12 11:30:27 -06:00
Charles Kerr eeccc3788f
docs: move rpc-spec document from txt to markdown (#2606) 2022-02-11 10:48:21 -06:00
Charles Kerr 6383e2ff5f
feat: support dscp classes in socket iptos (#2594)
* refactor: Replace ToS with DSCP

IP TOS was superseded by DSCP in RFC 2474.

Co-authored-by: dgcampea <dgcampea@outlook.com>
2022-02-10 15:35:28 -06:00
Charles Kerr 7bdb6f777b
refactor: remove callback from tr_torrentVerify() public API (#2592) 2022-02-09 12:02:59 -06:00
LaserEyess 5565255d85
add labels to torrent-add rpc method (#2539)
This commit adds labels to the torrent-add method, allowing RPC users to
specify labels when adding a torrent. Labels metadata is commonly known
when adding torrents, so this removes the need to send another
torrent-set call to add labels.

Additionally, transmission-remote is updated to handle labels in
torrent-add.

Co-authored-by: LaserEyess <LaserEyess@users.noreply.github.com>
2022-02-03 00:02:30 -06:00
Charles Kerr 878405f862
Revert "fix: sonarcloud (#2558)" (#2562)
This reverts commit 8b9483f7fb.
2022-02-01 11:30:51 -06:00
Charles Kerr 8b9483f7fb
fix: sonarcloud (#2558)
* fix: add const modifier for functions

* fix: many sonarcloud use-init-statement warnings
2022-01-31 22:46:27 -06:00
Charles Kerr df1cca9b57
chore: update copyright years, make notices consistent (#2463) 2022-01-20 12:27:56 -06:00
Charles Kerr 8d75736ad1
fix: empty torrent filename (#2435)
fix torrents readded due to unremoved cfg files.
2022-01-17 23:14:00 -06:00
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
Charles Kerr db23ca4c6b
refactor: replace tr_info with tr_torrent_metainfo (#2397)
* refactor: replace tr_info with tr_torrent_metafo
2022-01-15 13:33:57 -06:00
Charles Kerr a9284c0a6b
fix: magnet link regression (#2390) 2022-01-11 08:28:14 -06:00
Charles Kerr dfc06fe918
refactor: use std::vector in tr_info (#2386) 2022-01-09 10:55:09 -06:00
Charles Kerr 49f2823d6f
refactor: use std::string in tr_info (#2384) 2022-01-08 17:41:05 -06:00
Charles Kerr 8b65b660c8
refactor: use std::string in tr_file (#2382) 2022-01-08 12:53:35 -06:00
Charles Kerr eafbf59832
refactor: avoid referencing tr_file struct directly (#2373) 2022-01-01 19:25:25 -06:00
Charles Kerr 6149870540
refactor: remove tr_file.priv (#2349) 2021-12-26 16:04:20 -06:00
Charles Kerr fd96a9270b
refactor: remove tr_file.offset (#2347) 2021-12-26 12:43:27 -06:00
Charles Kerr a515c1d94b
refactor: use tr_torrent_metainfo in tr ctor (#2345) 2021-12-26 10:25:07 -06:00
Charles Kerr 3f8cf63e59
refactor: use tr_torrent_metainfo in mac client (#2343) 2021-12-25 21:12:32 -06:00
Charles Kerr b058daff4b
refactor: change tr_torrentNew() args (#2337) 2021-12-24 16:05:17 -06:00
Charles Kerr 33553c5331
refactor: move tr_ioFindFileLocation() to tr_file_piece_manager (#2334) 2021-12-24 00:39:55 -06:00
Charles Kerr dd1379b0b6
refactor: add tr_interned_string (#2332) 2021-12-23 11:16:05 -06:00
Charles Kerr bd68d3a2fd
refactor: use tr_sha1_digest_t everywhere (#2330) 2021-12-21 16:14:15 -06:00
Charles Kerr 37a8046ed5
fix: more sonarcloud warnings (#2324) 2021-12-16 23:47:51 -06:00
Charles Kerr b93f3f0463
refactor: more tr_torrent housekeeping (#2320) 2021-12-16 03:43:51 -06:00
Charles Kerr 1e20d676c1
refactor: make tr_torrentInfo() private (#2285)
* refactor: make tr_torrentInfo() private
2021-12-14 15:59:44 -06:00
Charles Kerr 656df477f2
refactor: add tr_announce_list (#2308)
* refactor: add tr_announce_list (#2308)
2021-12-14 14:59:40 -06:00
Charles Kerr ab0c49859e
refactor: add tr_torrentTrackers() (#2282)
* refactor: add tr_torrentTrackers()
2021-12-08 10:55:52 -06:00
Charles Kerr c46ce2da06
refactor: add tr_torrentWebseed(), tr_torrentWebseedCount() (#2277)
* refactor: add tr_torrentWebseedCount()
2021-12-07 12:11:28 -06:00
Charles Kerr bfbca961d4
refactor: remove assigned-but-unused tr_info.originalName (#2276) 2021-12-07 00:37:34 -06:00
Charles Kerr 5096bbae9b
refactor: add tr_torrent::file() (#2274)
* refactor: add tr_torrent::fileCount()
2021-12-06 22:18:17 -06:00
Charles Kerr 867a131e1d
refactor: add tr_torrent::fileCount() (#2273)
Provide an accessor to get a torrent's file count.

This is an incremental step towards making tr_torrent's impl private.
2021-12-06 15:26:04 -06:00
Charles Kerr c656bee061
refactor: add tr_saveFile() (#2267)
* refactor: add tr_saveFile()

* refactor: add tr_ctorSaveContents()
2021-12-04 19:32:35 -06:00
Charles Kerr 35fe175f2a
refactor: add file-piece-map (#2246)
* refactor: add file-piece-map

* refactor: use tr_file_priorities

* refactor: use tr_files_wanted
2021-11-28 19:12:54 -06:00
Charles Kerr 34881f6295
refactor: make parts of tr file private (#2241)
* refactor: make parts of tr_file private
2021-11-27 21:17:47 -06:00
Charles Kerr de169c7ec3
refactor: tr_completion (#2220)
* refactor: refactor tr_completion + add test coverage for it
2021-11-25 12:26:51 -06:00
Charles Kerr 073c6af1d6
refactor: swarm (#2103)
* refactor: encapsulate request tracking in a class

Introduces a new class to peer-mgr, `ClientRequests`, which tracks what
active requests we've got pending: which blocks, when the requests were
sent, and who they were sent to.

This shouldn't change peer-mgr behavior. Its goal is to carve out some
of peer-mgr's data structures and encapsulte them behind an API that's
simpler to understand.

* refactor: move ActiveRequests to its own file

* perf: avoid duplicate call to tr_cpMissingBlocksInPiece
2021-11-19 12:37:38 -06:00
Charles Kerr af8e9e66b9
fixup! refactor: rpc-server.cc (#2152) (#2164)
fixup: rpc-server auth regression; fix tests
2021-11-14 21:54:48 -06:00
Charles Kerr a8f640c559
refactor: tr_dirSpace() (#2143)
* refactor/tr_dirSpace
2021-11-13 12:09:14 -06:00
Charles Kerr d1f8c28fcd
refactor: make piece checksums private (#2130)
* refactor: remove tr_info.pieces
2021-11-12 10:42:51 -06:00
Charles Kerr 7693ef69bf
refactor: magnet metainfo (#2124)
* refactor: magnet-metainfo
2021-11-09 20:42:18 -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 9dca5f2086
perf: intern the announcer module's URL strings (#2085)
* perf: intern the announcer module's internal URLs
2021-11-02 18:00:01 -05:00
Charles Kerr d6032f829b
refactor: remove tr_piece struct (#2059)
* refactor: remove tr_piece struct
2021-10-29 13:24:30 -05:00
Charles Kerr 8cdc2c633e
refactor: replace tr_torrentFiles() with tr_torrentFileProgress() (#1994)
* refactor: s/tr_torrentFiles/tr_torrentFileProgress

Replace tr_torrentFiles() with a new function, tr_torrentFileProgress().

tr_torrentFiles() heap-allocated an array of progress structs. There is
nothing intrinsic in tr_torrent making batch computation more efficient,
so this PR replaces it with tr_torrentFileProgress(), a per-file variant
that doesn't use the heap.
2021-10-21 13:31:03 -05:00
Daniel Kamil Kozar 77b11232f2
Add support for creating torrents with a source flag (#443)
* Add support for creating torrents with a source flag

* Add the source flag functionality for Mac OSX

* Source flag should be a part of the info dictionary

* Address review comments

* Rename "sourceFlag" to "source" since "Flag" is usually reserved for booleans.
* Free the "source" pointer in tr_metainfoFree.
* Add information about transmission-create argument to its manpage.

* Replace all occurences of "sourceFlag" with "source" and use "Source tag" in UI

* Settle on just "Source" in UI

* The last usage of "flag" hopefully bites the dust! ;-)

* Add a missing free for the source in tr_metainfoFree

* Add a "source" field to the torrent-get RPC method

* uncrustify

* Test for torrents having different infohashes due to different source flags.

This is the whole point of this feature, so it makes sense to test it.

* case is important

* try to incorporate the macosx xml changes
2021-10-18 18:05:39 -05:00
Charles Kerr 462651bb8e
refactor: rpcimpl.cc getTorrents() returns a std::vector (#1986)
* refactor: rpcimpl.cc getTorrents() returns a std::vector

* refactor: tr_torrentQueueMove*() uses std::vector
2021-10-18 09:48:45 -05:00
Dmytro Lytovchenko 953f07375a
Modernize bitfield.cc: Storage changes and refactor (#1927)
* Modernize bitfield.cc: Storage changed to vector of bytes, return vector from getRaw, new Span readonly memory view
Modernize bitfield.cc: Code style/review notes
Modernize bitfield.cc: Code format

* Modernize bitfield.cc: Swap end and begin in bit counting code assertion

* Modernize bitfield.cc: Rewrite states and simplify code

* Modernize bitfield.cc: Fixing the code and tests

* Modernize bitfield.cc: Fixing tests

* Modernize bitfield.cc: Formatting; +std::size, +const
2021-10-16 09:04:19 -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
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 003685b40a
refactor: use nullptr instead of NULL (#1884)
* refactor: use nullptr instead of NULL.

No functional changes; just more C++ification
2021-10-06 11:32:17 -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 6b7f2f9e53
refactor: make tr_info.errorString a const char*. (#1878)
this field now points to tr_torrent.errorString instead of copying into
a standalone char array.

old: sizeof(tr_torrent) 2640
new: sizeof(tr_torrent) 2136
2021-10-05 12:23:07 -05:00
Charles Kerr 17ee032dd8
refactor: remove TR_BEGIN_DECLS, TR_END_DECLS (#1837)
* refactor: remove TR_BEGIN_DECLS, TR_END_DECLS
2021-09-25 11:07:22 -05:00
Mike Gelfand db3d40d0ed Switch to clang-format for code formatting, include Mac client 2021-08-16 00:38:29 +03:00
Chrool cfce6e2e3a
configure anti brute force (#1447)
* add brute force configuration options
2020-11-14 12:43:42 -06:00
Charles Kerr 0bfbc3eba7
Sonarcloud warnings 4 (#1499)
* chore: fix some sonarcloud html warnings (e.g. deprecated attribute use)

* chore: uppercase literal suffixes

* chore: remove redundant casts

* chore: remove commented-out code

* chore: use qInfo() instead of std::cerr
2020-11-02 09:16:12 -06:00
Charles Kerr efaa66a920
fix: resolve some lgtm warnings (#1444)
* fix: warnings found by LGTM static analyzer
2020-09-11 16:07:45 -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
Charles Kerr 00be8d00d7
refactor: make variant_headers reusable to qt app. (#1369)
* refactor: make variant_headers reusable to qt app.

Torrent.cc's `change()` template methods are generically useful to deal
with tr_variant wrangling, but previously were only used in Torrent.cc.
This PR moves them into a new API `VariantHelpers.h` for use by Prefs,
Session, TorrentModel, etc.
2020-07-26 23:30:58 -05:00
Charles Kerr fcda077cdd
chore: remove extraneous/default class destructors (#1317)
* chore: remove extraneous/default class destructors

* fixup! chore: remove extraneous/default class destructors
2020-06-15 09:30:29 -05:00
Charles Kerr fa6df52d58
chore: remove unused methods (#1207)
* chore: remove unused methods in qt client

* chore: remove unused libtransmission methods

* chore: remove unused gtk methods

* chore: remove more unused libtransmission methods

* chore: remove more unused code found by @reardonia
2020-05-11 17:20:46 -05:00
Charles Kerr 44fc571a67
feat: add editDate to RPC (#1056)
* feat: add tr_stat.infoDate to note tr_info changes

The last time during this session that any tr_info field changed
(e.g. trackers/filenames edited or magnet torrent got metadata).
RPC clients can monitor this to know when to reload fields which
don't usually change.
2019-11-12 17:13:42 -06:00
Charles Kerr abac811dd2
fix: gcc warnings in libtransmission/ and utils/ (#843)
* fix: __attribute__(__printf__) warnings

* fix: implicit fallthrough warning

* fixup! fix: implicit fallthrough warning

* fix: disable warnings for 3rd party code

Since we want to leave upstream code as-is

* fixup! fix: disable warnings for 3rd party code

* fixup! fix: disable warnings for 3rd party code

* silence spurious alignment warning

Xrefs
Discussion: https://stackoverflow.com/a/35554349
Macro inspiration: 90ac46f710/f/src/util/util_safealign.h (_35)

* fixup! fix: disable warnings for 3rd party code

* fixup! fix: implicit fallthrough warning

* make uncrustify happy

* remove uncrustify-test.sh

that's probably off-topic for this PR

* fixup! fix: __attribute__(__printf__) warnings

* Update libtransmission/CMakeLists.txt

Co-Authored-By: ckerr <ckerr@github.com>

* fixup! silence spurious alignment warning

* use -w for DISABLE_WARNINGS in Clang

* refactor: fix libtransmission deprecation warnings

* fix: pthread_create's start_routine's return value

This was defined as `void` on non-Windows but should have been `void*`

* chore: uncrustify

* fix: add DISABLE_WARNINGS option for SunPro Studio

* fix "unused in lambda capture" warnings by clang++

* fix 'increases required alignment' warning

Caused from storing int16_t's in a char array.

* fix net.c 'increases required alignment' warning

The code passes in a `struct sockaddr_storage*` which is a padded struct
large enough for the necessary alignment. Unfortunately it was recast as
a `struct sockaddr*` which has less padding and a smaller alignment. The
warning occrred because of these differing alignments.

* make building quieter so warnings are more visible

* fixup! fix 'increases required alignment' warning

* Fix -Wcast-function-type warnings in GTK+ app code

https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.

GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.

Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.

In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).

* fixup! fix "unused in lambda capture" warnings by clang++

* fixup! fix "unused in lambda capture" warnings by clang++

* fix two more libtransmission compiler warnings

* fix: in watchdir, use TR_ENABLE_ASSERTS not NDEBUG
2019-11-06 11:27:03 -06:00
Mike Gelfand 10cdd7f790 Use explicit boolean conversions 2019-07-14 16:25:07 +03:00
Mike Gelfand 82df3a87f4 Update to Uncrustify 0.68.1
Tweak a few rules in the process. Now all code in cli, daemon, gtk,
libtransmission, qt, and utils is properly formatted with no manual
intervention.
2019-02-15 09:21:48 +03:00
Tavis Ormandy cf7173df93 mitigate dns rebinding attacks against daemon 2018-01-15 23:31:25 +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 f27596238d Include stdbool.h unconditionally
All the compilers should provide the header file by now. Remove `tr_isBool`
sanity checks along the way as compiler should guarantee that bool (_Bool)
values are 0 or 1 and nothing else.
2017-05-24 22:53:06 +03:00
Sebastiaan Lokhorst ac661ff099 Allow the RPC server to listen on an IPv6 address 2017-04-26 17:46:36 +02:00
Mike Gelfand 4f9d9ad92b Code style change leftovers
For some reason, GTK client wasn't fully processed. All the rest of changes
are mostly in comments.
2017-04-21 10:40:57 +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 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
Jordan Lee 77b5105ea0 fix bad TR_DEPRECATED macro on clang :P 2016-03-29 16:01:41 +00:00
Jordan Lee 8d38442cc1 give a useful definition of TR_DEPRECATED on msvc as well 2016-03-29 15:47:29 +00:00
Jordan Lee 5fbd24fda5 fix a handful of minor compiler warnings, mostly in the unit tests, eg field width shortening or implicit signed/unsigned conversions 2016-03-29 03:04:54 +00:00
Mike Gelfand d4213f09d5 On second thought, bring back stdbool.h check back
Might be useful for uClibc (which still doesn't provide it) and others.
2015-12-29 19:44:50 +00:00
Mike Gelfand eb8fc35ac6 Remove useless checks and definitions (C99)
Now that MSVC support for C99 is quite good, remove previously needed but
now unused checks and definitions, like PRI* format macros (including
PRIdMAX and TR_PRIuSIZE, replaced with %jd and %zu) and inline macro.
Also, remove ssize_t typedef and replace few occurences with ev_ssize_t.
Also, remove check for stdbool.h availability (guaranteed by C99) and
include it unconditionally (except when in C++ mode).
2015-12-29 19:37:31 +00:00
Mike Gelfand 4a4badd4af Ongoing refactoring (use size_t instead of int) 2015-12-25 10:19:50 +00:00
Jordan Lee 39c48a162e (trivial) remove trailing enum comma 2015-12-06 21:41:18 +00:00
Mike Gelfand 88983c1ac1 Use tr_sys_path_remove instead of remove 2015-10-23 04:09:40 +00:00
Mike Gelfand f89fab72f9 Remove unused session tag 2015-10-18 18:39:14 +00:00
Mike Gelfand 2e6d5c8bc9 Add more booleans to the picture 2015-05-31 22:13:31 +00:00
Mike Gelfand c845e35ce1 Fix format specifier warning introduced couple commits earlier 2014-12-13 17:04:14 +00:00
Mike Gelfand 74a5bdb9e6 Don't mess with MinGW printf support for now (tricky) 2014-12-13 16:00:14 +00:00
Mike Gelfand 52a9d774e4 Fix compilation on Windows
This should not affect non-Win32 platforms in any way.
As for Win32 (both MinGW and MSVC), this should hopefully allow for
unpatched compilation. Correct functioning is not yet guaranteed though.
2014-12-13 15:22:39 +00:00
Mitchell Livingston 0e01879974 Use built-in _WIN32 macro instead of WIN32 2014-07-04 00:00:07 +00:00
Jordan Lee e40a7d5359 (trunk) replace the tr_metainfo_builder.isSingleFile and tr_info.isMultifile fields an 'isFolder' bool in both structs.
This makes the variable naming more uniform. It also clarifies the information we're really trying to convey -- previously, isSingleFile was false whenever the torrent held a directory tree, even if there was only a single file in the tree.

Sync the Mac OS X client's use to match the libtransmission variable names.
2014-06-08 22:16:01 +00:00
Jordan Lee 4b9626bb83 Licensing changes:
1. add the option the code to be used under GPLv2 or GPLv3; previously only GPLv2 was allowed

2. add the "proxy option" as described in GPLv3 so we can add future licenses without having to bulk-edit everything again :)

3. remove the awkward "exception for MIT code in Mac client" clause; it was unnecessary and confusing.
2014-01-19 01:09:44 +00:00
Jordan Lee ea7d2482dd introduce TR_PRIuSIZE macro for portable printf()ing of size_t. mikedld 2013-09-08 17:32:09 +00:00
Jordan Lee 4c8bda8805 function pointer type correctness. mikedld 2013-09-08 17:08:18 +00:00
Jordan Lee 4aa5c5c08d (trunk, libT) #5476: also, define __USE_MINGW_ANSI_STDIO and __STDC_FORMAT_MACROS on win32 systems so these new macros will work on mingw-w64 and mingw. (rb07) 2013-08-26 17:15:12 +00:00
Jordan Lee 9fe48d7a08 (trunk, libT) #5476: correct the definitions of PRIu64 and PRIu32 on win32 systems; thanks to rb07 for this correction 2013-08-26 17:12:16 +00:00
Jordan Lee 5661aaad5e add windows-friendly definitions for PRIu64, PRId64, PRIu32 2013-08-24 20:49:27 +00:00
Jordan Lee 027e3f3066 (trunk, libT) #4682 'Add return id from duplicate torrent torrent-add rpc' -- added. 2013-05-22 20:35:38 +00:00