45 Commits
Author SHA1 Message Date
Fletcher Dunn b3182a5708 Header/documentation cleanup.
Reorder file to group common functionality together, and put more
common / basic stuff at the top.

Improve comments in general.
2019-03-11 14:12:38 -07:00
Fletcher Dunn 8f53646472 Improve comments.
Added documentation about SteamNetConnectionStatusChangedCallback_t.  This is an
important callback, so it's been pretty bad that it was essentially undocumented
until now.

Also use ESteamNetworkingConnectionState instead of int.  (I have taken steps
to make sure that the enum is the right size.)

The notes about ISteamNetworkingUtils::InitializeRelayNetworkAccess are not
 relevant in the opensource context.
2019-03-11 13:54:44 -07:00
Fletcher Dunn 2e047a3ed5 Add SteamNetworkingIPAddr::operator== 2019-02-26 16:00:24 -08:00
Fletcher Dunn 77682221a0 Bump STEAMNETWORKINGSOCKETS_INTERFACE_VERSION.
(Not relevant to the opensource code, which does not have ABI backwards compat.)
2019-02-26 15:39:16 -08:00
Fletcher Dunn 727b894673 Plumbing changes to be compatible with Steamworks SDK.
In Steamworks, we want to keep the number of odinary DLL imports to an
absolute minimum, because those come from steam_api.dll, which we do
not update.  (The developer needs to take a new one to update their SDK.)
The functions in the interface come from steamclient.dll, which we do
update frequently.

This resulted in the following changes:
* Printing and parsing of SteamNetworkingIPAddr and SteamNetworkingIdentity
  were moved to ISteamNetworkingUtils functions.  Most C++ code will still
  access them through the inline class methods, so they won't really care
  where they are implemented.
* Deleted some hashing functions.  This is not hard to write, and the
  definition of operator= gives you an example of what to do.
* SteamNetworkingMessage::Release will happen through a pointer, so that it
  can be dynamiclaly linked.

Other changes:
* Renamed an old name "STEAMDATAGRAMLIB" to "STEAMNETWORKINGSOCKETS" in
  a few places.
* Use STEAMNETWORKINGSOCKETS_ENABLE_SDR in a few places, to remove
  SDR-specific functionality.  (We might opensource the SDR support code
  in the future.)
2019-02-26 15:27:59 -08:00
Fletcher Dunn 60af1aac8f Pad SteamNetworkingIdentity.
This isn't critical in an environment like this, where we don't have ABI compatibility commitments.  But for the Steamworks SDK this will hopefully be useful.  Once we release a version of an interface, we must support that ABI indefinitely.
2019-02-26 15:03:35 -08:00
Fletcher Dunn 05f98ddf36 Reorder SteamNetworkingMessage_t.
Put essential stuff at the top, less commonly used fields at the bottom.  Also, SteamNetworkingIdentity is a large object, so having it in the middle of the object increased the likelihood of touching multiple cache lines.
2019-02-05 13:14:47 -08:00
Fletcher Dunn 48359cd2aa Correct name of global accessor in Steamworks version.
(No change in this lib because #ifdef)
2019-02-05 13:11:29 -08:00
Steven Noonan 879ea1b70a steamnetworkingtypes.h: fix static library extern "C" linkage
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2019-01-30 13:33:43 -08:00
Fletcher Dunn d7557e558b Improve comments 2019-01-30 12:06:05 -08:00
Fletcher Dunn 5d20204781 Overhaul how configurtion options are set.
Moved them to ISteamNetworkingUtils, which is now actually shared Steam (mostly) with a real accessor and and interface, and not a dummy interface object with all static methods.

Connection settings have a system of inheritance, so they can be set globally, per SteamNetworkingSockets interface, per listen socket, or per connection.

Deleted the config variable to simulate fake *message* loss.  That is not useful.

Introduced STEAMNETWORKINGSOCKETS_ENABLE_SDR define, to make it more clear why code is being #ifdef'ed out.  (E.g. if we open-sourced that code, we would want that included.)

Replaced ESteamNetworkingSendType with a basic flags bitmask.

Cleaned up a bunch of comments.

Changed SteamNetworkingMessage_t release mechanism.  Now the callback is only to free the buffer, and it's assumed that this API will manage the actual objects.  (This is important because the actual type is a derived type and has extra stuff on the end.)  Also laid some groundwork for user management of message objects.  (Relevant for issue #51.)
2019-01-30 10:58:38 -08:00
Fletcher Dunn be9abcde34 Fix SteamNetworkingIPAddr IPv6 bugs. 2019-01-25 18:27:40 -08:00
Fletcher Dunn c7826f5c8d Delete GetConnectionDebugText 2019-01-25 13:32:45 -08:00
Fletcher Dunn e2194a23c7 SetDebugOutputFunction cleanup.
Make it a method of ISteamnetworkingUtils method.  This matches Steam.

Make sure ESteamNetworkingSocketsDebugOutputType is 32-bits, and declare the output callback to take an enum instead of int.
2019-01-23 21:08:10 -08:00
Fletcher Dunn 723c9c4c42 Use 96-bit AES-GCM IV's. Secure the protocol number.
Switched AES-GCM IV's to be 96-bit instead of 128-bit.
- This is what TLS uses (RFC5288)
- This is what NIST recommends (https://dl.acm.org/citation.cfm?id=2206251)
- This is more optimal.  (Certainly for OpenSSL's implementation; I believe it's true in general for GCM.)
- This is the only value that libsodium supports.  Note that we're still using a 32-bit tag, and libsodium only supports the full 128-bit tag (to my knowledge, see #48).  But we might decide to use the full 128-bit tag, and that that point libsodium could be used.

Moved the protocol number out of transport-specific handshake packets to be a "crypt parameter", where it will be signed.  In the future we might need to allow some clients to connect to older clients that have a known security vulnerability (perhaps only during some temporary transition period).  We don't want an attacker to be able to forge the protocol version and force the weaker protocol to be negotiated.

Bumped the protocol version because these are wire-compatibility-breaking changes.

Added a specific error code if a connection fails due to protocol incompatibilities.
2019-01-23 09:18:24 -08:00
Fletcher Dunn b4a439ad87 Oops, forgot a file. 2019-01-16 11:04:09 -08:00
Fletcher Dunn 6f3aaa5b16 Fix use of IPv4 address in SteamNetConnectionInfo_t.
Use SteamNetworkingIPAddr instead.
2019-01-15 17:50:31 -08:00
Fletcher Dunn 7d4e720908 Improve plain C interface.
* Provide plain C wrappers to the inline functions in SteamNetworkingIPAddr and SteamNetworkingIdentity
* Change names to be consistent with the rest of the Steamworks names.
2019-01-14 09:34:20 -08:00
Fletcher Dunn 5f8e50343b Add SteamAPI_SteamNetworkingMessage_t_Release. 2019-01-13 09:28:03 -08:00
Fletcher Dunn b5d76be71f Fix function name.
Fixes issue #32
2019-01-12 18:25:24 -08:00
Fletcher Dunn c50b076099 Delete unused file.
This configuration stuff was moved into the top of steamnetworkingtypes.h
2019-01-12 17:52:47 -08:00
Fletcher Dunn 6722034677 Move all public headers to steam folder, matching the Steamworks SDK layout.
Also moved a bunch of Steam-specific stuff to other files, which are not included in this repository.
Moved high level init/kill to a seperate file, so that isteamnworkigsockets.h won't be cluttered with
a bunch of #ifdefs.

Added IClient interface layer, which is useless in this context, butneeded in Steam, since we
provide backwards compatibility for all old ISteamXxx interfaces.
2019-01-11 17:42:05 -08:00
Fletcher Dunn 5a25561336 Break out high level library init and kill to a seperate file.
This doesn't exist in the Steamworks SDK, so moving it to a seperate file means that the files that are in both branches can have fewer differences.

Deleted the "GameServer" interface.  That is a Steamworks thing.  I'll add another method to create additional interfaces later, if we need them.

CreateSocketPair now allows you to assign the identities to each end of the pipe.

Fix some really basic irritating issues trying to use ordinary UDP and loopback connections without an identity.  Make it more straightforward to just use generic identity with no authentication.
2019-01-10 16:38:44 -08:00
Fletcher Dunn 8a1bbece9a Don't be so presumptuous to give something in the global namespace a generic name CLANG_ATTR. (A macro no less!)
Use a prefix so we don't collide.
2019-01-10 16:38:44 -08:00
Fletcher Dunn d07b7b2eda Sync up with work internally in the Steam code.
* Interface changes:

Replaced all CSteamIDs with SteamNetworkingIdentity, which is an abstract concept.

Added IPv6 support.  This has not been tested at this time, but all the basics
are there and any issues should be small bugfixes.

Improved and standardized connection debug names.  You can set a debug name for a connection,
and the full debug string, which includes the Connection ID, transport-specific data, and
your name (if any) are printed consistently in logging messages and this name is also present
in SteamNetConnectionInfo_t.  Connection handles are now the same as the local ConnectionID
on the wire.  This makes debugging a lot easier.

GetListenSocketInfo renamed to GetListenSocketAddress and now actually does something.

Split out P2P and ordinary UDP listen sockets into two seperate objects.  This simplifies
the opensource code (since P2P is not support)

* Misc internal code cleanup:

Broke up CCrypto monolith, so that we can more easily and cleanly:
- Share what we really want to share with Steam.  Mainly some text parsing of keys, etc.
- Replace the actual crypto primitives with another provider (e.g. libsodium)

Delete a whole bunch of unused and messy cruft that was left when we ripped this out from Steam,
as well as code and messages specific to relayed connections (supported only on Steam)

Switch a bunch of maps to hashmaps instead of red/black tree maps.  The CUtlHashMap class comes
from Steam and is designed to scale to very large size (N in the millions), and if the table
needs to be rehashed, the cost is amortized instead of triggering a large cost all at once.
This functionality is not needed.  Nor do we need stable handles, so it would be better to use
a table based on open addressing.  That would be a small optimization and also allow us to
get rid of bitstring.*, which unfortunately got added as a result of this change.

Added standalone IPv6 address parsing files: ipv6text.*.  These are plain C and do not have
any dependencies, and could be split out, since they are independenctly useful and, unlike
all of our other utility routes (e.g. tier0, tier1, etc), actually worthy of being used
outside of Valve.
2019-01-02 18:27:20 -08:00
Fletcher Dunn 145199aee1 Integrate end-to-end stats tracking acks with SNP data acks.
This not only removes some redundancy, but also is a step towards rejecting duplicate sequence numbers earlier. (#20)

Also rework how hosted dedicated servers are configured, but that is not relevant to the opensource version of this code.
2018-09-10 11:15:28 -07:00
Fletcher Dunn 030a1e6ac6 Set proper struct packing using VALVE_CALLBACK_PACK_SMALL/VALVE_CALLBACK_PACK_LARGE.
Issue #24.
2018-06-04 13:36:24 -07:00
Fletcher Dunn 6c6713ef42 Sync with SteamWorks.
This change is relevant to a feature not included in the opensource code.
2018-06-04 10:39:21 -07:00
Steven Noonan 6360f633ad flat interface: fix most C compilation compatibility
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2018-06-01 16:10:02 -07:00
Fletcher Dunn aac6da50c3 Rework flat interface.
More consistent with what the Steamworks one will look like.  Crazy-long names, intptr_t for ths "this" pointer (I don't understand why, but that's what is done elsewhere), and always pass the "this" pointer, even when it's not actually needed
2018-06-01 15:51:23 -07:00
Fletcher Dunn 3eec58a417 Integ fixes related to Valve-hosted dedicated servers.
(Not relevant for the opensource codebase, just keeping things in sync.)
2018-06-01 12:53:49 -07:00
Fletcher Dunn 7fda0de8af Reorder fields in message struct.
This doesn't put the fields in the "order of importance if youa re trying to understand it" order.
But it does make sure that no matter what the pointer size, everythig is aligned on natural boundaries, with no packing gaps.
2018-06-01 12:51:02 -07:00
Fletcher Dunn 4a7166bd6b Adjust convars for log levels. Make message object plain C struct. 2018-05-22 17:39:05 -07:00
Fletcher Dunn 95cefceec5 Delete Win32-specific debug window.
It's a weird feature and dependency for a library like this to have.
2018-04-26 12:02:02 -07:00
Fletcher Dunn 6b810a8b45 Update comment.
This really isn't relevant for the opensource version of the library, but I'm keeping things exactly in sync with the Steam code.
2018-04-25 18:17:06 -07:00
Fletcher Dunn b1a49aef9d Always send stats inline, never standalone.
Previously there were some cases where the connection code would need to send stats,
and it wasn't able to piggy-back them on a data packet.  A seperate standalone
stats message was used for this.  Changed to plumbing so that the connection code
could initiate sending of an SNP data packet, but ask SNP to not use the whole packet,
and pass through some data, back to the connection-type-specific code.  This way all
stats can be sent inline in a data packet.

This is a step towards getting rid of the LinkStatsTracker's acks.  Those are still
useful for stats on the relay leg of relayed connections, but for end-to-end, SNP
already does acks, and so it's silly and complicated to have two different mechanisms
for this.

Tweaked ack delay values and timeouts.  If the ping was realy low, then if a receiver waited
until the timeout and was forced to flush the acks (no piggy-back opportunity
presented itself), then the sender's timeout was exactly the same, and so there
was no room for error and the ack would just barely timeout.

Also when a packet is NACKed, spew a bit more detail about what actually caused the
nack (either an actual nack from the other side, or ack timeout).

Changed some constants related to PingLocation stuff.  That isn't really applicable
to this lib, but I've made some improvements to that system in the Steam code.
2018-04-23 09:41:34 -07:00
Fletcher Dunn b1a945f1c7 Update comment. VS2015 compile fix. 2018-04-19 23:16:01 -07:00
Fletcher Dunn 2b4112abce Added plain C ("flat") interface. 2018-04-19 22:25:47 -07:00
Fletcher Dunn c178029f02 Rewrite reliability layer and wire format.
This features a robust ack model inspired by Google QUIC,
which allows for minimal retransmission of reliable data.
It should also allow for the rate calculations to be done
by the sender, but that has been temporarily broken.

The wire framing has also been significantly optimized.
2018-04-17 16:18:25 -07:00
Steven Noonan 28c3ee79e1 make all exported symbols have C linkage
We don't want any C++ symbol mangling to cause ABI issues (a la the
C++11 ABI change madness).

Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2018-04-05 17:21:10 -07:00
Steven Noonan e049f34b33 steamnetworkingtypes.h: eliminate -Wextra-semi warning
Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2018-04-04 13:33:23 -07:00
Fletcher Dunn cd20520740 Added unit test. Fixed a bunch of hygiene issues.
The test is compiling, but not fully working.
NOTE: THIS IS UNIT TEST, NOT A TYPICAL SAMPLE OF HOW TO USE THE LIBRARY, PLEASE DON'T CUT AND PASTE.  If we have time we'll add a better sample code with a proper server and client.
Also renamed some "SteamDatagram" things (which is the name used to refer to the relay network, not included with the opensource code) to "SteamnetworkingSockets".
Remove include of platform.h in a public header.  That's not supposed to be visible or needed outside of compiling the library.
Added a stub for ISteamNetworkingUtils.  The only thing that's available in the opensource library is the timestamp function.  In the Steamworks version there are utilities for reasoning about the relay network and estimating ping between two locations.
2018-04-03 12:36:43 -07:00
Steven Noonan 7db463285b MinGW build fixes
These changes compile and link, but they probably crash or something
right now. We need to get a unit test or three into the repo so we can
vet changes like this.

Signed-off-by: Steven Noonan <steven@valvesoftware.com>
2018-04-02 13:13:01 -07:00
Fletcher Dunn dc6fcbc2cf Delete CUtlString and CUtlStringBuilder, use std::string everywhere. 2018-04-02 12:51:24 -07:00
Fletcher Dunn 954e7f1d26 Add meson build file, which was mistakenly omitted from initial comit.
Move truly "public" headers to an "include" folder.  The internal "public" directory contains files that are only "public" in the context of the Steam build environment.
2018-03-30 13:36:41 -07:00