Commit Graph

158 Commits

Author SHA1 Message Date
Fletcher Dunn 4fbfe83ef4 Semantic change to ISteamNetworkingSockets::SendMessages
Added bDeleteFailedMessages.  By setting this to false, the caller has
the opportunity to retry failed messages, which is an especially
reasonably thing to do in the case of the send buffer being full.

Also clarified expected (and enforced) expected behaviour on
how subsequent messages on a connection are handled after a failed
message send.  Previously, there was a fairly significant bug, which is
that we would coutinue to try to send messages, which is bad because
it can break fundamental guarantees about message delivery order.  Now,
we will always stop at the first failure.

This fixes issue #317
2026-04-28 10:11:25 -07:00
Fletcher Dunn 10fdf237cc Update comment
Arg, I guess this was not staged when I committed earlier
2026-04-26 20:41:54 -07:00
Fletcher Dunn ef74e9027d CreateSocketPair - fix confusing "swapped" identities
They are swapped for historical reasons.  (It's too dangerous/
difficult to change the API to the more intuitive order.)
So, I just added comments to clarify exactly what the behaviour
is, and renamed a bunch of variables to hopefully make the code
more clear, too.

This addresses #404
2026-04-26 19:36:51 -07:00
Fletcher Dunn 8767517e57 Whitespace 2026-04-26 19:36:00 -07:00
Brad Smith a7a0291666 Add OpenBSD support 2026-04-26 17:50:13 -07:00
copyrat90 082aaeab50 Expose flat API for ISteamNetworkingMessages 2026-04-15 16:11:28 -07:00
Pavel Solodovnikov b921fff00a SteamNetworkingIPAddr: fix potentially dangerous -wcast-align warning in IsIPv6AllZeroes()
C-style cast from `uint8*` to `uint64*` is unsafe and can blow up
in cases when the source pointer is not aligned to `uint64` type
requirements.

Signed-off-by: Pavel Solodovnikov <pavel.al.solodovnikov@gmail.com>
(cherry picked from commit 5a7c2dd482)
2026-04-15 15:05:42 -07:00
copyrat90 a3f6174c3b Fix data type for config value SetString() 2026-04-15 12:56:35 -07:00
Fletcher Dunn a246ee39c3 Add a way to read jitter in SteamNetConnectionRealTimeStatus_t 2025-07-24 09:44:00 -07:00
Fletcher Dunn b813c78656 Add k_ESteamNetworkingConfig_SDRClient_EnableTOSProbes
P4:9167134
(cherry picked from commit 13ad238258)
2024-09-08 16:53:42 -07:00
Fletcher Dunn 1812563dd8 Tweak the meaning of the ECN convar.
Now, -1 means "auto" and 0 means "don't set anything".
Add g_nSendECNAuto
Add ResolveECNSendGlobal

P4:9166210,9168032
(cherry picked from commit fcc19e1368)
2024-09-08 16:53:19 -07:00
Fletcher Dunn 7c9f441466 Sync Steamworks SDK headers with 1.60, released in July.
P4:9152589,9152646
(cherry picked from commit 291f32cb6b)
2024-08-30 17:46:56 -07:00
Fletcher Dunn c7ae3cb392 Implement jitter measurement on plain UDP connections.
This is disabled by default.
Added k_ESteamNetworkingConfig_SendTimeSincePreviousPacket to enable it.

NOTE: In order to enable a sender to know whether the receiver will be able
to decode the value, we need to bump k_nCurrentProtocolVersion.

P4:9135136
(cherry picked from commit 14956c67f5)
2024-08-30 11:02:15 -07:00
Fletcher Dunn dfbd38d174 Get this header in sync with partner branch 2024-08-29 16:22:35 -07:00
Fletcher Dunn 1cd5bfe6ab Add a new jitter simulation that does "clumping"
P4:9002451
2024-08-28 16:26:54 -07:00
Fletcher Dunn e4b7cdcf6a Add accessors for other platform identities.
This is in the public SDK, it's not trade secret stuff.
2024-03-13 16:13:54 -07:00
Fletcher Dunn 3590e265de Add IPLocalHost_AllowWithoutAuth
P4:8760985, 8761015
2024-03-13 16:11:20 -07:00
Fletcher Dunn 10364cbca5 Replace k_ESteamNetworkingConfig_SDRClient_DebugTicketAddress with k_ESteamNetworkingConfig_SDRClient_DevTicket
P4:8760688
2024-03-13 15:47:14 -07:00
Fletcher Dunn a4d094b221 Add low-level support needed to automatically correct out-of-order packets.
This is currently only implemented for relayed connections.

P4:8760686
2024-03-13 15:46:37 -07:00
Fletcher Dunn 40db0f6d6b Add k_ESteamNetworkingConfig_SDRClient_LimitPingProbesToNearestN
(Only relevant to SDR.)

Also make duplicate config ID fatal.

P4:8760569,8760585
2024-03-13 15:42:06 -07:00
Fletcher Dunn cd6e08b84f Sync up some Steamworks SDK header files
P4:8760464, 8760706
2024-03-13 15:40:42 -07:00
Fletcher Dunn e0c8ae90e5 Fix some little typos
P4:8312405
2023-09-02 11:06:16 -07:00
Fletcher Dunn cbc94b4801 Add experimental option to set the ECN IP header field
P4:8312400
2023-09-02 10:54:48 -07:00
Fletcher Dunn ae2ef79037 Fix SendRateMin and SendRateMin behaviour and documentation.
The documentation was, uh, aspirational.  Eventually I'd like to have it work
that way, but until we have bandwidth estimation the current behaviour was
really pretty busted.

This fixes #270
2023-05-28 12:54:25 -07:00
Fletcher Dunn d380208d22 Fix bug in CalculateSteamNetworkingPOPIDFromString
Reading past the end of an empty string and not properly returning zero.  (!)

P4:8088056
2023-05-27 17:40:12 -07:00
Fletcher Dunn 323af30e7f Sync up header with Steam
P4:8088053
2023-05-27 17:32:18 -07:00
Fletcher Dunn 356afe93d1 Add SteamNetworkingSockets_SetServiceThreadInitCallback
Also, make sure thread affinity is not set on the playstation.
Tweak thread name from 'SteamNetworking' to 'SteamNetworkingSockets'

P4:8088043
2023-05-27 17:12:38 -07:00
Hussein Ait-Lahcen 222e097c21 flat GetConnectionRealTimeStatus is invalid 2022-08-12 10:06:45 -07:00
Hussein Ait-Lahcen d281c04784 missing GetConnectionRealTimeStatus in flat 2022-08-12 10:06:45 -07:00
Hussein Ait-Lahcen c5b9b77c52 missing ConfigureConnectionLanes in flat header 2022-08-12 10:06:45 -07:00
Fletcher Dunn dbe5a29a94 Add another recv limit to protect against malicious peers
RecvMaxSegmentsPerPacket

This is exceedingly useful for games that only use SteamNetworkingSockets
for "datagram transport" over SDR, and do not want to use the reliability
layer or message fragmentation, reassembly, packing.  In this case,
1 message = 1 UDP packet, and allowing more messages per packet is really
just an opportunity for an attacker to amplify their attack.  Relays
provide packet rate limiting, but since they do not terminate the
encryption, they cannot look inside the end-to-end payload and thus cannot
help enforce message rate limits.

But even for games that are using our framing layer, if you knowyour
traffic pattern and know you never send 500 tiny messages at once, you
can lower this limit and gain a little bit of protection.

We probably are going to need to add a token bucket message rate limiter
at some point.

P4:7421833
2022-08-06 14:36:36 -07:00
Jeff Hill a456c2011f Add configurable recv limits to protect against malicious peer
RecvBufferSize
RecvBufferMessages
RecvMaxMessageSize

P4:7421829,7421830
2022-08-06 14:25:21 -07:00
Fletcher Dunn b8acef56c9 Don't #define VALVE_POSIX
I changed the Steam headers that were checking this (they are not used
in the opensource code) and it is no longer needed.

P4:7380958,7380960
2022-07-15 18:51:55 -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 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 b221ac1a1c Fix incorrect comment describing lan priority
Fixes issue #224
2022-06-08 11:11:36 -07:00
Fletcher Dunn 4b9e27841c Sync up steam headers
P4:7194210
2022-04-08 08:06:41 -07:00
Jeff Hill 23dfdbf5d4 First draft at built-in ICE client.
This means WebRTC won't be necessary to use P2P and NAT punch functionality.

P4:7193749
2022-04-07 18:21:57 -07:00
Fletcher Dunn b794235422 STEAMNETWORKINGSOCKETS_NOSTEAM is now a thing.
(Not really relevant to the opensource code.)

P4:7193707,7193716,7193719,7193724
2022-04-07 17:58:23 -07:00
Fletcher Dunn 8fe64b410d Bring Steam headers in sync with Steam main branch
Also delete some old steam2 stuff we don't need.

P4:7056269
2022-02-04 13:15:46 -08:00
Fletcher Dunn fea0e836d9 Clarify some comments about FakeIP stuff
P4:6986485
2022-01-05 10:55:41 -08:00
Fletcher Dunn 9b794e3077 Fix for flat API generation from Steam.
The render classes should not have a flat interface.  That's not useful.

P4:6894623
2021-11-12 18:36:14 -08:00
Fletcher Dunn 1b0e5ab908 Tweak comment
Mention another reason why we might sometimes deliver messages
out of priority order.

P4:6865690
2021-10-29 17:41:28 -07:00
Fletcher Dunn 9efdab59ce Multiple lane support working!
Visible changes:
- Uncomment ConfigureConnectionLanes
- Rename GetQuickConnectionStatus to GetConnectionRealTimeStatus, and change
  the prototype to return information about multiple lanes.
- Adding a test case to send data on more than one lane and make sure we get
  the priorities we expect.
- Also refactored the test-connection so that you specify what test(s) to
  run on the command line, instead of using the LIGHT_TESTS compile-time
  option.
- Bump interface version numbers.

Internal changes/bugfixes:
- Fix bug with my implementation of fair queuing.  I was always calculating
  the finish time for a lane based on the current virtual time.  But really
  it must be calculated from the time when the previous message in the same
  lane finishes.  Otherwise you don't share the bandwidth properly when it
  alternates lanes.  To keep the implementation simple, I just tag each
  message with the virual finish time.  I believe that this can actually
  cause the virtual time to go in reverse if you queue a message on an idle
  lane and we swap the active lane while sending is in progress.  But I
  think it's OK right now, and we will actually do the right thing and get
  back on track after a message or two.  To make room for this variable,
  I shuffled around how we had shoved in reliable bookkeeping in
  CSteamNetworkingMessage.
- Fix bug selecting the next message to send.  We were ignoring the priority
  classes and just using virtual time!
- Fix some bad hex math encoding and decoding the lane select frame.
- Fix some bugs that were confused about which set of links were used to
  track the list of messages in a particular lane
- Fix bug when serializing segments from multiple lanes, only one of the
  lanes will get to take advantage of the special segment encoding where
  the segment length is implied by the packet size.
- Reorder the fields in SSNPSenderState::Lane to pack them a bit better

Fixes issue #95.

P4:6865294
2021-10-29 16:46:11 -07:00
Fletcher Dunn 5a8ba93040 Improve debug names of stuff
- Added VirtualPortRender, which can be used to show symbolic names to the
  "messages" vport and the fake UDP port vports.
- Replace "vport %d" with VirtualPortRender calls in several debug output
  call sites.
- Improve and refactor CSteamNetworkConnectionP2P::GetConnectionTypeDescription
  to handle fake IP and vports smarter.

p4:6865178
2021-10-29 15:21:54 -07:00
Fletcher Dunn d34d8a25cb Fix for game coordinator lib handling STEAMNETWORKINGSOCKETS_FOREXPORT
P4:6865142
2021-10-29 15:13:54 -07:00
Fletcher Dunn 67782b3a6e First pass at multiple lane support finished
Implement packet decode for the lane select frame.  I have not executed all
this one single time!  (But I have been making sure I haven't broken the
single-lane case.)  If I have not written any bugs, the the feature almost
done!

Remaining work:
- Write test harness, make sure it does actually work...
- Bump versions, deal with old peers who don't understand lanes, etc.

Also, add STEAMNETWORKINGSOCKETS_MAX_LANES.
- Add some optimizations if STEAMNETWORKINGSOCKETS_MAX_LANES is small.
  In particular, STEAMNETWORKINGSOCKETS_MAX_LANES=1 disables support,
  and all the code is compiled out.
- Also this can be used to limit the amount of work a malicious sender
  can make a receiver do.

P4:6819330,6819343
2021-10-08 17:28:37 -07:00
Fletcher Dunn 2b2b5caace More progress on multiple lanes
- Updated wire protocol document
- Implement encoding for multiple lanes.
- Added function declaration to ISteamNetworkingSockets with rather copious
  documentation.  (But left it commented out for now, until it all works).

Remaining work:
- Implement decoding
- Bump versions, deal with old peers who don't understand lanes.
- Add tests

P4:6819091,6819098
2021-10-08 16:10:18 -07:00
Fletcher Dunn 4765afce5d Two changes to the design of lanes
- Added a system for strict priority classes, in addition to the "weight"
  system.  The combination of these two makes for a very flexible system,
  while also hopefully being easy to understand.

- Each lane has its own message number sequence.  This has several
  advantages:
  - It makes it clear that the order of messages between lanes is
    not guaranteed
  - It greatly simplifies packet encoding/decoding.  (Going to make some
    more progress on that next.)

(Based on discussions with jeffreyh@valvesoftware.com.  Thanks!)

P4:6818689,6818692
2021-10-08 14:46:33 -07:00
Fletcher Dunn 744535b052 Groundwork for "lanes".
Lanes are different messages queues with different priority levels.

Work in progress.  This change just adds some data structures, but
the actual wire encoding/decoding not yet implemented.

See also:
- Issue #95
- https://twitter.com/Mokosha/status/1444009029987041281

P4:6806862
2021-10-04 12:19:36 -07:00