Commit Graph

1616 Commits

Author SHA1 Message Date
Fletcher Dunn f266d3138b ICE client: Send TURN CreatePermission requests 2026-05-27 11:16:30 -07:00
Fletcher Dunn e09fbc9616 ICE client: simplify STUN/TURN requests
- Move 'factory' functions to be methods on ICESessionInterface
- Delete CRecvSTUNPktCallback, callback can be just a simple pointer to
  method
- Serialize the request once instead of saving off attributes and
  complicated memorty management.
2026-05-27 10:10:37 -07:00
Fletcher Dunn d41a4db85c ICE client: Add logic to gather relay candidates from TURN servers 2026-05-27 08:39:55 -07:00
Fletcher Dunn ea9c4ade95 test_p2p.cpp now understands --turn-server 2026-05-27 08:33:55 -07:00
Fletcher Dunn 75f621aadb Test STUN server now supports minimal TURN features 2026-05-27 08:33:52 -07:00
Fletcher Dunn e5b4615d2e ICE client refactor: Delete list of local candidates
And we don't need ICELocalCandidate at all any more.
This is so much simpler.
2026-05-26 23:45:40 -07:00
Fletcher Dunn 6f6419084e ICE client refactor: Simplify
Delete UpdateHostCandidates, just create the host candidate immediately
when we create the interface.

Also delete ICECandidateBase::CalcPriority.  We only called that when
adding a new local candidate, so just do the work directly in the
constructor.
2026-05-25 23:35:12 -07:00
Fletcher Dunn e735bc0329 ICE client refactor: ICECandidatePair stores local interface
Not the local candidate!  A "local candidate" is a thing that we need to
tell our peer about, but when we need to send or receive packets, we
use a socket.  When a socket has a host candidate, a server reflexive
candidate, etc, we don't really know or care which of those candidates
the peer used to talk to us.

Also, deleted IsCandidatePermitted.  We need this, but the place we were
calling it was wrong.
2026-05-25 23:35:12 -07:00
Fletcher Dunn fd500ef8ba ICE client refactor: simplify parsing flow
Delete UnpackSTUNHeader and IsValidSTUNHeader.  Combine them and
expand them inline at the only place we need to do this.

Rename DecodeSTUNPacket to ParseSTUNAttributes.  It will get a copy
of the header already parsed, and will assume that the packet has
already been verified to be STUN.

Rename CSteamNetworkingSocketsSTUNRequest::OnPacketReceived to
ReplyPacketReceived and pass in what we have already parsed.
Delete return value, which was unused by only call site also
referred to silly nonsensical constants
2026-05-25 23:35:14 -07:00
Fletcher Dunn 60314c1606 ICE client refactor: Each Interface knows what session owns it
Socket callback will be the interface pointer, which gives us
a little bit more context and makes a few things simpler.
2026-05-25 23:35:13 -07:00
Fletcher Dunn 2a9bedc599 ICE client refactor: Delete ICELocalCandidate::m_base 2026-05-25 18:00:38 -07:00
Fletcher Dunn 3d29fc0a08 ICE client refactor: local candidates remember the interface
This removes several places where we need to lookup the interface.
But since we are storing a pointer, it means now we need to make sure
and carefully cleanup if an interface drops out of the interface list.
2026-05-25 17:52:31 -07:00
Fletcher Dunn 14e01af87d ICE client refactor: Move m_base to local candidate only 2026-05-25 17:52:28 -07:00
Fletcher Dunn 47300da67b ICE client refactor: candidate type from address not base 2026-05-25 17:52:27 -07:00
Fletcher Dunn 9032a75a17 ICE client refactor: Candidate type enum
There was a nested type CSteamNetworkingICESession::ICECandidateType,
which was named very confusingly similar to EICECandidateType.  That
type uses different enum values based on the address family.

Renamed it to ICECandidateKind, made it an enum class, and promoted
to global scope.

Also, moved RFC5245CandidateAttr so we don't have to forward declare
it.
2026-05-25 17:52:24 -07:00
Fletcher Dunn bfdefb73af ICE client refactor: Handling of received peer candidates
RFC5245CandidateAttr now store the address directly, nor address string
and port.
AddPeerCandidate will receive this directly, and return the type
2026-05-25 17:52:23 -07:00
Fletcher Dunn 390d19d1ff ICE client refactor: Add ICELocalCandidate derived type 2026-05-25 17:52:23 -07:00
Fletcher Dunn 24dd247196 ICE client refactor: each interface owns 0/1 STUN requests
A STUN requests knows what interface it came from
No need for a separate list of STUN requests or keepalives
2026-05-25 15:00:50 -07:00
Fletcher Dunn d01e782ae8 ICE client refactor: Rename Interface to ICESessionInterface 2026-05-25 15:00:50 -07:00
Fletcher Dunn fdd7f515ed ICE client refactor: Don't store local address redundantly
The socket knows what address it was bound to.
Also added helper function IPAddrEqualIgnoringPort
2026-05-25 15:00:49 -07:00
Fletcher Dunn eb6d0678fa ICE client refactor: Interface owns the socket
Simplify GatherInterfaces

Store the interface vector indirectly.  This makes is so that we don't
have to define the move constructors/assignment, needed so that we can
remove items from the list.  Also, looking ahead, I want the callbacks
to have a pointer to their interface, which will remove a little bit
of lookup work, and this will require stable pointers.
2026-05-25 15:00:33 -07:00
Fletcher Dunn bf19de7778 ICE client refactor: delete m_vecHostCandidateSockets
Just store the socket in the corresponding Interface
2026-05-25 15:00:33 -07:00
Fletcher Dunn 9273c5bcc9 ICE client refactor: Delete unused function GetCandidates 2026-05-25 15:00:33 -07:00
Fletcher Dunn de47bdfa0b ICE client: delete dead code 2026-05-25 13:53:47 -07:00
Fletcher Dunn b7d60c2edf ICE client - document state variables 2026-05-24 18:47:57 -07:00
Fletcher Dunn b88a52c206 Fix dangling pointer bug
If there is more than one STUN server and the name is
shorter than std::string small string optimization size.
2026-05-22 22:22:02 -07:00
Fletcher Dunn 951a3a967b Remove unnecessary call to UpdateFakeRateLimitTokenBuckets
This just spends CPU time with no benefit, and also leads to a
(probably harmless) tsan warning
2026-05-22 21:39:19 -07:00
Fletcher Dunn 19fd53901c test_p2p now supports --repeat 2026-05-22 21:26:57 -07:00
Fletcher Dunn 2ca71d516f Add cases that require IPv6 server reflexive to work 2026-05-21 21:58:17 -07:00
Fletcher Dunn 491d224f10 ICE client supports IPv6 server reflexive candidates 2026-05-21 21:57:27 -07:00
Fletcher Dunn 98d4bada61 ResolveHostname can now accept a literal IP or IP:port 2026-05-21 21:56:19 -07:00
Fletcher Dunn 7a871443ed Test STUN server now supports IPv6 2026-05-21 21:54:09 -07:00
Fletcher Dunn 7db494c6e7 Compiler warnings
P4:10650618
(cherry picked from commit f7e8d96de3)
2026-05-18 15:43:46 -07:00
Fletcher Dunn 3ff74eae0e Setup loopback aliases for p2p tests properly 2026-05-18 07:34:44 -07:00
Fletcher Dunn 3060bfd781 Add IPv6 support to p2p mock framework 2026-05-18 00:05:26 -07:00
Fletcher Dunn f4eb1c6403 Tweak output when setting up aliases 2026-05-17 23:16:53 -07:00
Fletcher Dunn c18d9e3d27 test_p2p will muck with the local network stack
To allow us to bind to other addresses besides 127.0.0.1.
We'll need something similar for IPv6, but for now we only
need it for IPv4 on MacOS
2026-05-17 23:05:23 -07:00
Fletcher Dunn 7515a9e00c test_p2p now deliberately selects ICE implementation
Our implementation honors the mock network.  We know that webrtc has
their own very robust mocking framework they put their own implementation
through.
2026-05-17 22:29:48 -07:00
Fletcher Dunn e3ac0ede5e Imrove p2p tests
Make sure we test a super common and important scenario: two hosts
on the same LAN that *also* have the same gateway, and thus could
talk thorugh a hairpinned public route, but should use the LAN
route instead based purely on priority numbers, not latency
2026-05-17 21:49:51 -07:00
Fletcher Dunn 4aefbf6f16 Improve detection of 'probably local' routes
CConnectionTransportP2PICE_Valve::OnConnectionSelected will check the
prefix len
2026-05-17 21:49:46 -07:00
Fletcher Dunn b63a9d606d GetLocalAddresses now also returns the prefix length 2026-05-17 20:54:27 -07:00
Fletcher Dunn 5888b141c2 Delete some stray spew
I guess it's been here for 4 years
2026-05-17 20:02:24 -07:00
Fletcher Dunn d790bd66e2 Improve P2P mocking framework
There can be more than one gateway.  (E.g. cell connection and local
internet connection.)  Each interface is assigned to one gateway,
or none of the interface is public.

Add ability to tag an adapter as non-functioning.

Simulate network latency.

Add more test cases.
2026-05-17 20:01:31 -07:00
Fletcher Dunn 0e18b7dd57 Confirm route type in p2p test
p2p_test.cpp will print the route type
The runner script will extract it and check that the route type is what
we expect
2026-05-13 22:12:22 -07:00
Fletcher Dunn 9a0293e3bb Remove ping check to decide if a route is 'fast' 2026-05-13 22:12:22 -07:00
Fletcher Dunn 6947ea3064 test_p2p: run local STUN server and test several mock cases. 2026-05-13 22:12:22 -07:00
Fletcher Dunn af470f47f6 Add a STUN server 2026-05-13 22:12:21 -07:00
Fletcher Dunn eb25f201c1 test_p2p: Add option to set stun server 2026-05-13 22:12:21 -07:00
Fletcher Dunn 2cb87c1c82 test_p2p.exe: add command line args to setup mock network 2026-05-13 22:12:21 -07:00
Fletcher Dunn 1ca37d421b Add framework for setting a mock network environment 2026-05-13 22:12:20 -07:00