Commit Graph

183 Commits

Author SHA1 Message Date
Yat Ho
25d2ebf8fc refactor: overhaul tr_address special address checks (#7818)
* refactor: rewrite is_martian_addr() with tr_address methods

- Fix broken check for IPv4 multicast address in is_martian_address()

* refactor: rewrite is_global_unicast_address()

- Rewrite using new tr_address methods
- Add missing IPv4 loopback check
- Follow RFC 4291 IPv6 global unicast definition
- Fix and update existing tests

* chore: reorganise methods and add comments

* fix: check for teredo and 6to4

* test: tests for new methods
2025-11-21 18:09:38 -06:00
Yat Ho
4318a6f1ac fix: caching a source address doesn't imply public internet connectivity (#7520) 2025-11-12 14:46:26 -06:00
Yat Ho
ace36c922d refactor: replace all evutil_make_listen_socket_ipv6only usages (#7779) 2025-11-08 16:36:54 -06:00
Yat Ho
b3424ed260 feat: match IPv4-mapped addresses with IPv4 whitelist (#7523)
* feat: match IPv4-mapped addresses with IPv4 whitelist

* test: for converting IPv4-mapped to native IPv4

* perf: avoid copying in `tr_wildmat()`
2025-11-07 20:26:45 -06:00
Yat Ho
49c099f6fa refactor: add more details to logs in ip cache (#7525)
* refactor: add more details to error logs in ip cache

* refactor: improve logs for ip cache set methods

* code review: warn if cannot obtain any source address

* refactor: error if cannot obtain any source address

* code review: better variable naming
2025-10-16 08:44:53 -05:00
Yat Ho
58c4386ddd fix: correctly get Windows socket error codes in get_source_address (#7524)
* fix: use correct error codes in `get_source_address()` on windows

* fix: get `sockerrno` value before closing socket
2025-10-15 19:21:00 -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
76ab7ba592 refactor: set peer io socket in constructor (#7355)
* refactor: `tr_netOpenPeerSocket()` returns `tr_socket_t`

* refactor: store preferred transport as array

* refactor: set peer io socket in constructor

* refactor: remove `log_peer_io_bandwidth()`

This partially reverts commit efec6505

* refactor: rename `tr_netOpenPeerSocket` to snake_case

* code review: remove redundant comment

* code review: add comment about array order
2025-03-03 23:47:37 -06:00
Charles Kerr
6132706565 chore: iwyu (#6864)
* chore: do not include <set> unless we use it

* chore: do not include <map> unless we use it

* chore: do not include <string> unless we use it

* chore: do not include <list> unless we use it

* chore: do not include <memory> unless we use it

* chore: do not include <optional> unless we use it

* chore: do not include <functional> unless we use it
2024-05-27 17:36:02 -05:00
Yat Ho
4657d210ba feat: dual stack udp tracker support (#6687)
* chore: housekeeping

* refactor: reduce copying when building payloads

* feat: dual-stack udp tracker support

* refactor: convert function names to snake_case

* fix: `readability-identifier-naming` warning

* fix: account for dual-stack in tests

* code review: add prefix to global names

* fix: don't resolve to IPv4-mapped address

* refactor: use `tr_address` method to check ip protocol

* fix: workaround MSVC x86 build failure

* fix: handle host components that has square brackets

* Partial Revert: "fix: account for dual-stack in tests"

Not needed anymore

* fix: store ipv6 peers in pex6

---------

Co-authored-by: Charles Kerr <charles@charleskerr.com>
2024-05-26 15:43:55 -05:00
Yat Ho
d6f5e60a35 feat: ipv6 lpd (#6700)
* feat: ipv6 lpd

* feat: find interface index from ip address

* refactor: use `tr_socket_address::from_string()`

* fix: enable multicast loop

* chore: housekeeping

* refactor: dedupe `if_nametoindex()` call

* refactor: rename `mcast_socket_` to `mcast_sockets_`

* code review: fix variable name typo

* code review: unify comment styles

* fixup! code review: unify comment styles

* code review: explain 15KB in Win32 interface index code
2024-05-26 00:04:50 -05:00
Dzmitry Neviadomski
0e25584e78 Make std::hash specialization for tr_socket_address a struct (#6788)
To be in line with std::hash declaration

See https://en.cppreference.com/w/cpp/utility/hash

Signed-off-by: Dzmitry Neviadomski <nevack.d@gmail.com>
2024-04-20 21:01:47 -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
Charles Kerr
42b09b22df refactor: reduce utils.h includes (#6431) 2023-12-24 11:02:54 -06:00
Charles Kerr
581d9c34cc fix: gcc-13 warnings pt. 2 (#6404)
* fix: tr_priority_t usage warnings

* build: disable -Wnull-dereference warnings when building GTest

* fix: -Wunused-result warning in tr_spawn_async()

* fix: -Warray-bounds warning in NetTest::compact4()
2023-12-23 10:32:04 -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
5a6f0a5623 fixup! refactor: re-organise net.h member functions (#5878) (#5933)
* fix: check if address is valid in `tr_address::is_any()`

* refactor: add static implementation of `tr_address::is_valid()`
2023-10-25 11:53:46 -04:00
Yat Ho
c70c49e87b fix: encode ip in network byte order for udp announce (#6126) 2023-10-18 09:46:57 -05:00
Yat Ho
eea7d4d886 refactor: re-organise net.h member functions (#5878) 2023-08-17 22:13:01 -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
a9a6e54858 refactor: make tr_socket_address a class (#5772) 2023-07-12 17:29:47 -05:00
tearfur
78367c098f perf: use std::unordered_map for tr_swarm.pool and Handshakes (#5740) 2023-07-11 11:57:29 -05:00
tearfur
5ec4ca550e chore: iwyu (#5746) 2023-07-08 10:24:03 -05:00
tearfur
97da2adbca fix: spelling mistake in net.h function call (#5739) 2023-07-07 20:13:02 -05:00
Charles Kerr
f83a60830a refactor: add tr_socket_address typedef (#5730) 2023-07-05 11:33:50 -05:00
tearfur
8543555584 refactor: use std::pair to store socket addresses (#5723) 2023-07-04 20:29:12 -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
tearfur
474a30ab2d feat: add global IP cache, fix UDP connection failure warnings 2023-05-05 12:17:40 -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
Julien
4b8cfa2e57 chore: update copyrights to 2023 (#4834) 2023-02-11 14:49:42 -06:00
Cœur
c89edcd1f6 underscores in documentation comments should be code escaped (#4639) 2023-01-23 10:26:11 -06:00
Charles Kerr
7367d465b5 style: use the new paragraph comment style everywhere (#4634) 2023-01-22 13:21:30 -06:00
Charles Kerr
9678b26984 refactor: misc-use-anonymous-namespace pt. 3 (#4539) 2023-01-07 08:27:54 -06:00
Charles Kerr
b47c34726b refactor: tr_peer_socket keeps track of peer count (#4534) 2023-01-04 15:37:55 -06:00
Charles Kerr
611b181a99 feat: add yourip to extension protocol handshake (#4504)
* feat: add yourip to the extension protocol handshake
2023-01-01 12:20:46 -06:00
Charles Kerr
5ce503f1ab refactor: udp_core constructor (#4469)
* refactor: udp_core constructor

* refactor: invert dependency between tr_session.publicAddress() and tr_globalIPv6()
2022-12-28 02:03:35 -06:00
Charles Kerr
ab9e971903 refactor: tr_globalIPv6() returns a std::optional<tr_address> (#4464) 2022-12-25 07:55:51 -06:00
Charles Kerr
a3f561bcc0 refactor: add tr_address.is_global_unicast_address() (#4462)
Was previously private to net.cc. Expose here so that we can add tests.

Add tests.
2022-12-24 18:53:50 -06:00
Charles Kerr
14a3d01e45 fix: sonarcloud (#4453) 2022-12-23 10:56:27 -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
36edd516aa refactor: replace tr_boundinfo with tr_session::BoundSocket (#4103) 2022-11-06 10:35:48 -06:00
Charles Kerr
ee8a6bd130 refactor: simplify blocklist code (#4086) 2022-11-03 15:46:27 -05:00
Charles Kerr
611d36ac84 refactor: decouple session settings from the session class (#4053) 2022-11-01 19:32:26 -05:00
Charles Kerr
798e873b87 fix: sonarcloud warnings (#4023) 2022-10-24 22:13:09 -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
572e1bb50f refactor: add tr_address::fromSockaddr() (#3964)
* refactor: remove TR_DISCARD_ALIGN

* refactor: add tr_address::fromSockaddr()
2022-10-14 01:20:39 -05:00