Commit Graph

185 Commits

Author SHA1 Message Date
Yat Ho
0715897fc8 feat: use canonical peer priority to decide which peers to keep (#6981)
* feat: CRC32-C

* feat: canonical peer priority calculation bep-40

* test: add test cases for IPv4 canonical peer priority

* refactor: compare by canonical priority

* fix: use network byte order for peer ports

* test: more cases

* build: xcode

Co-authored-by: Dzmitry Neviadomski <nevack.d@gmail.com>

* ci: test system crc32c library

---------

Co-authored-by: Dzmitry Neviadomski <nevack.d@gmail.com>
2025-10-25 12:05:20 -05:00
Yat Ho
08ec7fb7c7 build: lint header files with clang-tidy (#7527)
* build: clang-tidy headers when building libtransmission

* chore: revert `= default` workaround

It was introduced in 6909ec0bad to fix build issues with macOS 10.14. We
no longer support that version.

* fix: clang-tidy warnings for libtransmission

* build: clang-tidy headers when building tests

* fix: clang-tidy warnings for tests

* build: clang-tidy headers when building qt

* code review: don't manually edit mime-types.h

* code review: unify variable naming for static private members
2025-05-07 22:10:16 +01:00
Yat Ho
1054ba4ab6 refactor: store peers as benc in resume file (#6892)
* refactor: add `tr_pex::to/from_variant()`

* refactor: store peers as benc in resume

* fix: discard invalid pex in `tr_pex::from_variant()`

* fix: limit number of peers loaded from resume
2025-03-08 12:19:18 -06:00
Yat Ho
7e4b4f10a1 refactor: faster wishlist (#7027)
* chore: housekeeping

* perf: short circuit peer has block check

* refactor: track active requests in each respective peer

* refactor: swap `ActiveRequests` with new request tracking method

* refactor: use bitfield to store active requests per peer

* perf: check active request numbers first

* refactor: initialise candidate values in constructor

* refactor: better naming

* refactor: use `find_by_block()` more

* refactor: store wishlist mediator in swarm object

* test: make it compile

* test: update endgame test

* test: new test for choke event

* test: remove redundant lines

* test: new test for request event

* test: new test for reject event

* refactor: cache block have state in wishlist

* test: fix `gotBlockResortsPiece`

* fixup! refactor: track active requests in each respective peer

* fixup! test: fix `gotBlockResortsPiece`

* fix: count webseeds when calculating active requests

* build: update xcode project

* fix: add missing `candidates_dirty_` checks

* chore: remove old `depends-on` comments

* fixup! refactor: use bitfield to store active requests per peer

* refactor: extract block peer event to separate function

* perf: reorder conditions by overhead

* perf: check for completed block instead of completed piece

* chore: remove duplicated "unrequested piece" check

* refactor: merge similar block size sanity check

* refactor: use map to store number of requests in wishlist

* refactor: add asserts

* refactor: flush write buffer as soon as there is new data

* refactor: more accurate function naming

* fix: account for corrupt pieces in wishlist

* fix: account for unaligned blocks in wishlist

* Revert "fix: account for unaligned blocks in wishlist"

This reverts commit c3fce93cbae49c11d62e26caccedf55c1987aa95.

* fixup! refactor: use map to store number of requests in wishlist

* fix: account for unaligned blocks in wishlist v2

* chore: add `[[nodiscard]]`

* fixup! fix: account for unaligned blocks in wishlist v2

* fix: crash when handshake finishes in the middle of function
2024-11-11 19:30:00 -06:00
Yat Ho
49f4c604da fix: don't increment failure count when stopping torrent (#7238)
* fix: don't increment failure count when stopping torrent

* refactor: don't reset failure count on torrent stop
2024-11-08 12:42:59 -06: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
96de1706af perf: restore 3.00 peer info (atom) pool pruning (#6712)
* refactor: remove inactive peer info housekeeping

* refactor: restore atom pulse (now peer info pulse)

* refactor: don't hard cap peer info limit
2024-05-26 16:34:26 -05:00
Yat Ho
20aef2f79d fix: misc net.cc and blocklist.cc fixes (#6717)
* fix: `tr_address` should be invalid by default

* fix: allow loopback address for LPD and incoming connections

* fix: `parseCidrline()` should set address type

* code review: keep `memcmp`
2024-03-24 17:09:51 -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
Yat Ho
348177863a fix: don't consider peer info inactive if any of the time values is 0 (#6606) 2024-02-17 23:46:02 -06:00
Julien
8ac323d5d6 chore: removed copyright timespans in headers (#4850) 2023-11-01 16:11:11 -05:00
Charles Kerr
e54b17d92e refactor: blocklists (#6189) 2023-10-31 19:20:01 -04:00
Yat Ho
88fe76781c perf: connectable pool housekeeping (#6111) 2023-10-19 13:05:19 -05:00
Yat Ho
6cec60f1fb refactor: store outgoing handshake in tr_peer_info objects (#6103) 2023-10-14 12:58:15 -05:00
Yat Ho
eea7d4d886 refactor: re-organise net.h member functions (#5878) 2023-08-17 22:13:01 -05:00
tearfur
badeed374f fix: incorrect pex flags merge logic (#5876) 2023-08-05 12:37:33 -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
Charles Kerr
ea9fd64830 refactor: tr_compare_3way() (#5799) 2023-07-15 21:55:44 -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
tearfur
5ec4ca550e chore: iwyu (#5746) 2023-07-08 10:24:03 -05:00
Charles Kerr
f83a60830a refactor: add tr_socket_address typedef (#5730) 2023-07-05 11:33:50 -05:00
Charles Kerr
56b27057fd refactor: add lightweight observable / observer for decoupling (#5716) 2023-07-04 15:47:18 -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
64261685d8 fix: use both address + port together as a key for peer lookup (#5619) 2023-06-19 20:26:39 -05:00
Julien
4b8cfa2e57 chore: update copyrights to 2023 (#4834) 2023-02-11 14:49:42 -06:00
Charles Kerr
724a0f48f0 fix: clang-tidy header warnings (#4686) 2023-01-28 17:58:20 -06:00
Charles Kerr
d9278bd167 refactor: misc-use-anonymous-namespace pt. 5 (#4552) 2023-01-07 16:55:00 -06:00
Charles Kerr
0a69685a4e refactor: tr_address cleanup (#4338)
* refactor: move tr_tracker_http_announce() helper funcs into their own namespace

* refactor: move tr_globalIPv6() helper funcs into their own namespace

* refactor: move tr_address_is_valid_for_peers() helper funcs into their own namespace

* refactor: make tr_address_compare() a private method

* refactor: rename tr_address::isIPv4() to is_ipv4()

* refactor: use snake_case for tr_address methods

* refactor: make tr_address_is_valid_for_peers() a member function
2022-12-08 20:27:52 -06:00
Charles Kerr
0061e4f9a9 refactor: tr_address::display_name() (#4335) 2022-12-08 16:44:19 -06:00
Charles Kerr
22a3a5db25 refactor: peer-socket pt 2 (#4326)
* refactor: tr_netOpenPeerSocket() now takes a tr_address reference

* refactor: disable copy assignment, copy constructor

* refactor: move log statements to peer_socket constructor
2022-12-06 10:28:28 -06:00
A Cœur
12e564096b fix: "Implicit conversion loses integer precision" warnings (#3960) 2022-10-25 11:14:42 -05:00
Charles Kerr
b32f3e0a24 refactor: add tr_address::toCompact() (#4014)
* refactor: add tr_address::toCompact()

* test: use the theory.org compact ipv4/6 examples in NetTest.compact4, NetTest.compact6

* refactor: add tr_address::toCompact()

* test: add toCompact, fromCompact tests

* refactor: add compact <--> sockaddr_storage conversion
2022-10-24 13:40:12 -05:00
Charles Kerr
d191a04228 refactor: decouple tr_announcer_udp (#4002) 2022-10-21 13:15:14 -05:00
Charles Kerr
4a359fd481 refactor: session private fields (#3961)
* refactor: make tr_session.private_peer_port a private field

chore: make tr_session.public_peer_port a private field

* refactor: make tr_session.web_ a private field

* refactor: make tr_session.lpd_ a private field

* refactor: make tr_session.bind_ipv4_ private

refactor: make tr_session.bind_ipv6_ private

* refactor: make tr_session.bandwidth_groups_ private; add const accessor

* refactor: make tr_session.port_forwarding_ private

* refactor: make tr_session.peerMgr private pt 1: add tr_session::addIncoming()

* refactor: make tr_session.peerMgr private pt 1: add tr_session::addTorrent()

* refactor: make tr_session.peer_mgr_ private

* refactor: make tr_session.setPeerPort() private
2022-10-13 21:25:02 -05:00
Mike Gelfand
f1f55cc3df Sync translations (#3939)
* Sync translations with code

* Sync translations with Transifex

* Remove Mac menu title that isn't displayed and shouldn't be translated

* Add context to logging level strings in GTK client

* Use "µTP" consistently in code

* Use ellipsis instead of three docs in Qt client strings

* Close HTML tags in blocklist-related strings

* Remove trailing space from a translatable string in Qt client

* Add missing plural forms for English strings in Qt client

* Fix spelling: metaInfo -> metainfo
2022-10-11 18:39:41 +03:00
Charles Kerr
c0f29a89ea refactor: add [[nodiscard]] (#3793) 2022-09-08 21:49:51 -05:00
Charles Kerr
1782dc6d7a refactor: use readability-identifier-naming in clang-tidy (#3784) 2022-09-07 11:04:28 -05:00
Charles Kerr
29f57bc296 chore: iwyu headers (#3661) 2022-08-17 11:08:36 -05:00
Charles Kerr
83ffa6bf1b chore: fix spdx abbreviations (#3602) 2022-08-08 13:05:39 -05:00
Charles Kerr
dab81c1af6 fix: readability-inconsistent-declaration-parameter-name warnings in libtransmission (#3572) 2022-08-03 01:15:37 -05:00
Charles Kerr
1a0afbe95e refactor: iwyu (#3525) 2022-07-25 21:45:54 -05:00
Charles Kerr
ba26e79afe refactor: decouple tr_handshake (#3435)
Add a shim between the handshake code and the rest of the codebase to 
improve decoupling so that a followup PR can add handshake unit tests. 

The handshake code no longer directly relies on tr_torrent, tr_session, 
tr_dht, or tr_peerMgr.
2022-07-11 18:29:48 -05:00
Charles Kerr
71bc7143b8 Revert "refactor: tr_address cleanup (#3422)" (#3426)
This reverts commit 9a44eeaa27.
2022-07-09 18:44:20 -05:00
Charles Kerr
9a44eeaa27 refactor: tr_address cleanup (#3422)
* refactor: remove tr_address_compare()

* refactor: remove tr_address_to_string()

* refactor: remove NUM_TR_AF_INET_TYPES

* refactor: replace tr_sessionGetPublicAddress with tr_session::getPublicAddress()

* refactor: tr_peerIo() takes tr_address by value

* refactor: replace tr_sessionIsAddressBlocked with tr_session::isAddressBlocked()

* refactor: tr_peerMgrAddIncoming now takes tr_address by value

* refactor: replace tr_address_is_valid_for_peers() with tr_address.isValidForPeers()

* refactor: tr_netOpenPeerSocket takes tr_address by value

* refactor: remove tr_generateAllowedSet()

* refactor: setup_sockaddr takes a tr_address by value

* refactor: tr_netBindTCP() takes a tr_address by value

* refactor: tr_dhtAddNode() takes a tr_address by value

* refactor: remove tr_address_from_string()

* refactor: rename tr_address.isValidForPeers() to .isValidPeerAddress()

* refactor: replace tr_address_from_sockaddr_storage() with tr_address::fromSockaddrStorage()

* refactor: minor cleanup to tr_address::readable()
2022-07-08 13:23:41 -05:00
Charles Kerr
61c1a0f1e8 feat: add rpc torrentGet.availability (#3252) 2022-06-11 12:06:07 -05:00
Charles Kerr
75a7c5f080 refactor: add tr_peerMsgs.networkSocket() (#3175) 2022-06-01 21:33:33 -05:00
Charles Kerr
cec2195c78 refactor: tr_peerMgrGetPeers() returns a vector (#3142)
* refactor: tr_peerMgrGetPeers() returns a vector

* chore: iwyu <iterator> for std::back_inserter

* chore: iwyu <vector> for std::vector
2022-05-26 20:29:10 -05:00
Charles Kerr
51760bd5c1 refactor: make tr_peerIoGetAddress() a member function (#3141)
* refactor: make tr_peerIoGetAddress() a member function

* refactor: make tr_peerIo.addr a private field

* refactor: make tr_peerIoIsIncoming a member function

* refactor: make tr_peerIoHasBandwidthLeft a member function

* refactor: make tr_peerIoGetPieceSpeed_Bps a member function

* refactor: make tr_peerIoSupportsFEXT() a member function

* refactor: mark tr_peerIo::supportsDHT nodiscard

* refactor: update naming style for tr_peerIo fields

* refactor: make tr_peerIo.is_seed a private field
2022-05-26 12:17:03 -05:00