* refactor: add TR_PRIsv, TR_PRIsv_ARG macros
Like PRId64 and similar macros, these new macros are printf() helpers.
They are for passing std::string_views to printf()-like functions.
* refactor: uninit vars in subprocess-posix
* refactor: uninit vars in handshake
* refactor: uninit vars in file-posix
* refactor: uninit vars in platform-quota
* 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)
* 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
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* Add CommonCrypto-based crypto utils implementation
Ported and adapted from an old (circa 2014-2015) branch of mine.
DH helpers are based on CCBigNum since CCDH doesn't provide acceptable error
reporting, and SecDH interface is a bit weird and limiting. Given that all
mentioned APIs are private, it doesn't seem to matter which one we're using as
any of them could be changed/removed by Apple at any point.
* Switch Xcode project to CommonCrypto backend
* refactor: [[maybe_unused]] iff arg _might_ be used
If the arg is never used, comment out its name.
If the arg is _sometimes_ used e.g. with ifdefs, use [[maybe_unused]].
* refactor: uninit vars in bandwidth.cc
* refactor: uninit vars in cache.cc
* refactor: uninit vars in fdlimit.cc
* refactor: uninit vars in inout.cc
* refactor: uninit vars in platform.cc
* refactor: uninit vars in log.cc
* refactor: uninit vars in tr-utp.cc
* refactor: uninit vars in stats.cc
* refactor: uninit vars in trevent.cc
* refactor: uninit vars in session-id.cc
* fixup! refactor: uninit vars in cache.cc
* refactor: uninit vars in upnp.cc
* refactor: uninit vars in file.cc
* refactor: uninit vars in tr-lpd.cc
* refactor: uninit vars in tr-udp.cc
* refactor: uninit vars in peer-io.cc
* refactor: uninit vars in rpc-server.cc
* refactor: uninit vars in port-forwarding.cc
* refactor: uninit vars in torrent-ctor.cc
* 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.
* 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.
* 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
* refactor: fix uninit var warnings in magnet.cc
* refactor: fix uninit var warnings in completion.cc
* refactor: fix uninit var warnings in session.cc
* 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
wolfSSL's fastmath support requires options.h to be included before
anything else. Otherwise bad codepaths get taken and a crash occurs
during DH initialization.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
* 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.
* Fix 409/404 error when request URI is exactly equal with server URL
* Fix 409/404 error when user requests "/web" path without trailing slash
* Fix errors when "rpc_url" setting has no trailing slash
* Code style fixes
* rpc-server.c: code refactoring and minor fixes
* Minor code style fix
* rpc-server.c: handle_request refactoring
Co-Authored-By: uprt <15909793+uprt@users.noreply.github.com>
* rpc-server.c: minor refactoring
Co-Authored-By: uprt <15909793+uprt@users.noreply.github.com>
* Fix clang-format warning
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
* chore: allow vararg calls in qt/.clang-tidy
An awkward PR since this isn't intended for the qt/ codebase at all, but
rather for use with libtransmission instead. But libtransmission is *so*
noncompilant at this point that this config can't be promoted higher up
the tree yet. Instead, it needs to be callable on-request by devs.
* refactor: make clang-tidy happy with bandwidth.h, .cc
* refactor: use getFooSpeedBytesPerSecond()
* refactor: make tr_peerIo a class
No behavioral changes.
Use `new` and `delete` and change `struct` references to `class`.
* refactor: make some tr_peerIo fields const
* refactor: reorganize tr_peerIo fields to remove padding holes
* refactor: remove redundant field tr_peerIo.isIncoming
* refactor: make tr_peerIo.inbuf, .outbuf fields const*
* 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>
* 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>
* 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>
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()
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
* fixup! refactor: use std::set in tr_webseed (#1847)
fix: use placement new to instantiate tr_webseeds.tasks
* fixup! refactor: use std::string in tr_scrape_response (#1866)
fix: avoid assigning a nullptr to std::string
* fixup! refactor: use std::string in tr_scrape_response (#1866)
fix: avoid assigning a nullptr to std::string
* C++ modernize: Replace MIN/MAX with type safe std::min/std::max
* Template std::min/max invocations now explicitly use largest integer type
* torrent.cc did not have <algorithm> included
* MIN/MAX Changes for subprocess-win32.cc
* Using type{} style cast instead of template parameter in std::min/max
* 32-bit type cast errors with uint64_t versus size_t
* 32-bit type cast errors inout.cc and file.cc
* Missing include in windows code; Type cast error fixed
* Missing macro in win32 daemon; Replaced MIN in commented code with std::min
* Update libtransmission/tr-getopt.cc
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* Update libtransmission/file-posix.cc
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* Update tests/libtransmission/copy-test.cc
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* Update libtransmission/peer-mgr.cc
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* Strlen returns size_t, remove cast
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
Simple change to silence warnings, changes the offending enums to be
constexprs. There is still more cleanup work to update other enums;
this just addresses the ones causing compiler warnings
* fix: dead-store asssignment warning in file-posix.
This also extracts the different per-platform preallocation methods into
their own standalone functions for readability and clarity.
* refactor: tr_quickfindFirstK --> std::partial_sort
Remove `tr_quickfindFirstK()` and use `std::partial_sort()` instead.
Co-authored-by: Mike Gelfand <mikedld@mikedld.com>
We know what strings are passed into tr_strip_positional_args(). Instead
of using dynamic allocation, use a fixed-size array that's big enough to
fit the strings that we have.
Port libtransmission to C++. This PR doesn't refactor everything to c++.
Its code changes are only what was necessary to compile and link as c++.
See libtransmission/README.md for details on how to submit modernization
patches!
Co-authored-by: Mike Gelfand <mikedld@mikedld.com>
* Switch to a standalone ARC4 implementation
This frees us from expecting it being provided by one of the crypto
libraries we support, all of which deprecated and/or removed it at this
point.
Fixes: #1103Fixes: #1777
* Suppress lgtm warnings about RC4 being weak (we don't care)
The previous code had some redundant calculations, e.g. calling
tr_torrentGetActivity() a couple of times per torrent, once in
tr_sessionCountQueueFreeSlots() and once in tr_torrentIsStalled().
Only one call is necessary.
tr_sessionCountQueueFreeSlots() used to keep iterating through all
torrents even if the number of free slots had already been decremented
to zero, even though further iteration does not change the zero return
value :) This PR checks the return value while looping to prevent this.
* perf: if logs are disabled, don't build log names
handshake.c and peer-io.c call tr_peerIoGetAddrStr() to build a name for
passing to tr_logAddDeepNamed(). Since tr_peerIoGetAddrStr() isn't free,
make sure deep logging is enabled before building the name.
* perf: prioritize announces based on scrape stats
This change is to improve responsiveness when starting a large batch of
torrents, e.g. when starting up a seedbox, but is also generally useful.
First, try to scrape as many torrents as as quickly as possible, giving
preference to that even over announces. Thanks to multiscrape we can run
through scrapes an order of magnitude faster than announces. Then scrape
responses tell us which swarms have leechers and we can prioritize those
torrents' announces.
Second, increase how many scrapes and announces we start at a time. This
limit probably hasn't been needed since 2da97b25 and by scraping faster,
the sooner we'll know which torrents to announce first.
* chore: remove printf() tracer
* perf: use scrape to know when a swarm is all-seeds
For private torrents, the tracker is the sole source of peers. So when a
private torrent's tracker responds that there are 0 leechers, we can use
that information to mark the entire swarm as seeders and to not initiate
connections to those peers if we are seeding. This can help seedboxes to
more efficiently pick which swarms to prioritize.
This strategy is not used on public torrents, since new seeder-to-seeder
connections can be useful there for pex.
This PR changes tr_peerMgrAddPex() to (1) remove tr_atom.seedProbability
field (which was not as robust as intended) and (2) add batches of peers
instead of a single peer.
* fix: only use all-seeds check for private torrents
tr_peerMgrStartTorrent() is called once per torrent on startup, so this
can be expensive if the user has a lot of torrents.
Instead, enqueue a pending rechoke that will happen on idle. This way,
all the added torrents can be handled by a single rechoke call.
* 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)
* Add in-kernel copying support for Linux (sendfile64(2), copy_file_range(2)), FreeBSD 13 (copy_file_range(2)), MacOS (copyfile(2)), and Windows (CopyFileExA).
* Fix macro name USE_COPY_FILE_RANGE.
* Minor bugfixes for userspace fallback.
* Fix linux sendfile64 bugs.
* Remove some overzealous asserts.
* Allow transmission-test-copy to take an optional argument for an external reference file.
* Fix return value error of tr_sys_path_copy.
* Use COPYFILE_ALL for Macs without COPYFILE_CLONE.
* Add in-kernel file copying for several platforms.
Numerous operating systems now have support for copying files directly in the
kernel, which is generally more efficient than copying in a userspace read(2)/
write(2) loop. (This becomes particularly relevant for 4th gen PCI-E storage,
which approaches the latency of DRAM.) For Linux I use sendfile64(2), and, for
later kernels, copy_file_range(2). FreeBSD 13 will also support
copy_file_range(2). MacOS has copyfile(2), and Windows has CopyFileExA.
Operating systems lacking such a syscall continue to use the existing
read(2)/write(2) loop.
* Appease uncrustify.
* Appease uncrustify.
* copy-test: generate random content at run time.
* copy-test: Stylistic changes and more check()s.
* copy-test: files_are_identical should follow test idioms
* tr_sys_path_copy: numerous tweaks as requested by review.
* s/old file/source file; s/new file/destination file.
* tr_sys_path_copy: handle win32 wide characters in paths.
* Uncrustify.
* test-copy: Use non-string create_file_with_contents.
* tr_sys_path_copy: numerous fixes.
Per review: generate test file content at runtime; tidy use of check();
fix style; re-measure file sizes in the copy; define a macro when the
system does not provide it; use Unicode APIs on Windows; and fix
documentation.
* Updated as per comments.
* Rebase kernel-copy changes onto 3.0 with gtest.
* Undo irrelevant comment change.
* Fix syntax error.
* Use tr_malloc() instead of tr_valloc().
* Use EXPECT instead of TR_ASSERT in gtest.
* Add error handling.
* Acceptable coding style has changed again.
Now it's camelCase. Also use nullptr instead of NULL, etc.
* Fix east/west const.
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
This is based off of PR#1526 by azy5030 to add in: Torrent Web, BiglyBT, and FrostWire. I made the additional change requested by livings124.
In addition this also adds support for: HTTP Seed, aria2 (#532), and BitLord.
* refactor: remove unnecessary func tr_valloc()
We're only using it in a handful of places, and none of them need the
kind of alignment that posix_memalign() provide. So we can drop a few
dozen lines by removing the portability wrapper.
* refactor: const correctness
* refactor: fix some implicit conversions
* refactor: make local pointers const if their objects are not modified
* refactor: do not cast away const in torrent-cell-renderer
* refactor: remove call to deprecated gtk_icon_size_lookup_for_settings
* refactor: member functions that do not mutate their objects should be declared const
* chore: do not end comments with a semicolon
* refactor: const correctness
* refactor: use getpwuid_r instead of getpwuid
* chore: simplify dict walking loop logic
* refactor: remove dead store assignment in announcer
* refactor: use std::make_shared
* chore: add '@license' tag to web sources' comments
Webpack's tersify plugin looks for that JSDoc tag in order to decide
which comments to extract into the generated license file.
* chore: address sonarcloud.io warnings
* chore: address sonarcloud.io code smells
* fixup! chore: address sonarcloud.io warnings
Give the web client a major overhaul.
User-visible highlights include:
* Mobile is now fully supported.
* Added fullscreen support on mobile.
* Better support for dark mode.
* Added mime icons to the torrent list.
* Improved theme consistency across the app.
Maintainer highlights include:
* Updated code to use ES6 APIs.
* No longer uses jQuery UI.
* No longer uses jQuery.
* Use Webpack to bundle the Javascript, CSS, and assets together -- the entire bundle size is now 68K gzipped.
* Added eslint / prettier / stylelint tooling.
* Uses torrent-get's 'table' mode for more efficient RPC calls.
* feat: add torrent-get 'primary-mime-type' to RPC.
This is a cheap way for RPC clients to know what type of content is in a
torrent. This info can be used to display the torrent, e.g. by using an
icon that corresponds to the mime type.
* use size_t for content byte count
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* explicit boolean expressions
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* use uint64_t for content byte counts
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* avoid unnecessary logic branches
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* explicit cast
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* refactor: add an autogenerated mime-type.h header
* chore: maybe fix the win32 FTBFS
* chore: add mime-types.[ch] to xcode
* Squashed commit of the following:
commit 4c7153fa48
Author: Mike Gelfand <mikedld@users.noreply.github.com>
Date: Tue Oct 13 03:15:19 2020 +0300
Remove autotools-based build system (#1465)
* Support .git files (e.g. for worktrees, submodules)
* Fix symlinks in source tarball, switch to TXZ, adjust non-release name
* Remove autotools stuff
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* Support .git files (e.g. for worktrees, submodules)
* Fix symlinks in source tarball, switch to TXZ, adjust non-release name
* Remove autotools stuff
Since there is no way to mark parameters as [potentially] unused in
standard C and when using MSVC compiler, use the widely accepted
cast-to-void approach instead.