Commit Graph

224 Commits

Author SHA1 Message Date
Yat Ho 13987e7996
refactor: warn peer incompliant behaviour in ltep (#7203)
* refactor: add log warning for ut metadata in private torrent

* refactor: add log warning for ut pex in private torrent

* refactor: add log warning for ltep handshake without advertised support

* refactor: unify ltep handshake log format

* refactor: removed redundant ltep logs

* refactor: add back log for ut pex
2024-10-27 19:38:56 -05:00
Yat Ho 9ff95d162e
fix: various pex flag bugs and cleanup (#6917)
* fix: allow connection between seeds when pex is enabled

* chore: add comment to explain `tr_peerMsgs::on_torrent_got_metainfo()`

* refactor: remove `tr_swarm::mark_peer_as_seed()`

* fix: update seed flag in response to BT msgs

Regression from 81a42c6bb6

* chore: remove redundant code to update peer seed flag

* refactor: inc failure count if there were no piece data exchanged

* fix: save information from ltep handshake

* refactor: rename `tr_peerIo::is_seed_` to disambiguate

* fix: add instead of set pex flags when adding non-pex and non-resume peers

* fix: don't mark peer as connectable on getting ltep port msg

By BEP-11's definition, this flag is only set for peers whom we successfully initiated an outgoing connection with.

* refactor: set holepunch flag when we get it from ltep handshake

* fix: only accept positive `reqq` in ltep handshake

* refactor: handle encryption preference in `tr_peer_info`

* refactor: prefer own value for utp support

* refactor: make `tr_peer_info::from_first_` const

* refactor: handle holepunch support in `tr_peer_info`

* fix: parse metadata size only if we have a valid extention id for metadata xfer

* refactor: remove `tr_peer_info::add_pex_flags()` as it's no longer needed

* fix: correctly handle holepunch support when there is no `m` key in ltep handshake

* fix: distinguish between upload only and seed

Say we just connected to a partial seed, the peer sends an ltep handshake that has the `upload_only` key, then a BT `Bitfield` message:

Without this change, the pex seed flag would be set when parsing the ltep handshake, then immediately unset when parsing the `Bitfield` message.

We don't want that.

* fix: don't update `tr_peer_info::is_seed_` when merging peer info objects

* perf: priority in peer candidate score need 2 bits only

* fix: prefer to connect to downloading peers

Regression from c867f00153

* chore: add TODO for C++20 opportunity

* refactor: don't filter out peers without `ADDED_F_CONNECTABLE`

revert change from a2849219f7

* refactor: move peer state updates out of peermgr code

---------

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2024-09-08 22:05:03 -05:00
Yat Ho 1b57c294be
fix: process BT messages that immediately follows handshake (#6913)
* refactor: don't loop in `tr_handshake::can_read()`

* fix: return `READ_NOW` after handshake success

* code review: more accurate comment wording

* Revert "refactor: don't loop in `tr_handshake::can_read()`"

This reverts commit 4f33520cba6a38171ed203a071158aa37ddcd325.

* refactor: convert `ReadState` to enum class

* refactor: use new `ReadState` value to break out of loop
2024-08-24 17:04:28 -05:00
Yat Ho b1a765459a
fix: limit number of bad pieces to accept from a webseed (#6875)
* perf: initialise blame bitfield by piece count

* refactor: set blame for all peers

* refactor: make `tr_swarm::add_strike()` work for all peers

* refactor: move `tr_peer::do_purge` to `tr_peerMsgs`

* fix: limit number of bad pieces to accept from a webseed
2024-08-24 14:18:12 -05:00
Yat Ho 62240393ed
feat: configurable client `reqq` (#7030)
* chore: housekeeping

* refactor: raise client reqq value

* feat: allow configuring client reqq value

* feat: expose reqq config in RPC

* test: add new key

* code review: distinguish client vs peer

* docs: fix new config name

---------

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2024-08-23 21:46:37 -05:00
Mike Gelfand c21ee87eea
Add CI configuration for clang-tidy on Windows (#6997)
* Add CI configuration for clang-tidy on Windows

* Fix issues reported by clang-tidy on Windows

* Workaround clang-tidy defects on Windows

* Fix C-style casts (which clang-tidy didn't report)
2024-07-16 22:13:29 +01:00
T Reardon 7f79cb16ee
chore: clarify DhtPort specific usage (#6963) 2024-07-11 01:42:47 +01:00
Yat Ho 5f091fac18
refactor: store peer info objects in shared pointers (#6614)
* chore: housekeeping

* refactor: store peer info objects in shared_ptr

* refactor: minimise insert/erase operations to the peer info pool

* refactor: unify `on_got_port()` exit point to simplify cleanup

* fix: use `std::unordered_map` as a stand-in for `small::map`

* refactor: use small maps but with `std::vector` as base

* fix: suppress goto warning

* refactor: use `small::map`

* fix: remove constexpr
2024-05-25 19:13:15 -05:00
Yat Ho 152f3e91a5
refactor: convert `tr_peerMsgsImpl` helper functions to class methods (#6580)
* refactor: update bep links

* chore: use more appropriate data types

* chore: checkpoint

* refactor: split `can_request()` into each of their own different signature

* chore: checkpoint

* refactor: convert tr_peerMsgsImpl functions to methods

* chore: checkpoint

* refactor: store peer info as reference

* refactor: convert all member variables to private

* chore: re-arrange methods

* refactor: optimise tmp vector default size in `send_ut_pex()`

* chore: housekeeping

* chore: housekeeping

* refactor: avoid `dynamic_cast` when sending cancel

* fix: restore `blocks_sent_to_peer` stat

regression e91af26923

* fix: choke first then reject

* refactor: convert `tr_peerMsgsNew()` to static factory function

* refactor: store `tr_torrent` reference instead of pointer

* Revert "refactor: store peer info as reference"

This reverts commit bb419bf2

---------

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2024-03-15 19:52:09 -05:00
Charles Kerr b1b685af3f
refactor: make tr_torrentReqIsValid() private (#6620) 2024-02-18 16:00:13 -06:00
Charles Kerr eeea3c540f
fix: clang-tidy-19 warnings (#6597)
* fix: readability-redundant-casting warnings in libtransmission

* fix: readability-avoid-return-with-void-value warnings in libtransmission

* fix: readability-redundant-member-init warnings in libtransmission

* fix: readability-redundant-inline-specifier warnings in libtransmission

* fix: performance-avoid-endl warnings in libtransmission

* fix: bugprone-multi-level-implicit-pointer-conversion warnings in libtransmission

* fix: bugprone-switch-missing-default-case warnings in libtransmission

* fix: readability-redundant-string-cstr warnings in libtransmission

* fixup! fix: bugprone-multi-level-implicit-pointer-conversion warnings in libtransmission
2024-02-13 10:42:19 -06:00
Yat Ho ca11c33d05
fix: various DHT bugs (#6569)
* fix: unconditionally send DHT Port msg if supported

* chore: add "maybe" to dht add_node functions

* feat: change `bind-address-ipv*` defaults to empty string

* chore: housekeeping

* fix: initialise DHT node id with random bytes

* chore: housekeeping
2024-02-04 12:18:01 -06:00
Charles Kerr 239478925f
fix: performance-enum-size warnings (#6504) 2024-01-08 08:32:58 -06:00
Charles Kerr 3f6969217c
chore: remove FMT_STRING macros (#6497) 2024-01-06 14:05:18 -06:00
Yat Ho 10d047005a
refactor: convert `tr_incomplete_metadata` to c++ class (#6383)
* refactor: unset peer BEP-9 support if size hint is invalid

* fix: open torrent file in binary mode

* refactor: move metadata size check to method

* refactor: remove duplicate checks

* refactor: reduce temp variable scope in `parseLtepHandshake()`

* refactor: convert `get_piece_length()` to method

* refactor: convert `tr_torrentSetMetadataSizeHint()` to method

* refactor: convert `tr_torrentGetMetadataPiece()` to method

* refactor: convert `tr_torrentUseMetainfoFromFile()` to method

* refactor: convert `tr_torrentSetMetadataPiece()` to method

* refactor: convert `tr_torrentGetNextMetadataRequest()` to method

* refactor: convert `tr_torrentGetMetadataPercent()` to method

* refactor: add basic framework for MagnetMediator

* refactor: initialise `tr_incomplete_metadata` fields in constructor

* refactor: check metadata transfer completion in `set_metadata_piece()`

* refactor: convert `use_new_metainfo()` and `on_have_all_metainfo()` to methods

* refactor: move parts of `tr_torrent::set_metadata_piece()` into `tr_incomplete_metadata`

* refactor: move parts of `tr_torrent::get_next_metadata_request()` into `tr_incomplete_metadata`

* refactor: move parts of `tr_torrent::get_metadata_percent()` into `tr_incomplete_metadata`

* refactor: hide all `tr_incomplete_metadata` fields

* refactor: move `incomplete_metadata` to private

* feat: add test for `set_metadata_piece()`

* refactor: unify integer types

* refactor: rename `tr_incomplete_metadata` to `tr_metadata_download`

* chore: make clang-tidy happy

libtransmission/torrent-magnet.cc:117:68: warning: comparison of integers of different signs: 'long' and 'const uint64_t' (aka 'const unsigned long') [clang-diagnostic-sign-compare]

* refactor: pass log name to `tr_metadata_download` constructor

* chore: iwyu

* fix: thread-safe `TorrentMagnetTest.setMetadataPiece`

* chore: housekeeping

* Revert "fix: thread-safe `TorrentMagnetTest.setMetadataPiece`"

This reverts commit 2a7fcd93a262888f9f55d542b1a9a2da9ca72cea.

* fix: stop soon instead of stop now in `on_metainfo_completed()`

This is unreachable code now, but if it is ever reached, Transmission
will very likely crash.

* fix: maybe fix OpenBSD test failure
2024-01-02 21:04:17 -06:00
Yat Ho fe95914558
fix: use correct time to determine write buffer size (#6414) 2023-12-23 09:28:43 -06:00
Yat Ho 4b882b1bad
fix: sometimes stuck magnet metadata transfer (#6364)
* fix: don't check `total_size` against `metadata_size_hint`

* refactor: remove `metadata_size_hint`

* refactor: restart metadata transfer from scratch on failing
2023-12-16 08:47:55 -06:00
Charles Kerr 3cd66899fe
refactor: remove prefetch (#6332) 2023-12-04 11:45:37 -06:00
Charles Kerr 2e46bad22d
refactor: constify the inout module (#6328)
* refactor: move tr_preallocation_mode info tr_open_files

* refactor: remove unnecessary error nullptr check

* refactor: use snake_case for private method names in inout.cc

* refactor: extract-method get_fd() from read_or_write_bytes()

* refactor: make function args const where possible

* refactor: simplify read_or_write_bytes()

* refactor: make buflen a uint64_t in read_or_write_piece()

* refactor: move tr_torrentStop() logic from read_or_write_piece() to tr_ioWrite()

* refactor: make tr_ioFoo() functions take a const torrent

* refactor: make tr_cache::close_torrent_files() take a tor_id instead of a torrent
2023-12-02 14:16:36 -06:00
Charles Kerr d766050dd8
perf: fewer temporary strings (#6325)
* perf: parse the .resume file contents inplace

* perf: use unmanaged strings in make_torrent_field()

* perf: accept moved strings in tr_error::set()

* perf: use small::vector in tr_peerMsgsImpl::sendPex()

the expected pex size is predictable and fits easily on the stack
2023-12-01 16:48:16 -06:00
Charles Kerr 64d9d57363
chore: fix minor clang-tidy warnings (#6275) 2023-11-21 09:02:03 -06:00
Charles Kerr 8ebb5b0bc3
refactor: Values pt. 4 - use Speed in peer_mgr, peer_msgs (#6241) 2023-11-12 14:38:27 -06:00
Charles Kerr 0e85befc0f
refactor: Values pt. 3 - use Speed in tr_session (#6235) 2023-11-12 12:30:37 -06:00
Charles Kerr a575be778f
refactor: Values pt. 2 - use Speed in tr_bandwidth (#6234) 2023-11-10 17:12:24 -06:00
Yat Ho a2b547fb50
chore: iwyu (#6201) 2023-11-03 12:03:26 -05:00
Julien 8ac323d5d6
chore: removed copyright timespans in headers (#4850) 2023-11-01 16:11:11 -05:00
Yat Ho d224985ef8
fixup! perf: cut down excess copying when downloading (#5907) (#6169) 2023-10-27 00:19:24 -04:00
Yat Ho 6e7fdef721
perf: cut down excess copying when downloading (#5907)
* refactor: directly copy from socket to incoming payload

* refactor: directly process the incoming field

There is no need to copy the payload to a new buffer before processing.

`process_peer_message()` isn't going to return until it's done, and nothing else is going to mess with the incoming field while inside `process_peer_message()`.

* refactor: remove while loop

* add assert
2023-10-25 09:51:36 -04:00
Charles Kerr bbc3ce039f
refactor: remove quark support from tr_variant (#6159) 2023-10-24 14:49:23 -04:00
Charles Kerr db96771c80
refactor: add tr_torrent::Error helper class (#6077) 2023-10-08 21:33:34 -05:00
Charles Kerr 59c638c63d
refactor: replace tr_variant::is_*() with tr_variant::holds_alternative() (#5930) 2023-08-21 16:16:54 -05:00
Charles Kerr 5837603b6f
refactor: make tr_variant follow RAII (#5923) 2023-08-20 23:15:23 -05:00
Yat Ho eea7d4d886
refactor: re-organise `net.h` member functions (#5878) 2023-08-17 22:13:01 -05:00
Charles Kerr a4d205612a
refactor: add tr_variant_serde (#5903) 2023-08-17 11:02:45 -05:00
tearfur a2849219f7
feat: split connectable and non-connectable pool (#5801) 2023-08-01 09:56:26 -05:00
tearfur f758cb3597
refactor: avoid code duplication (#5793) 2023-07-17 08:56:57 -05:00
tearfur ca4cb1a675
fix/cleanups to tr_peerMsgsImpl (#5783)
* fix: correct condition to advertise pex support in ltep handshake

1. Advertise pex support regardless of whether the peer had advertised pex support. No reason to give up an opportunity to advertise pex support just because our direct peer does not support it.
2. Check if pex is enabled in global settings as well.
2023-07-14 10:51:52 -05:00
Charles Kerr c867f00153
refactor: replace `peer_atom` with `tr_peer_info` (#5773) 2023-07-14 07:06:25 -05:00
Charles Kerr bc562eb9a5
perf: avoid atom lookup in tr_peerMgrSetUtpSupported() (#5766) 2023-07-12 10:10:20 -05:00
Charles Kerr f036b7c3bf
perf: use small::max_size_vector in tr_torrentGetMetadataPiece() (#5768) 2023-07-12 07:36:16 -05:00
tearfur 5ec4ca550e
chore: iwyu (#5746) 2023-07-08 10:24:03 -05:00
Charles Kerr c364abcb6f
chore: misc-include-cleaner (partial) (#5738) 2023-07-06 10:00:07 -05:00
Charles Kerr f83a60830a
refactor: add tr_socket_address typedef (#5730) 2023-07-05 11:33:50 -05:00
Charles Kerr 2f2ae61d0c
refactor: remove unused function tr_peer.bandwidth() (#5691) 2023-06-29 11:14:05 -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
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 699b3d8416
perf: use a std::map to store peers in `tr_swarm` (#5645) 2023-06-22 15:21:44 -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 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