Commit Graph

5915 Commits

Author SHA1 Message Date
tearfur 2211086338
fix: conform to libcurl requirements to avoid memory leak (#5702) 2023-07-05 22:05:03 -05:00
Charles Kerr f83a60830a
refactor: add tr_socket_address typedef (#5730) 2023-07-05 11:33:50 -05:00
tearfur 6482d78852
perf: reduce copying in `enforceSwarmPeerLimit()` (#5731)
* reduce copying in `enforceSwarmPeerLimit()`

* clearer comparator naming
2023-07-05 10:10:04 -05:00
tearfur 2a9c30a616
add constexpr noexcept (#5729) 2023-07-04 23:50:39 -05:00
tearfur 8543555584
refactor: use `std::pair` to store socket addresses (#5723) 2023-07-04 20:29:12 -05:00
Charles Kerr 5b38e819da
perf: minor cleanups (#5728)
* refactor: in torrent_metainfo.is_private(), cheaper to return a bool than a bool const&

* refactor: in tr_torrent::id(), cheaper to return an int than an int const&

* refactor: in tr_metainfo_builder.is_private(), cheaper to return a bool than a bool const&

* refactor: break peer_atom.flags2 into separate bools
2023-07-04 19:47:51 -05:00
tearfur 449da2b53e
fix: assert failure when Transmission quit with pending IP queries (#5721) 2023-07-04 16:33:58 -05:00
Charles Kerr 56b27057fd
refactor: add lightweight observable / observer for decoupling (#5716) 2023-07-04 15:47:18 -05:00
Charles Kerr 6a2a4c3032
perf: move log strings instead of cloning them (#5726) 2023-07-04 14:03:45 -05:00
Charles Kerr 0a6d1806f9
perf: avoid string allocations by using fixed-width hash strings (#5725) 2023-07-04 13:04:03 -05:00
Charles Kerr e68b76bc14
perf: use small::unordered_map in tr_torrent::primary_mime_type() (#5722) 2023-07-04 09:40:36 -05:00
Charles Kerr 7c7771a12b
perf: use small:set in tr_file_piece_map::reset() (#5720) 2023-07-03 21:57:09 -05:00
Charles Kerr d76d26a580
perf: faster Cache::write_contiguous() (#5715) 2023-07-02 15:23:32 -05:00
Charles Kerr d2d30c2734
chore: update mime types (#5712) 2023-07-02 08:32:21 -05:00
Charles Kerr 4c282bdbb4
fix: recent build warnings and errors (#5711)
* fix: use std::empty instead of isEmpty()

* fix: fix trivially assignable warning hicpp-move-const-arg

* fix: fix clang-diagnostic-unused-but-set-variable warning

* fix: fix readability-braces-around-statements warning
2023-07-01 10:22:15 -05:00
tearfur 9c17463a80
fix: revert "perf: improve IPv4 `tr_address` comparison" (#5709)
* Revert "perf: improve IPv4 `tr_address` comparison (#5651)"

This reverts commit 70decc1d9d.

* added tests

* add ipv4 equal test and std header
2023-07-01 09:39:35 -05:00
Charles Kerr 8183d7fddf
refactor: utils naming (#5696)
* chore: rename tr_strvContains to tr_strv_contains

* chore: rename tr_strvStartsWith to tr_strv_starts_with

* chore: rename tr_strvEndsWith to tr_strv_ends_with

* chore: rename tr_strvSep to tr_strv_sep

* chore: rename tr_strvStrip to tr_strv_strip

* chore: rename tr_strvToBuf to tr_strv_to_buf

* refactor: rename tr_saveFile() to tr_file_save()

rename tr_loadFile() to tr_file_read()

rename tr_moveFile() to tr_file_move()

* refactor: rename tr_parseNum() to tr_num_parse()

refactor: rename tr_parseNumRange() to tr_num_parse_range()

* chore: group related functions together in header
2023-06-30 09:49:58 -05:00
Charles Kerr ce66e5c442
iwyu: remove, add std headers where used (#5694)
* chore: remove unused #include <array>

* chore: remove unused #include <chrono>

* chore: remove unused #include <set>

* chore: remove unused #include <algorithm>

* chore: remove unused #include "interned-string.h"

* chore: remove unused #include <list>

* chore: remove unused #include <optional>

* chore: iwyu <cstddef>

* chore: iwyu <ctime>

* chore: remove unused #include <cerrno>

* chore: remove unused #include <deque>

* chore: remove unused #include <vector>

* chore: remove unused #include <memory>

* chore: remove unused #include <unordered_set>

* chore: remove unused #include <array>

* chore: remove unused #include <mutex>

* chore: remove unused #include <functional>

* chore: remove unused #include <cmath>
2023-06-29 23:51:55 -05:00
Charles Kerr cb101ec6cf
refactor: make tr_logGetQueueEnabled() private (#5693)
it is only used in log.cc, so remove it from the public header
2023-06-29 14:19:40 -05:00
tearfur b79de0b431
perf: convert comparator functors to static constexpr (#5687) 2023-06-29 13:13:25 -05:00
Charles Kerr 2f2ae61d0c
refactor: remove unused function tr_peer.bandwidth() (#5691) 2023-06-29 11:14:05 -05:00
Charles Kerr 22bb9e5757
refactor: rename tr_dirSpace() to tr_sys_path_capacity() (#5689) 2023-06-29 10:23:00 -05:00
Charles Kerr 3474a1da58
chore: remove tr_wait(); use std::this_thread::sleep_for() (#5683) 2023-06-29 08:51:39 -05:00
Charles Kerr fd4a0b1d16
chore: remove unused function tr_env_get_int() (#5682) 2023-06-28 22:04:07 -05:00
Charles Kerr 7e1ecf2f0f
refactor: remove useless TR_DEBUG_FD env var (#5681)
This feature was originally meant to redirect verbose logging to *any*
fd, but it now only supports writing to stdout or stderr, and defaults
to stderr.

Redirecting to stdout isn't very useful and complicates the code, so
just remove it and always use stderr.
2023-06-28 16:26:15 -05:00
tearfur 7fa1498ed5
perf: make `CompareCacheBlockByKey` constexpr (#5678) 2023-06-28 10:23:38 -05:00
tearfur 6bbe6537cb
feat: bypass disk write cache when `cache-size-mb` is zero 2023-06-28 08:57:26 -05:00
Charles Kerr 9afced725a
refactor: remove libtransmission::Buffer (#5676)
* refactor: use StackBuffer in announcer-udp

* chore: update buffer tests

* refactor: remove unused libtransmission::Buffer

superseded by libtransmission::StackBuffer
2023-06-27 19:06:25 -05:00
Geoffrey Bonneville 7fdfabe184
fix: do not write log if file handler is bad (#5675) 2023-06-27 13:44:10 -05:00
Charles Kerr 2db2091599
perf: in cache, flush biggest contiguous blocks (#5671) 2023-06-27 12:08:29 -05:00
Charles Kerr 24bc3d135d
perf: add StackBuffer using small::vector (#5672)
* perf: use libtransmission::StackBuffer in variant-benc

* perf: use libtransmission::StackBuffer in variant-json

* perf: use libtransmission::StackBuffer in handshake

* perf: use libtransmission::StackBuffer in peer-msgs

* perf: use libtransmission::StackBuffer in peer-io
2023-06-27 10:51:20 -05:00
tearfur 70decc1d9d
perf: improve IPv4 `tr_address` comparison (#5651) 2023-06-26 21:17:32 -05:00
tearfur ed02f98014
ditch `std::lldiv` so that functions can take matching parameter types (#5659)
* ditch `std::lldiv` so that functions can take matching parameter types

* revert unintended change
2023-06-25 13:29:58 -05:00
Charles Kerr dc88b97f37
refactor: small again (#5666)
* refactor: restore the non-small parts of 5654

* refactor: restore the peer-mgr-active-requests parts of 5654

* chore: iwyu evbuffer in web.h
2023-06-25 12:33:32 -05:00
tearfur aa6f00b162
refactor: global-ip-cache.cc nits (#5655) 2023-06-24 14:30:37 -05:00
LaserEyess 9b5a75528e
fix: broken unix socket support (#5665)
The changes in #5523 made two errors in the new implementation

1. tr_unix_address::to_string() got the ternary check backwards, leading
   to always printing an empty string when the address is valid.
2. The inputs to tr_strvStartsWith in tr_unix_address::from_string()
   were backwards as well, leading to the check failing for valid
   socket addresses.

Co-authored-by: LaserEyess <LaserEyess@users.noreply.github.com>
2023-06-24 13:57:20 -05:00
Charles Kerr df1adf0e0f
chore: revert small buffer (#5654)
* Revert "perf: use libsmall in libtransmission, pt 3 (#5653)"

This reverts commit 3b03494580.

* Revert "perf: use small in libtransmission (#5650)"

This reverts commit 559f6f0332.
2023-06-22 18:42:48 -05:00
tearfur 41cfdce6fd
refactor: replace some C idioms with C++ ones (#5656)
* tidy up legecy practices

* remove undefined std::ignore usage

* avoid extra function stack level in daemon.cc
2023-06-22 17:58:16 -05:00
tearfur 699b3d8416
perf: use a std::map to store peers in `tr_swarm` (#5645) 2023-06-22 15:21:44 -05:00
tearfur b562b2de4b
feat: new default piece size calculation for transmission-create (#5615) 2023-06-22 11:50:57 -05:00
Charles Kerr 3b03494580
perf: use libsmall in libtransmission, pt 3 (#5653)
* refactor: use BufferReader, BufferWriter in peer-socket

* feat: expose GrowthFactor in tr-buffer

* perf: choose better defaults for the peer message buffers

* chore: sync tests

* refactor: use small::map in ActiveRequests::Impl
2023-06-22 00:24:42 -05:00
Charles Kerr 559f6f0332
perf: use small in libtransmission (#5650)
* refactor: reimplement Buffer using small

* refactor: use SmallBuffer in announcer-udp

* refactor: use SmallBuffer in variant-json

* refactor: use SmallBuffer in variant-benc

* refactor: use SmallBuffer in handshake

* refactor: use SmallBuffer in peer-msgs

* refactor: delete move semantics on stack-based buffers
2023-06-21 22:41:09 -05:00
tearfur 40e80989b2
encode `&key=` as fixed-width 8-digit hex (#5652) 2023-06-21 11:53:06 -05:00
Charles Kerr 432fc9bafc
refactor: add libsmall dependency (#5649)
* refactor: add small dependency

* refactor: use small in variant.cc

* refactor: use small in cache.h
2023-06-20 22:50:36 -05:00
tearfur 548f840b8d
fixup: refactor handshake objects to use socket address as key as well (#5644) 2023-06-20 13:10:26 -05:00
tearfur 280dea4e33
add support for sending the `ipv4` parameter during ltep handshake (#5643) 2023-06-20 10:51:07 -05:00
tearfur 64261685d8
fix: use both address + port together as a key for peer lookup (#5619) 2023-06-19 20:26:39 -05:00
LaserEyess 23a52fa1c5
fixup: dedup tr_rpc_address with tr_address (#5523)
* fixup: dedup tr_rpc_address with tr_address

tr_rpc_address was duplicating a lot of work that tr_address was doing a
lot better. Fall back to using tr_address for ipv4/ipv6 connections and
make a tr_unix_addr for handling unix sockets.

* remove unnecessary functions
2023-06-19 15:51:20 -05:00
Василий Чай ddac05954b
fix: return error when renaming into existing file (#5563) 2023-06-19 00:30:55 -05:00
tearfur b8ff35c4ce
handle IPv6 NAT during LTEP handshake (#5565)
* fix: peer handshake reported wrong ipv6 address

https://github.com/transmission/transmission/issues/5542#issuecomment-1556710922
2023-06-18 19:06:31 -05:00
Charles Kerr fd583ac878
deps: bump libfmt to v10.0.0 (#5635)
seems to be semver/minor safe for our API use

Fixes #5511.

Possibly fixes #5627.
2023-06-18 17:36:39 -05:00
tearfur 802619e174
fix: fixes and improvements to global IP query (#5510) 2023-06-11 18:27:01 -05:00
Charles Kerr c8e84f870b
ci: remove "brew update" step (#5606) 2023-06-11 16:28:43 -05:00
Mike Gelfand 8ca02b8f28
Avoid locale use in `tr_truncd()` (#5587)
`tr_parseNum<>()` is implemented with `fast_float::from_chars()`, and
the latter is documented as "expecting a locale-indepent format
equivalent to what is used by std::strtod in the default ("C") locale".
To accomodate locale independent number parsing, switch back to
locale-independent number formatting in `tr_truncd()` by both removing a
`L` format specifier from `fmt::format_to_n()` call and using a fixed
"." decimal separator when truncating the value.
2023-06-10 17:09:18 -05:00
Daniel Kamil Kozar c1c27f3da0
Expose files' begin and end pieces via RPC (#5578)
* Expose files' begin and end pieces via RPC

This adds two arguments, `beginPiece` and `endPiece`, for each of the entries
in the `files` array of the RPC's `torrent-`get` method.

The point is to allow RPC clients to display a file's completion progress as
piece-based in addition to byte-based.
2023-06-05 13:15:32 -05:00
Cœur 87472672a6
build: fix xcode build (#5521) 2023-05-19 23:17:24 -05:00
Charles Kerr e171cbae9c
refactor: move Buffer::add_socket() to BufferWriter::add_socket() (#5543) 2023-05-19 23:06:26 -05:00
Charles Kerr ae888ef08e
perf: avoid map insertion for complete blocks received (#5540) 2023-05-19 18:36:07 -05:00
Charles Kerr 52b03c2489
refactor: migrate methods to buffer reader (#5533) 2023-05-18 16:56:29 -05:00
Charles Kerr 4fd5f3a490
refactor: use reserve_space() in peer-io (#5532) 2023-05-17 13:57:27 -05:00
Charles Kerr b9698210ef
refactor: restore part of Buffer::reserve_space() (#5529) 2023-05-16 21:46:41 -05:00
Charles Kerr 2cf9678737
fix: revert buffer reserve space (#5528)
* Revert "refactor: use BufferReader, BufferWriter as function args (#5518)"

This reverts commit c2d48a7d11.

* Revert "fixup! refactor: add BufferReader, BufferWriter::reserve_space() (#5513)"

This reverts commit b08e17beef.

* Revert "refactor: add BufferReader, BufferWriter::reserve_space() (#5513)"

This reverts commit 51fd7056ba.
2023-05-14 17:24:42 -05:00
Charles Kerr e88bf946e1
perf: avoid extra work in read_vc() (#5527) 2023-05-14 15:01:04 -05:00
Charles Kerr 8a1a6dba49
perf: avoid extra heap alloc in block cache (#5522) 2023-05-13 14:16:00 -05:00
Charles Kerr 69fc149f07
fix: avoid unintentional map insertions in ActiveRequests::count() (#5520) 2023-05-12 20:18:26 -05:00
Charles Kerr 7cabeff24f
perf: use std::bitset instead of tr_bitfield in incoming_piece_data (#5519)
Since max size is small and known at compile time, we can avoid extra heap allocations
2023-05-12 19:31:59 -05:00
Charles Kerr c2d48a7d11
refactor: use BufferReader, BufferWriter as function args (#5518) 2023-05-12 18:10:08 -05:00
Charles Kerr b08e17beef fixup! refactor: add BufferReader, BufferWriter::reserve_space() (#5513)
chore: remove tracer fmt::print() statements
2023-05-12 11:47:01 -05:00
Charles Kerr 51fd7056ba
refactor: add BufferReader, BufferWriter::reserve_space() (#5513) 2023-05-12 11:15:15 -05:00
Charles Kerr c61d8b7cf7
refactor: rename tr_tracker_view.host to .host_and_port for clarity (#5508) 2023-05-08 20:28:10 -05:00
Charles Kerr 0d3b321bac
refactor: use snake_case for libtransmission class methods (#5497) 2023-05-05 23:11:05 -05:00
tearfur d65f9329cd
refactor: followup/cleanup of `tr_global_ip_cache` PR (#5498)
* remove tr_session::bindAddress()

* replace tr_net_hasIPv6 with tr_session::has_ip_protocol()

* update comment
2023-05-05 22:05:28 -05:00
kmikita 693d202a64
refactor: save stats.json periodically and when closing session #5476 (#5490) 2023-05-05 15:33:23 -05:00
tearfur 474a30ab2d
feat: add global IP cache, fix UDP connection failure warnings 2023-05-05 12:17:40 -05:00
Gary Elshaw 2f1d5a225c
fix: comment typos in libtransmission (#5473) 2023-04-30 13:29:29 -05:00
Mike Gelfand e8fcb025a0
fix: use user-preferred locale (#5444)
* Use user-preferred locale

Previous fix adding `L` format specifier was correct but only fixed half
of the problem, as C++ locale is set up to be "C" by default. GTK client
used to call `setlocale(LC_ALL, "")` to set up user-preferred locale
which only affected C functions and `std::locale` (used by libfmt) was
unaware of those changes.

Apply the fix to all the binaries since they're all doing some sort of
output to the user and calling libtransmission helpers, as well as using
libfmt directly.

* Improve libtransmission's json-test

Set the locale C++ way to avoid any sort of inconsistencies, and also
restore it to the old one once finished testing.

* Improve transmission-show test runner script

Quote outputs to avoid CMake error about `message()` being called with
no arguments. Capture stderr to the same output file. Fallback to `git
diff` if `diff` wasn't found. A few other minor changes.
2023-04-27 09:10:33 -05:00
Charles Kerr 47667bab8d
fix: bug that prevented providing the final metadata piece (#5460)
Fixes bug in implementation of BEP 9

Xref: https://www.bittorrent.org/beps/bep_0009.html
2023-04-26 19:40:49 -05:00
Charles Kerr 1b6b85989c
feat: add generic favicon_cache class for reuse between Qt, GTK app (#5294) 2023-04-22 21:11:16 -05:00
Charles Kerr 9d2507c7e3
refactor: snake_case in libtransmission class methods (#5428) 2023-04-22 20:25:55 -05:00
Charles Kerr 7e7d8137a0
fixup! feat: Add BufferWriter class (#5154) (#5437) 2023-04-22 18:13:39 -05:00
Charles Kerr 9f8a7a656e
fix: Buffer::Buffer(Buffer&&) bug (#5435) 2023-04-22 16:10:09 -05:00
Charles Kerr ce4ffc3bdb
fix: 5422 use-after-free in peerMsgs::canRead (#5425) 2023-04-20 13:18:53 -05:00
Charles Kerr 3044c14b10
perf: in Buffer::Iterator, defer evbuffer API calls (#5420) 2023-04-19 16:00:30 -05:00
Charles Kerr f2aa3e197b
refactor: add tr_sys_dir_get_files() (#5412) 2023-04-18 16:23:20 -05:00
Charles Kerr a8e01ac38d
fix: minor warnings (#5409)
* chore: fix readability-qualified-auto warnings

* chore: fix clang-analyzer-core.uninitialized.Branch warning

* fix: collision of key 'ERROR' in transmission-qt

* chore: silence -Wshadow warning

* chore: silence warning C4100: 'iter': unreferenced formal parameter

* chore: fix warning C4127: conditional expression is constant warning
2023-04-17 23:11:09 -05:00
Charles Kerr 7d86d67bc7
chore: prefer fmt/core.h over fmt/format.h (#5404) 2023-04-16 15:34:19 -05:00
Charles Kerr 3af9645615
refactor: add tr_address::is_any() (#5398)
As suggested by @tearfur

Xref: https://github.com/transmission/transmission/pull/5329#discussion_r1166236165
2023-04-15 19:30:20 -05:00
Kyle Sanderson 06c784f639
fix: uninitialized session_id_t values (#5396) 2023-04-15 00:07:07 -05:00
Charles Kerr e91af26923
perf: remove staging step for outbound peer msgs (#5394)
Write non-piece peer messages directly to the peer's outbuf instead of
waiting for a pulse() message to refill it. This can help with latency
sending messages out.

Change the semantics of `tr_peerIo::get_write_buffer_space()`: this is
now interpreted as the preferred minimum size, rather than the maximum.
It's OK to enqueue an outgoing piece message as long as there's _some_
space left, even if the message is larger than that space.

Build peer messages with template fold expressions. This lets us move
all the message-building to a single function and add some sanity checks
to the outgoing messages.
2023-04-14 19:31:09 -05:00
Charles Kerr 9158ae7126
feat: add tr_bitfield::intersects() (#5155) 2023-04-14 18:45:46 -05:00
Charles Kerr ed4919a4f4
feat: Add BufferWriter class (#5154) 2023-04-14 17:08:01 -05:00
midzer 68e965aa28
perf: pass by reference (#4876) 2023-04-14 17:06:26 -05:00
Charles Kerr d445c7f061
fix: crash in peer stats (#5279) 2023-04-14 16:03:08 -05:00
Charles Kerr d72cb67cfb
chore: include directory name in libtransmission #includes (#5308) 2023-04-14 14:33:23 -05:00
Pierre Dubouilh ebfba686b0
feat: sequential download (#4795) 2023-04-14 11:47:54 -05:00
Cœur afa9f64feb
refactor: align tr_formatter_speed_KBps with `stringForSpeed: kb: mb: gb:` (#5108) 2023-04-14 10:36:34 -05:00
Charles Kerr 63421489fe
refactor: tr_sys_dir_open() takes a std::string_view (#5380) 2023-04-14 09:31:46 -05:00
Charles Kerr 0e2b8d721c
fix: only torrent metainfo display-name as a fallback (#5378)
Fixes #5347.
2023-04-12 17:26:43 -05:00
Charles Kerr e33d9536ef
fix: return success on RPC add-torrent duplicate (#5370)
Keep Transmission 3's behavior to avoid unannounced API change
2023-04-12 13:37:04 -05:00
Cœur 91717fe91d
fix: potential NSString leak in tr_strv_convert_utf8() 2023-04-11 17:36:22 -05:00