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)
I couldn't find infos about the "status" field of "torrent-get" in this file or on the web, so I had to look in the source code to find it, and I don't think everyone will do that. So it would be nice for this file to contain details about status
Co-authored-by: Charles Kerr <charles@charleskerr.com>
* Add instruction in README.md to config a release build.
* Use RelWithDebInfo instead of Release in README.md
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
The "id" member's only purpose is to serve as the key for the
active_notifications hash table. However, the same thing can be very easily
achieved by switching the GHashTable's hash/equal functions to "direct", which
just use the void pointers (which all keys are in a GHashTable) directly as if
they were values, and use GUINT_TO_POINTER() when referring to this hash table's
key.
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
Looks better and matches the Gtk client.
Co-authored-by: dubhater <cantabile.desu@gmail.com>
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
It's the only place where Session::isServer() is used to decide if
a file selector should be used, or a text box. Session::isLocal()
is used everywhere else.
Co-authored-by: dubhater <cantabile.desu@gmail.com>
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
* 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>
* Update enabled complier warnings
* Convert to Modern Objective-C syntax using Xcode's tool
* Convert to modern objc syntax manually, fix some PR issues
* Remove unnecessary parentheses
* Use property syntax for all custom properties
* Use property syntax for all system properties
* Fix erroneously autoreleased values
* Revert VDKQueue to old objc syntax
Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
Co-authored-by: Mitch Livingston <livings124@mac.com>
* Update libevent to 2.1.12-stable.
Fixes `kq_init: detected broken kqueue; not using.: Undefined error: 0`
message on start on macOS.
* Do not build libevent samples.
* Explicitly set library type to static on MSVC for libevent.
Co-authored-by: Mitch Livingston <livings124@mac.com>
Co-authored-by: Charles Kerr <charles@charleskerr.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.