Commit Graph

866 Commits

Author SHA1 Message Date
Sam V 505c697d0a Fix incorrect nonempty check in ICE initialization 2022-06-16 07:39:44 -07:00
Fletcher Dunn 226eb10818 Add BEGIN_TIER1_NAMESPACE around CUtlBuffer code
This is to help avoid name collisions when static linking.
(See 53bff2cc0d)

P4:7324330
2022-06-15 13:12:31 -07:00
Fletcher Dunn 7012a24e0d A few more platform fixes
- minbase_identify will now check for _GAMING_XBOX_XBOXONE and
  _GAMING_XBOX_SCARLETT.  (And also _GAMING_XBOX)
- Added IsXboxScarlett() and IsXbox()
- A few places in the low level code need to be tweaked based on IsXbox()
  instead of _XBOX_ONE
- Added IsIOS() and IsTVOS()

Deleted some code that was disabling warnings, I don't think it's needed
anymore.

Tweak defines in CSteamNetworkingUtils::GetPlatformString

PS4/PS5 need Microsoft-style __declspec(dllexport)

P4:7324318
2022-06-15 13:09:27 -07:00
Fletcher Dunn 63dadf6492 Do not #define STEAMNETWORKINGSOCKETS_ENABLE_STEAMNETWORKINGMESSAGES by default on console
We really, *really* would prefer people to use the connection-oriented APIs.

P4:7324311
2022-06-15 13:07:14 -07:00
Fletcher Dunn 4e961ee0f2 Add a cast for Nintendo
They insist on using "enum class" and making their parallel version of
Berkely sockets, and I am 100% confident that literally not one single
person actually wants this.

P4:7324300
2022-06-15 13:06:00 -07:00
Fletcher Dunn 83bf588179 Don't customize OpenSSL rand if >= OpenSSL 3.0
The functions are deprecreated and it's breaking the build.

Should fix #236
2022-06-14 17:51:54 -07:00
Fletcher Dunn 09871d2dc4 Improve platform compatibility
Replace a bunch of non-standard defines with standard ones

Don't #define POSIX in public header or test for it.  Fixes #228.
(We shoulkd probably also make this change to Steamworks headers.)

Use IsLinux(), IsPosix(), etc instead of #ifdef LINUX or #ifdef POSIX

Moved some platform socket stuff out of steamnetworkingsockets_platform.h
and into platform_sockets.h.  (none of this is actually particular to
steamnetworkingsockets.)

Some platforms don't have IPv6 support.
2022-06-14 12:04:10 -07:00
Fletcher Dunn 78481e083d Inverted logic in auth caching
P4:7320764
2022-06-14 11:42:35 -07:00
Fletcher Dunn 3f2cc6ea76 Clear the poll list and mark it as needing rebuild in a few key places
This is in case the library is shutdown and re-initialized.

I believe this fixes #230.

P4: 7317139
2022-06-13 11:24:52 -07:00
Fletcher Dunn 0d45cffe03 Include specific libsodium headers instead of monolith 2022-06-13 11:24:16 -07:00
Sam V f6a8c0365d Rework protobuf dependency to use import library
ValveSoftware/GameNetworkingSockets#233
2022-06-13 11:18:32 -07:00
past-due 9a61630e5e [CMake] Explicitly specify CXX_EXTENSIONS ON 2022-06-13 09:13:53 -07:00
Fletcher Dunn 0a42a43bc1 Add CCryptoKeyBase_RawBuffer::EnsureRawDataPtrAvailable
Remove asserts in OpenSSL EVP implemtnation of CEC25519KeyBase::Wipe.  We
might have a raw copy, and that's OK.

(This change was needed to fix some bugs in code that is not part of the
opensource code.)

P4:7307240
2022-06-08 10:59:36 -07:00
Fletcher Dunn 6e8928b2af Add CCryptoKeyBase::BMatchesRawData
Fix bug in SteamNetworkingSockets::InternalSetCertificate incorrectly assuming
that GetRawDataPtr was always available.  It only works for some crypto
implementations.

P4: 7307233
2022-06-08 10:57:07 -07:00
Fletcher Dunn 1838b62e8f Break out code that sets/wipes the raw buffer into separate functions
This is so that derived classes can use them more easily.  (Specifically, to
be able to set the raw buffer without the virtual Wipe() being called.)

Also: WIPE NEEDS TO SECURELY WIPE, not just free the buffer!

P4:7307228
2022-06-08 10:56:12 -07:00
Fletcher Dunn a1ec9538af Refactor code that sets identity and certificates.
This is to enable cacfhing of certificates and relay tickets to a durable
cache, especially on consoles.

- InternalClearIdentity is virtual, this will give the SDR class a chance
  to nuke any existing tickets when we reset our identity.
- Added InternalOnGotIdentity
- Refactored SetCertificate and added some flags so that we can control
  how it interacts with the cache.  Things can get a bit tangled because
  in some sitautions the certificate is how we learn what our identity
  is.

P4:7307221
2022-06-08 10:51:11 -07:00
Fletcher Dunn d9a7295c8c Fix for rare deadlock with P2P callbacks.
When looking up connections by their handle, take both the table and the connection
lock using a timeout.  If we fail, release both locks and start all over.
This will proptect against a deadlock if we take the locks in the opposite order.
We currently don't ever encounter this situation solely within this library.  However,
we did come across a case with P2P callbacks calling into a custom signal handler.
We could probably fix the custom signal handler to not do this, but it seems like
there are going to be other edge cases, and this change is low risk because contention
is low and most lock attempts will succeed immediately.  And deadlocks are very
hard to reproduce and debug.

CR:saml

P4:7307214
2022-06-08 10:47:45 -07:00
Fletcher Dunn a581422fe4 Fix incorrect comment
P4:7307208
2022-06-08 10:45:50 -07:00
Fletcher Dunn c26b044fb3 Add extern "C"
P4:7307202
2022-06-08 10:43:27 -07:00
Fletcher Dunn 53bff2cc0d Add some namespaces around tier0 and tier1 stuff.
This minimizes the chance of name collision when statically linking.
(Especially if game is using some iteration of the Source engine!)

P4:7307196
2022-06-08 10:41:36 -07:00
Fletcher Dunn 644eeb6872 Delete some dead code
P4:7248965
2022-06-08 10:38:05 -07:00
Fletcher Dunn 0e7cd2c79d Fix some silly cosmetic things with IPv6 printing/parsing
Touch up some comments

P4:7246923
2022-06-08 10:34:17 -07:00
Fletcher Dunn 517f463d29 IPv6 text parsing now supports IPv4 dotted decimal
E.g. ::ffff:192.168.2.1

P4:7246897
2022-05-11 09:47:47 -07:00
Fletcher Dunn 792532352e Try to detect if RTTI is enabled at compile time
If not enabled don't use dynamic_cast.  (We only use it for certain debugging
checks.)

It is important to me that you be able to use this lib without RTTI enabled.

p4:7246870
2022-05-11 09:42:55 -07:00
Fletcher Dunn eb09e02ee3 Fix ICE/P2P cmake stuff
ENABLE_ICE means "enable any ICE support, including the native client"
and is on by default.  (Because the native client is not much code.)

Try to build the trivial_signling_server if we are building either
examples or tests, and ENABLE_ICE is set.  The P2P test needs it.
2022-04-26 19:05:57 -07:00
Fletcher Dunn 7d0128ed44 Fix allowed range of P2P_Transport_ICE_Implementation 2022-04-26 19:05:56 -07:00
Gary Wang cf10980a51 fix build under Windows with MSYS2 MinGW64 2022-04-26 18:04:54 -07:00
Fletcher Dunn 41c7d2b76c Link windows system lib using #pragma lib 2022-04-26 17:40:59 -07:00
Fletcher Dunn a39de80f9b Fix a bug which would trigger under very high packet loss.
The basic problem was that we were using m_statsEndToEnd.m_nMaxRecvPktNum
for two purposes:
- The highest numbered we have received, for purposes of jitter calculations
  and duplicate packet rejection.
- The highest numbered packet we want to ack.

But if we decide to drop a packet (to protect against a malicious sender, etc)
and intentionally not ack it, these values won't be the same!  This means we
might be acking packets that we did not actually process!  Fortunately, it only
happened if the fragmentation was extremely high, which only happens when there
is extrenely high packet loss.  Also, only certain cases of "don't ack this"
can cause any problems other than asserts.

The "soak" connection test has been detecting this bug for a while, but I
haven't had a chance to investigate, since it only triggered underly insanely
high packet loss (whichthe test simulates).  But now the soak test passes,
which....is good!

With this change, the role of m_statsEndToEnd.m_nMaxRecvPktNum is only for
duplicate detection.  We track the highest numbered packet that we wish to ack
in the sentinel in m_receiverState.m_mapPacketGaps.  The time when that packet
was received will also be tracked there.  This change actually simplified some
code.

One more change: how we protect against a malicious sender causing our packet gap
map to be too large.  When we go to add a new gap, previously if we were already
at the max, we would immediately abort the function.  Now, we move the handling
of "too many gaps" to be later in the function, and we try to select the "best"
gap to erase, with the goal of minimizing the degregation (very possibly none)
caused by us starting to nack a block of packets that were actually received
(and in fact perhaps previousally acked).

P4:7219136
2022-04-26 16:12:15 -07:00
Fletcher Dunn 0301b8a961 Fix relatively rare packet timing/accounting bug
If there's a packet number lurch and we reset the last received packet
number, we should mark the time when it was received.  Otherwise our
jitter calculations will be off

P4:7219094
2022-04-26 15:58:04 -07:00
Fletcher Dunn 3d470655bc Improved platform compatibility layer
Deleted several places where we were using this pattern:

   <platform 1 code>
   <platform 2 code>
   ... etc

This is a pain when you have some platforms that are under NDA and you
cannot share the code.  Instead I introduced some abstractions that made
it possible to move all of the platform-specific code (at least for NDA
platforms, which are my primary concern right now) to a separate file.
This way, we can just exclude particular files from distribution, rather
that have files that actually differ.

Also changed some platform-defines to more "functional" defines (USE_POLL,
USE_EPOLL, WAKE_THREAD_USING_EVENT, WAKE_THREAD_USING_SOCKET_PAIR) that
make it clear the reason for the #ifdef.  This also means on platforms
that support multiple methods (e.g. Linux) we could switch those options.

Finally, renamed a few things with "SteamDatagram" in the name to
"SteamNetworkingSockets".  I'm trying to have "datagram" refer exclusively
to the relay network, which is only available to Steam partners, and
thus in general should not be present in the opensource code.

P4:7219053,7219056,7219071
2022-04-26 15:47:22 -07:00
Fletcher Dunn b90a657997 Tweaking platform compatibility
Don't #define or check for GAME_CONSOLE.  That's what IsConsole() is for.
Add PS5 defines, add a few PS5 tweaks
Delete some PS3/Xbox360 stuff

P4:7219035
2022-04-26 15:27:02 -07:00
Fletcher Dunn b610cfeafe Only #include <dlfcn.h> if we're gonna actually try to load a library.
(We aren't going to do this on game consoles, where it doesn't exist.)

P4:7218729
2022-04-26 14:05:56 -07:00
Fletcher Dunn 00d19d5b7e Tweak platform detection
Use the IsXxx() functions instead of #ifdef.  That style is more
robust against mistakes.

Also this works on PS5

P4:7218721
2022-04-26 14:04:03 -07:00
Fletcher Dunn 429bb1fe26 Implement socket polling using epoll() where it is supported.
This is a fine change and all, probably a small optimization.
The real reason to do it is to make the PS5 port easier.

I have to admit that it totally worked the very first time, which
is kind of scary -- obviously something is deeply broken.  If so,
it is possible to switch back to regular polling by just defining
USE_POLL instead of USE_EPOLL

P4:7194744,7194845,7194874
2022-04-08 15:43:15 -07:00
past-due 1bb2cc4901 Implement CCrypto::GenerateHMAC for libsodium using sha1-wpa implementation 2022-04-08 14:54:25 -07:00
Fletcher Dunn 105f2574a6 A few small fixes with my last change for TURN servers. 2022-04-08 11:07:45 -07:00
Fletcher Dunn 82c4d96952 Restore support for TURN servers after big refactor.
FYI @LeventSevgili.  I don't have a test case for this, so I might have
broken something
2022-04-08 10:43:43 -07:00
Fletcher Dunn 16ed11b99d Fix build when ICE isn't enabled
Add some '#ifdef STEAMNETWORKINGSOCKETS_ENABLE_ICE's in a few places
2022-04-08 10:10:58 -07:00
Sam Lantinga 0d6f6e286b Compile fixes
P4:7194314
2022-04-08 09:45:15 -07:00
Jeff Hill 3981d80977 Hook up ping estimates in our ICE client
This is especialy important when SDR is available, so that we can know
whether the relayed route is faster than the "direct" route.

P4:7194299
2022-04-08 09:43:56 -07:00
Fletcher Dunn 357d2b8dcb Firm up some stuff wrt locking and object lifetimes.
Added some comments that clarify the rules around which locks must be held
to access which objects.

Added assertions to verify the appropriate locks are held, and provide better
feedback if a particular step takes a long time.

Move the sending of the initial auth message into shared code.

Deleted some code that was checking for a NULL m_pICESession.  That shoud
never happen based on the lifetimes of these objects.  It definitely
indicates a bug and I think it's fine to crash if it happens.

P4:7194292
2022-04-08 09:35:24 -07:00
Fletcher Dunn 286705e971 Tidy up a few little things
(This is actually the result of making some bigger changes and then
reverting most of them after realizing that they were, in fact, dumb.)

P4:7194283
2022-04-08 09:33:07 -07:00
Fletcher Dunn 222c10e556 Move shared stuff to CConnectionTransportP2PICE::LocalCandidateGathered.
Also added some notes on ping times and locking that need to be
investigated.

p4:7194271
2022-04-08 09:09:42 -07:00
Fletcher Dunn 85c9d73e69 Oops, some build fixes.
P4:7194267
2022-04-08 09:07:13 -07:00
Jeff Hill 63d24d08f6 Use common config interface for our ICE client.
Use the same enums and structures.
Also respect the permitted candidate types mask.

P4:7194247
2022-04-08 08:54:52 -07:00
Fletcher Dunn bce89efa90 Delete CSteamNetworkingICESession::m_nPort and the constructor argument to specify it.
ICE should always use ephemeral ports.  Binding to particular local ports
doesn't really make any sense.  This was originally added as a result of some
confusion regarding what "virtual ports" for for.

P4:7194241
2022-04-08 08:52:05 -07:00
Fletcher Dunn f5ca757344 More WebRTC / ICE refactor
Move quite a bit of ICE code out of steamnetworkingsockets_p2p.cpp and into
steamnetworkingsockets_p2p_ice.cpp

P4:7194240
2022-04-08 08:50:46 -07:00
Fletcher Dunn a95ada8e42 More WebRTC / ICE refactor
Move the generation of the ICESessionConfig into the common P2P code, since
none of it was specific to WebRTC.

Still need to do some refactoring of the Valve client, but checking in this
checkpoint as the code is working again.

Also, I'm aware that I have lost the configuration of the TURN servers.
Will add that back after I'm done with this big merge and refactor.  I hit
some merge conflicts.

P4:7194237
2022-04-08 08:48:08 -07:00
Fletcher Dunn 65ab4b7c6c Reorg ICE / WebRTC files
Split out WebRTC ICE client implementation into its own file.

Split out some ICE-related types that we want to share between any ICE client
into ice_client_types.h.  The goal here is to have our own client and the
WebRTC client have a similar setup interface.

P4:7194217,7194221,7194235
2022-04-08 08:46:49 -07:00