5abb7b651afed22dbe9f38437ff1438e0617282d
[vg.git] / vg_steam_networking.h
1 #pragma once
2 #include "vg_steam.h"
3
4 #ifdef VALVE_CALLBACK_PACK_SMALL
5 ;
6 #pragma pack(push,4)
7 #else
8 #pragma pack(push,8)
9 #endif
10
11 enum ESteamNetworkingConfigScope
12 {
13 k_ESteamNetworkingConfig_Global = 1,
14 k_ESteamNetworkingConfig_SocketsInterface = 2,
15 k_ESteamNetworkingConfig_ListenSocket = 3,
16 k_ESteamNetworkingConfig_Connection = 4,
17 k_ESteamNetworkingConfigScope__Force32Bit = 0x7fffffff
18 };
19 typedef enum ESteamNetworkingConfigScope ESteamNetworkingConfigScope;
20
21 enum ESteamNetworkingConfigDataType
22 {
23 k_ESteamNetworkingConfig_Int32 = 1,
24 k_ESteamNetworkingConfig_Int64 = 2,
25 k_ESteamNetworkingConfig_Float = 3,
26 k_ESteamNetworkingConfig_String = 4,
27 k_ESteamNetworkingConfig_Ptr = 5,
28
29 k_ESteamNetworkingConfigDataType__Force32Bit = 0x7fffffff
30 };
31 typedef enum ESteamNetworkingConfigDataType ESteamNetworkingConfigDataType;
32
33 enum ESteamNetworkingConfigValue
34 {
35 k_ESteamNetworkingConfig_Invalid = 0,
36 k_ESteamNetworkingConfig_TimeoutInitial = 24,
37 k_ESteamNetworkingConfig_TimeoutConnected = 25,
38 k_ESteamNetworkingConfig_SendBufferSize = 9,
39 k_ESteamNetworkingConfig_ConnectionUserData = 40,
40 k_ESteamNetworkingConfig_SendRateMin = 10,
41 k_ESteamNetworkingConfig_SendRateMax = 11,
42 k_ESteamNetworkingConfig_NagleTime = 12,
43 k_ESteamNetworkingConfig_IP_AllowWithoutAuth = 23,
44 k_ESteamNetworkingConfig_MTU_PacketSize = 32,
45 k_ESteamNetworkingConfig_MTU_DataSize = 33,
46 k_ESteamNetworkingConfig_Unencrypted = 34,
47 k_ESteamNetworkingConfig_SymmetricConnect = 37,
48 k_ESteamNetworkingConfig_LocalVirtualPort = 38,
49 k_ESteamNetworkingConfig_DualWifi_Enable = 39,
50 k_ESteamNetworkingConfig_EnableDiagnosticsUI = 46,
51 k_ESteamNetworkingConfig_FakePacketLoss_Send = 2,
52 k_ESteamNetworkingConfig_FakePacketLoss_Recv = 3,
53 k_ESteamNetworkingConfig_FakePacketLag_Send = 4,
54 k_ESteamNetworkingConfig_FakePacketLag_Recv = 5,
55 k_ESteamNetworkingConfig_FakePacketReorder_Send = 6,
56 k_ESteamNetworkingConfig_FakePacketReorder_Recv = 7,
57 k_ESteamNetworkingConfig_FakePacketReorder_Time = 8,
58 k_ESteamNetworkingConfig_FakePacketDup_Send = 26,
59 k_ESteamNetworkingConfig_FakePacketDup_Recv = 27,
60 k_ESteamNetworkingConfig_FakePacketDup_TimeMax = 28,
61 k_ESteamNetworkingConfig_PacketTraceMaxBytes = 41,
62 k_ESteamNetworkingConfig_FakeRateLimit_Send_Rate = 42,
63 k_ESteamNetworkingConfig_FakeRateLimit_Send_Burst = 43,
64 k_ESteamNetworkingConfig_FakeRateLimit_Recv_Rate = 44,
65 k_ESteamNetworkingConfig_FakeRateLimit_Recv_Burst = 45,
66 k_ESteamNetworkingConfig_Callback_ConnectionStatusChanged = 201,
67 k_ESteamNetworkingConfig_Callback_AuthStatusChanged = 202,
68 k_ESteamNetworkingConfig_Callback_RelayNetworkStatusChanged = 203,
69 k_ESteamNetworkingConfig_Callback_MessagesSessionRequest = 204,
70 k_ESteamNetworkingConfig_Callback_MessagesSessionFailed = 205,
71 k_ESteamNetworkingConfig_Callback_CreateConnectionSignaling = 206,
72 k_ESteamNetworkingConfig_Callback_FakeIPResult = 207,
73 k_ESteamNetworkingConfig_P2P_STUN_ServerList = 103,
74 k_ESteamNetworkingConfig_P2P_Transport_ICE_Enable = 104,
75 k_ESteamNetworkingConfig_P2P_Transport_ICE_Penalty = 105,
76 k_ESteamNetworkingConfig_P2P_Transport_SDR_Penalty = 106,
77 k_ESteamNetworkingConfig_SDRClient_ConsecutitivePingTimeoutsFailInitial = 19,
78 k_ESteamNetworkingConfig_SDRClient_ConsecutitivePingTimeoutsFail = 20,
79 k_ESteamNetworkingConfig_SDRClient_MinPingsBeforePingAccurate = 21,
80 k_ESteamNetworkingConfig_SDRClient_SingleSocket = 22,
81 k_ESteamNetworkingConfig_SDRClient_ForceRelayCluster = 29,
82 k_ESteamNetworkingConfig_SDRClient_DebugTicketAddress = 30,
83 k_ESteamNetworkingConfig_SDRClient_ForceProxyAddr = 31,
84 k_ESteamNetworkingConfig_SDRClient_FakeClusterPing = 36,
85 k_ESteamNetworkingConfig_LogLevel_AckRTT = 13,
86 k_ESteamNetworkingConfig_LogLevel_PacketDecode = 14,
87 k_ESteamNetworkingConfig_LogLevel_Message = 15,
88 k_ESteamNetworkingConfig_LogLevel_PacketGaps = 16,
89 k_ESteamNetworkingConfig_LogLevel_P2PRendezvous = 17,
90 k_ESteamNetworkingConfig_LogLevel_SDRRelayPings = 18,
91 k_ESteamNetworkingConfig_DELETED_EnumerateDevVars = 35,
92 k_ESteamNetworkingConfigValue__Force32Bit = 0x7fffffff
93 };
94 typedef enum ESteamNetworkingConfigValue ESteamNetworkingConfigValue;
95
96
97 enum ESteamNetworkingConnectionState
98 {
99 k_ESteamNetworkingConnectionState_None = 0,
100 k_ESteamNetworkingConnectionState_Connecting = 1,
101 k_ESteamNetworkingConnectionState_FindingRoute = 2,
102 k_ESteamNetworkingConnectionState_Connected = 3,
103 k_ESteamNetworkingConnectionState_ClosedByPeer = 4,
104 k_ESteamNetworkingConnectionState_ProblemDetectedLocally = 5,
105 k_ESteamNetworkingConnectionState_FinWait = -1,
106 k_ESteamNetworkingConnectionState_Linger = -2,
107 k_ESteamNetworkingConnectionState_Dead = -3,
108 k_ESteamNetworkingConnectionState__Force32Bit = 0x7fffffff
109 };
110 typedef enum ESteamNetworkingConnectionState ESteamNetworkingConnectionState;
111
112 enum ESteamNetConnectionEnd
113 {
114 k_ESteamNetConnectionEnd_Invalid = 0,
115 k_ESteamNetConnectionEnd_App_Min = 1000,
116 k_ESteamNetConnectionEnd_App_Generic = k_ESteamNetConnectionEnd_App_Min,
117 k_ESteamNetConnectionEnd_App_Max = 1999,
118 k_ESteamNetConnectionEnd_AppException_Min = 2000,
119 k_ESteamNetConnectionEnd_AppException_Generic =
120 k_ESteamNetConnectionEnd_AppException_Min,
121 k_ESteamNetConnectionEnd_AppException_Max = 2999,
122 k_ESteamNetConnectionEnd_Local_Min = 3000,
123 k_ESteamNetConnectionEnd_Local_OfflineMode = 3001,
124 k_ESteamNetConnectionEnd_Local_ManyRelayConnectivity = 3002,
125 k_ESteamNetConnectionEnd_Local_HostedServerPrimaryRelay = 3003,
126 k_ESteamNetConnectionEnd_Local_NetworkConfig = 3004,
127 k_ESteamNetConnectionEnd_Local_Rights = 3005,
128 k_ESteamNetConnectionEnd_Local_P2P_ICE_NoPublicAddresses = 3006,
129
130 k_ESteamNetConnectionEnd_Local_Max = 3999,
131 k_ESteamNetConnectionEnd_Remote_Min = 4000,
132 k_ESteamNetConnectionEnd_Remote_Timeout = 4001,
133 k_ESteamNetConnectionEnd_Remote_BadCrypt = 4002,
134 k_ESteamNetConnectionEnd_Remote_BadCert = 4003,
135 k_ESteamNetConnectionEnd_Remote_BadProtocolVersion = 4006,
136 k_ESteamNetConnectionEnd_Remote_P2P_ICE_NoPublicAddresses = 4007,
137
138 k_ESteamNetConnectionEnd_Remote_Max = 4999,
139
140 k_ESteamNetConnectionEnd_Misc_Min = 5000,
141 k_ESteamNetConnectionEnd_Misc_Generic = 5001,
142 k_ESteamNetConnectionEnd_Misc_InternalError = 5002,
143 k_ESteamNetConnectionEnd_Misc_Timeout = 5003,
144 k_ESteamNetConnectionEnd_Misc_SteamConnectivity = 5005,
145 k_ESteamNetConnectionEnd_Misc_NoRelaySessionsToClient = 5006,
146 k_ESteamNetConnectionEnd_Misc_P2P_Rendezvous = 5008,
147 k_ESteamNetConnectionEnd_Misc_P2P_NAT_Firewall = 5009,
148 k_ESteamNetConnectionEnd_Misc_PeerSentNoConnection = 5010,
149
150 k_ESteamNetConnectionEnd_Misc_Max = 5999,
151 k_ESteamNetConnectionEnd__Force32Bit = 0x7fffffff
152 };
153 typedef enum ESteamNetConnectionEnd ESteamNetConnectionEnd;
154
155 enum ESteamNetworkingIdentityType
156 {
157 k_ESteamNetworkingIdentityType_Invalid = 0,
158 k_ESteamNetworkingIdentityType_SteamID = 16,
159 k_ESteamNetworkingIdentityType_IPAddress = 1,
160 k_ESteamNetworkingIdentityType_GenericString = 2,
161 k_ESteamNetworkingIdentityType_GenericBytes = 3,
162 k_ESteamNetworkingIdentityType_UnknownType = 4,
163 k_ESteamNetworkingIdentityType__Force32bit = 0x7fffffff,
164 };
165 typedef enum ESteamNetworkingIdentityType ESteamNetworkingIdentityType;
166
167 enum ESteamNetworkingAvailability
168 {
169 k_ESteamNetworkingAvailability_CannotTry = -102,
170 k_ESteamNetworkingAvailability_Failed = -101,
171 k_ESteamNetworkingAvailability_Previously = -100,
172 k_ESteamNetworkingAvailability_Retrying = -10,
173 k_ESteamNetworkingAvailability_NeverTried = 1,
174 k_ESteamNetworkingAvailability_Waiting = 2,
175 k_ESteamNetworkingAvailability_Attempting = 3,
176 k_ESteamNetworkingAvailability_Current = 100,
177 k_ESteamNetworkingAvailability_Unknown = 0,
178 k_ESteamNetworkingAvailability__Force32bit = 0x7fffffff,
179 };
180 typedef enum ESteamNetworkingAvailability ESteamNetworkingAvailability;
181
182 /* Handle used to identify a connection to a remote host. */
183 typedef u32 HSteamNetConnection;
184 static HSteamNetConnection const k_HSteamNetConnection_Invalid = 0;
185
186 /*
187 * Handle used to identify a "listen socket". Unlike traditional
188 * Berkeley sockets, a listen socket and a connection are two
189 * different abstractions.
190 */
191 typedef u32 HSteamListenSocket;
192 static HSteamListenSocket const k_HSteamListenSocket_Invalid = 0;
193
194 typedef u32 SteamNetworkingPOPID;
195 typedef i64 SteamNetworkingMicroseconds;
196
197 #pragma pack(push,1)
198 /* Store an IP and port. IPv6 is always used; IPv4 is represented using
199 * "IPv4-mapped" addresses: IPv4 aa.bb.cc.dd => IPv6 ::ffff:aabb:ccdd
200 * (RFC 4291 section 2.5.5.2.)
201 */
202 typedef struct SteamNetworkingIPAddr SteamNetworkingIPAddr;
203 struct SteamNetworkingIPAddr
204 {
205 union
206 {
207 u8 m_ipv6[ 16 ];
208
209 /* RFC4038, section 4.2 */
210 struct IPv4MappedAddress
211 {
212 u64 m_8zeros;
213 u16 m_0000;
214 u16 m_ffff;
215 u8 m_ip[ 4 ]; /* NOTE: As bytes, i.e. network byte order */
216 }
217 m_ipv4;
218 };
219
220 u16 m_port; // Host byte order
221 };
222
223 typedef struct SteamNetworkingIdentity SteamNetworkingIdentity;
224 struct SteamNetworkingIdentity
225 {
226 ESteamNetworkingIdentityType m_eType;
227
228 int m_cbSize;
229 union
230 {
231 u64 m_steamID64;
232 char m_szGenericString[ 32 ];
233 u8 m_genericBytes[ 32 ];
234 char m_szUnknownRawString[ 128 ];
235 SteamNetworkingIPAddr m_ip;
236 u32 m_reserved[ 32 ];
237 };
238 };
239
240 #pragma pack(pop)
241
242 /*
243 * "Fake IPs" are assigned to hosts, to make it easier to interface with
244 * older code that assumed all hosts will have an IPv4 address
245 */
246 enum ESteamNetworkingFakeIPType
247 {
248 k_ESteamNetworkingFakeIPType_Invalid,
249 k_ESteamNetworkingFakeIPType_NotFake,
250 k_ESteamNetworkingFakeIPType_GlobalIPv4,
251 k_ESteamNetworkingFakeIPType_LocalIPv4,
252 k_ESteamNetworkingFakeIPType__Force32Bit = 0x7fffffff
253 };
254 typedef enum ESteamNetworkingFakeIPType ESteamNetworkingFakeIPType;
255
256 /* Set everything to zero. E.g. [::]:0 */
257 void SteamAPI_SteamNetworkingIPAddr_Clear( SteamNetworkingIPAddr* self );
258
259 /* Returns true if the IP is ::0. (Doesn't check port.) */
260 int SteamAPI_SteamNetworkingIPAddr_IsIPv6AllZeros(
261 SteamNetworkingIPAddr* self );
262
263 /*
264 * Set IPv6 address. IP is interpreted as bytes, so there are no endian issues.
265 * (Same as inaddr_in6.) The IP can be a mapped IPv4 address
266 */
267 void SteamAPI_SteamNetworkingIPAddr_SetIPv6( SteamNetworkingIPAddr* self,
268 u8 *ipv6, u16 nPort );
269
270 /* Sets to IPv4 mapped address. IP and port are in host byte order. */
271 void SteamAPI_SteamNetworkingIPAddr_SetIPv4( SteamNetworkingIPAddr* self,
272 u32 nIP, u16 nPort );
273
274 /* Return true if IP is mapped IPv4 */
275 steamapi_bool
276 SteamAPI_SteamNetworkingIPAddr_IsIPv4( SteamNetworkingIPAddr *self );
277
278 /*
279 * Returns IP in host byte order (e.g. aa.bb.cc.dd as 0xaabbccdd).
280 * Returns 0 if IP is not mapped IPv4.
281 */
282 u32 SteamAPI_SteamNetworkingIPAddr_GetIPv4( SteamNetworkingIPAddr* self );
283
284 /* Set to the IPv6 localhost address ::1, and the specified port. */
285 void SteamAPI_SteamNetworkingIPAddr_SetIPv6LocalHost(
286 SteamNetworkingIPAddr* self, u16 nPort );
287
288 /*
289 * Return true if this identity is localhost.
290 * (Either IPv6 ::1, or IPv4 127.0.0.1)
291 */
292 steamapi_bool SteamAPI_SteamNetworkingIPAddr_IsLocalHost(
293 SteamNetworkingIPAddr* self );
294
295 /*
296 * Print to a string, with or without the port. Mapped IPv4 addresses are
297 * printed as dotted decimal (12.34.56.78), otherwise this will print the
298 * canonical form according to RFC5952. If you include the port, IPv6 will be
299 * surrounded by brackets, e.g. [::1:2]:80. Your buffer should be at least
300 * k_cchMaxString bytes to avoid truncation
301 *
302 * See also SteamNetworkingIdentityRender
303 */
304 void SteamAPI_SteamNetworkingIPAddr_ToString( SteamNetworkingIPAddr* self,
305 char *buf, u32 cbBuf, steamapi_bool bWithPort );
306
307 /*
308 * Parse an IP address and optional port. If a port is not present, it is set
309 * to 0.
310 * (This means that you cannot tell if a zero port was explicitly specified.)
311 */
312 steamapi_bool SteamAPI_SteamNetworkingIPAddr_ParseString(
313 SteamNetworkingIPAddr* self, const char *pszStr );
314
315 /* See if two addresses are identical */
316 steamapi_bool SteamAPI_SteamNetworkingIPAddr_IsEqualTo(
317 SteamNetworkingIPAddr *self, SteamNetworkingIPAddr *x );
318
319 /*
320 * Classify address as FakeIP. This function never returns
321 * k_ESteamNetworkingFakeIPType_Invalid.
322 */
323 ESteamNetworkingFakeIPType SteamAPI_SteamNetworkingIPAddr_GetFakeIPType(
324 SteamNetworkingIPAddr* self );
325
326 /* Return true if we are a FakeIP */
327 steamapi_bool SteamAPI_SteamNetworkingIPAddr_IsFakeIP( SteamNetworkingIPAddr* self );
328
329 /*
330 * In a few places we need to set configuration options on listen sockets and
331 * connections, and have them take effect *before* the listen socket or
332 * connection really starts doing anything. Creating the object and then setting
333 * the options "immediately" after creation doesn't work completely, because
334 * network packets could be received between the time the object is created and
335 * when the options are applied. To set options at creation time in a reliable
336 * way, they must be passed to the creation function. This structure is used to
337 * pass those options.
338 *
339 * For the meaning of these fields, see ISteamNetworkingUtils::SetConfigValue.
340 * Basically when the object is created, we just iterate over the list of
341 * options and call ISteamNetworkingUtils::SetConfigValueStruct, where the scope
342 * arguments are supplied by the object being created.
343 */
344 typedef struct SteamNetworkingConfigValue_t SteamNetworkingConfigValue_t;
345 struct SteamNetworkingConfigValue_t
346 {
347 /* Which option is being set */
348 ESteamNetworkingConfigValue m_eValue;
349
350 /// Which field below did you fill in?
351 ESteamNetworkingConfigDataType m_eDataType;
352
353 /// Option value
354 union
355 {
356 i32 m_int32;
357 i64 m_int64;
358 float m_float;
359 const char *m_string; // Points to your '\0'-terminated buffer
360 void *m_ptr;
361 } m_val;
362 };
363
364 void SteamAPI_SteamNetworkingConfigValue_t_SetInt32(
365 SteamNetworkingConfigValue_t* self,
366 ESteamNetworkingConfigValue eVal, i32 data );
367
368 void SteamAPI_SteamNetworkingConfigValue_t_SetInt64(
369 SteamNetworkingConfigValue_t* self,
370 ESteamNetworkingConfigValue eVal, i64 data );
371
372 void SteamAPI_SteamNetworkingConfigValue_t_SetFloat(
373 SteamNetworkingConfigValue_t* self,
374 ESteamNetworkingConfigValue eVal, float data );
375
376 void SteamAPI_SteamNetworkingConfigValue_t_SetPtr(
377 SteamNetworkingConfigValue_t* self,
378 ESteamNetworkingConfigValue eVal, void *data );
379
380 void SteamAPI_SteamNetworkingConfigValue_t_SetString(
381 SteamNetworkingConfigValue_t* self, ESteamNetworkingConfigValue eVal,
382 const char * data );
383
384 typedef void ISteamNetworkingSockets;
385 typedef struct SteamNetworkingMessage_t SteamNetworkingMessage_t;
386 typedef struct SteamNetConnectionInfo_t SteamNetConnectionInfo_t;
387
388
389 /*
390 * Handle used to identify a poll group, used to query many
391 * connections at once efficiently.
392 */
393 typedef u32 HSteamNetPollGroup;
394 static HSteamNetPollGroup const k_HSteamNetPollGroup_Invalid = 0;
395
396 ISteamNetworkingSockets
397 *SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012(void);
398
399 static inline ISteamNetworkingSockets
400 *SteamAPI_SteamGameServerNetworkingSockets_SteamAPI(void)
401 {
402 return SteamAPI_SteamGameServerNetworkingSockets_SteamAPI_v012();
403 }
404
405
406 ISteamNetworkingSockets *SteamAPI_SteamNetworkingSockets_SteamAPI_v012();
407 static inline
408 ISteamNetworkingSockets *SteamAPI_SteamNetworkingSockets_SteamAPI()
409 {
410 return SteamAPI_SteamNetworkingSockets_SteamAPI_v012();
411 }
412
413
414 /*
415 * Send the message unreliably. Can be lost. Messages *can* be larger than a
416 * single MTU (UDP packet), but there is no retransmission, so if any piece
417 * of the message is lost, the entire message will be dropped.
418
419 * The sending API does have some knowledge of the underlying connection, so
420 * if there is no NAT-traversal accomplished or there is a recognized adjustment
421 * happening on the connection, the packet will be batched until the connection
422 * is open again.
423
424 * Migration note: This is not exactly the same as k_EP2PSendUnreliable! You
425 * probably want k_ESteamNetworkingSendType_UnreliableNoNagle
426 */
427 static const int k_nSteamNetworkingSend_Unreliable = 0;
428
429 /*
430 * Disable Nagle's algorithm.
431 * By default, Nagle's algorithm is applied to all outbound messages. This means
432 * that the message will NOT be sent immediately, in case further messages are
433 * sent soon after you send this, which can be grouped together. Any time there
434 * is enough buffered data to fill a packet, the packets will be pushed out
435 * immediately, but partially-full packets not be sent until the Nagle timer
436 * expires. See ISteamNetworkingSockets::FlushMessagesOnConnection,
437 * ISteamNetworkingMessages::FlushMessagesToUser
438 *
439 * NOTE: Don't just send every message without Nagle because you want packets to
440 * get there quicker. Make sure you understand the problem that Nagle is
441 * solving before disabling it. If you are sending small messages, often many at
442 * the same time, then it is very likely that it will be more efficient to leave
443 * Nagle enabled. A typical proper use of this flag is when you are sending
444 * what you know will be the last message sent for a while (e.g. the last in the
445 * server simulation tick to a particular client), and you use this flag to
446 * flush all messages.
447 */
448 static const int k_nSteamNetworkingSend_NoNagle = 1;
449
450 /*
451 * Send a message unreliably, bypassing Nagle's algorithm for this message and
452 * any messages currently pending on the Nagle timer. This is equivalent to
453 * using k_ESteamNetworkingSend_Unreliable and then immediately flushing the
454 * messages using ISteamNetworkingSockets::FlushMessagesOnConnection or
455 * ISteamNetworkingMessages::FlushMessagesToUser. (But using this flag is more
456 * efficient since you only make one API call.)
457 */
458 static const int k_nSteamNetworkingSend_UnreliableNoNagle =
459 k_nSteamNetworkingSend_Unreliable |
460 k_nSteamNetworkingSend_NoNagle;
461 /*
462 * If the message cannot be sent very soon (because the connection is still
463 * doing some initial handshaking, route negotiations, etc), then just drop it.
464 * This is only applicable for unreliable messages. Using this flag on reliable
465 * messages is invalid.
466 */
467 static const int k_nSteamNetworkingSend_NoDelay = 4;
468
469 /*
470 * Send an unreliable message, but if it cannot be sent relatively quickly, just
471 * drop it instead of queuing it. This is useful for messages that are not
472 * useful if they are excessively delayed, such as voice data.
473 * NOTE: The Nagle algorithm is not used, and if the message is not dropped, any
474 * messages waiting on the Nagle timer are immediately flushed.
475 *
476 * A message will be dropped under the following circumstances:
477 * - the connection is not fully connected. (E.g. the "Connecting" or
478 * "FindingRoute" states)
479 * - there is a sufficiently large number of messages queued up already such
480 * that the current message will not be placed on the wire in the next
481 * ~200ms or so.
482 *
483 * If a message is dropped for these reasons, k_EResultIgnored will be returned.
484 */
485 static const int k_nSteamNetworkingSend_UnreliableNoDelay =
486 k_nSteamNetworkingSend_Unreliable |
487 k_nSteamNetworkingSend_NoDelay |
488 k_nSteamNetworkingSend_NoNagle;
489
490 /*
491 * Reliable message send. Can send up to
492 * k_cbMaxSteamNetworkingSocketsMessageSizeSend bytes in a single message.
493 * Does fragmentation/re-assembly of messages under the hood, as well as a
494 * sliding window for efficient sends of large chunks of data.
495 * The Nagle algorithm is used. See notes on
496 * k_ESteamNetworkingSendType_Unreliable for more details.
497 * See k_ESteamNetworkingSendType_ReliableNoNagle,
498 * ISteamNetworkingSockets::FlushMessagesOnConnection,
499 * ISteamNetworkingMessages::FlushMessagesToUser
500 *
501 * Migration note: This is NOT the same as k_EP2PSendReliable, it's more like
502 * k_EP2PSendReliableWithBuffering
503 */
504 static const int k_nSteamNetworkingSend_Reliable = 8;
505
506 /*
507 * Send a message reliably, but bypass Nagle's algorithm.
508 *
509 * Migration note: This is equivalent to k_EP2PSendReliable
510 */
511 static const int k_nSteamNetworkingSend_ReliableNoNagle =
512 k_nSteamNetworkingSend_Reliable |
513 k_nSteamNetworkingSend_NoNagle;
514
515
516 HSteamListenSocket SteamAPI_ISteamNetworkingSockets_CreateListenSocketIP(
517 ISteamNetworkingSockets *self,
518 SteamNetworkingIPAddr *localAddress, int nOptions,
519 SteamNetworkingConfigValue_t *pOptions );
520
521 HSteamNetConnection SteamAPI_ISteamNetworkingSockets_ConnectByIPAddress(
522 ISteamNetworkingSockets *self,
523 SteamNetworkingIPAddr *address, int nOptions,
524 SteamNetworkingConfigValue_t *pOptions );
525
526
527 EResult SteamAPI_ISteamNetworkingSockets_AcceptConnection(
528 ISteamNetworkingSockets *self,
529 HSteamNetConnection hConn );
530
531 steamapi_bool SteamAPI_ISteamNetworkingSockets_CloseConnection(
532 ISteamNetworkingSockets *self,
533 HSteamNetConnection hPeer, int nReason, const char *pszDebug,
534 steamapi_bool bEnableLinger );
535
536 steamapi_bool SteamAPI_ISteamNetworkingSockets_GetListenSocketAddress(
537 ISteamNetworkingSockets *self, HSteamListenSocket hSocket,
538 SteamNetworkingIPAddr *address );
539
540 steamapi_bool SteamAPI_ISteamNetworkingSockets_CloseConnection(
541 ISteamNetworkingSockets *self,
542 HSteamNetConnection hPeer, int nReason, const char *pszDebug,
543 steamapi_bool bEnableLinger );
544
545 steamapi_bool SteamAPI_ISteamNetworkingSockets_CloseListenSocket(
546 ISteamNetworkingSockets *self, HSteamListenSocket hSocket );
547
548 EResult SteamAPI_ISteamNetworkingSockets_SendMessageToConnection(
549 ISteamNetworkingSockets* self,
550 HSteamNetConnection hConn, const void *pData, u32 cbData, int nSendFlags,
551 i64 * pOutMessageNumber );
552
553 void SteamAPI_ISteamNetworkingSockets_SendMessages(
554 ISteamNetworkingSockets* self,
555 int nMessages, SteamNetworkingMessage_t *const *pMessages,
556 i64 *pOutMessageNumberOrResult );
557
558 EResult SteamAPI_ISteamNetworkingSockets_FlushMessagesOnConnection(
559 ISteamNetworkingSockets* self,
560 HSteamNetConnection hConn );
561
562 int SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnConnection(
563 ISteamNetworkingSockets* self,
564 HSteamNetConnection hConn,
565 SteamNetworkingMessage_t **ppOutMessages,
566 int nMaxMessages );
567
568 /*
569 * Poll Groups
570 */
571
572 HSteamNetPollGroup SteamAPI_ISteamNetworkingSockets_CreatePollGroup(
573 ISteamNetworkingSockets *self );
574
575 steamapi_bool SteamAPI_ISteamNetworkingSockets_DestroyPollGroup(
576 ISteamNetworkingSockets *self,
577 HSteamNetPollGroup hPollGroup );
578
579 steamapi_bool SteamAPI_ISteamNetworkingSockets_SetConnectionPollGroup(
580 ISteamNetworkingSockets *self,
581 HSteamNetConnection hConn, HSteamNetPollGroup hPollGroup );
582
583 int SteamAPI_ISteamNetworkingSockets_ReceiveMessagesOnPollGroup(
584 ISteamNetworkingSockets *self,
585 HSteamNetPollGroup hPollGroup, SteamNetworkingMessage_t **ppOutMessages,
586 int nMaxMessages );
587 /*
588 * Returns basic information about the high-level state of the connection.
589 * Returns false if the connection handle is invalid.
590 */
591 steamapi_bool SteamAPI_ISteamNetworkingSockets_GetConnectionInfo(
592 ISteamNetworkingSockets* self,
593 HSteamNetConnection hConn, SteamNetConnectionInfo_t * pInfo );
594
595 int SteamAPI_ISteamNetworkingSockets_GetDetailedConnectionStatus(
596 ISteamNetworkingSockets* self,
597 HSteamNetConnection hConn, char *pszBuf, int cbBuf );
598
599 steamapi_bool SteamAPI_ISteamNetworkingSockets_SetConnectionUserData(
600 ISteamNetworkingSockets* self, HSteamNetConnection hPeer, i64 nUserData );
601
602 i64 SteamAPI_ISteamNetworkingSockets_GetConnectionUserData(
603 ISteamNetworkingSockets* self, HSteamNetConnection hPeer );
604
605 steamapi_bool SteamAPI_ISteamNetworkingSockets_GetListenSocketAddress(
606 ISteamNetworkingSockets* self,
607 HSteamListenSocket hSocket, SteamNetworkingIPAddr *address );
608
609 enum{ k_cchSteamNetworkingMaxConnectionCloseReason = 128 };
610 enum{ k_cchSteamNetworkingMaxConnectionDescription = 128 };
611 enum{ k_cchSteamNetworkingMaxConnectionAppName = 32 };
612 enum{ k_nSteamNetworkConnectionInfoFlags_Unauthenticated = 1 };
613 enum{ k_nSteamNetworkConnectionInfoFlags_Unencrypted = 2 };
614 enum{ k_nSteamNetworkConnectionInfoFlags_LoopbackBuffers = 4 };
615 enum{ k_nSteamNetworkConnectionInfoFlags_Fast = 8 };
616 enum{ k_nSteamNetworkConnectionInfoFlags_Relayed = 16 };
617 enum{ k_nSteamNetworkConnectionInfoFlags_DualWifi = 32 };
618
619 /* Describe the state of a connection. */
620 struct SteamNetConnectionInfo_t
621 {
622 /*
623 * Who is on the other end? Depending on the connection type and phase of the
624 * connection, we might not know
625 */
626 SteamNetworkingIdentity m_identityRemote;
627
628 /* Arbitrary user data set by the local application code */
629 i64 m_nUserData;
630
631 /*
632 * Handle to listen socket this was connected on, or
633 * k_HSteamListenSocket_Invalid if we initiated the connection
634 */
635 HSteamListenSocket m_hListenSocket;
636
637 /*
638 * Remote address. Might be all 0's if we don't know it, or if this is N/A.
639 * (E.g. Basically everything except direct UDP connection.)
640 */
641 SteamNetworkingIPAddr m_addrRemote;
642 u16 m__pad1;
643
644 /* What data center is the remote host in? (0 if we don't know.) */
645 SteamNetworkingPOPID m_idPOPRemote;
646
647 /*
648 * What relay are we using to communicate with the remote host?
649 * (0 if not applicable.)
650 */
651 SteamNetworkingPOPID m_idPOPRelay;
652
653 /* High level state of the connection */
654 ESteamNetworkingConnectionState m_eState;
655
656 /*
657 * Basic cause of the connection termination or problem.
658 * See ESteamNetConnectionEnd for the values used
659 */
660 int m_eEndReason;
661
662 /*
663 * Human-readable, but non-localized explanation for connection
664 * termination or problem. This is intended for debugging /
665 * diagnostic purposes only, not to display to users. It might
666 * have some details specific to the issue.
667 */
668 char m_szEndDebug[ k_cchSteamNetworkingMaxConnectionCloseReason ];
669
670 /*
671 * Debug description. This includes the internal connection ID,
672 * connection type (and peer information), and any name
673 * given to the connection by the app. This string is used in various
674 * internal logging messages.
675 *
676 * Note that the connection ID *usually* matches the HSteamNetConnection
677 * handle, but in certain cases with symmetric connections it might not.
678 */
679 char m_szConnectionDescription
680 [ k_cchSteamNetworkingMaxConnectionDescription ];
681
682 /* Misc flags. Bitmask of k_nSteamNetworkConnectionInfoFlags_Xxxx */
683 int m_nFlags;
684
685 /* Internal stuff, room to change API easily */
686 u32 reserved[63];
687 };
688
689 /*
690 * Quick connection state, pared down to something you could call
691 * more frequently without it being too big of a perf hit.
692 */
693 struct SteamNetConnectionRealTimeStatus_t
694 {
695 /* High level state of the connection */
696 ESteamNetworkingConnectionState m_eState;
697
698 /* Current ping (ms) */
699 int m_nPing;
700
701 /*
702 * Connection quality measured locally, 0...1.
703 * (Percentage of packets delivered end-to-end in order).
704 */
705 float m_flConnectionQualityLocal;
706
707 /* Packet delivery success rate as observed from remote host */
708 float m_flConnectionQualityRemote;
709
710 /* Current data rates from recent history. */
711 float m_flOutPacketsPerSec;
712 float m_flOutBytesPerSec;
713 float m_flInPacketsPerSec;
714 float m_flInBytesPerSec;
715
716 /*
717 * Estimate rate that we believe that we can send data to our peer.
718 * Note that this could be significantly higher than m_flOutBytesPerSec,
719 * meaning the capacity of the channel is higher than you are sending data.
720 * (That's OK!)
721 */
722 int m_nSendRateBytesPerSecond;
723
724 /*
725 * Number of bytes pending to be sent. This is data that you have recently
726 * requested to be sent but has not yet actually been put on the wire. The
727 * reliable number ALSO includes data that was previously placed on the wire,
728 * but has now been scheduled for re-transmission. Thus, it's possible to
729 * observe m_cbPendingReliable increasing between two checks, even if no
730 * calls were made to send reliable data between the checks. Data that is
731 * awaiting the Nagle delay will appear in these numbers.
732 */
733 int m_cbPendingUnreliable;
734 int m_cbPendingReliable;
735
736 /*
737 * Number of bytes of reliable data that has been placed the wire, but
738 * for which we have not yet received an acknowledgment, and thus we may
739 * have to re-transmit.
740 */
741 int m_cbSentUnackedReliable;
742
743 /*
744 * If you queued a message right now, approximately how long would that
745 * message wait in the queue before we actually started putting its data on
746 * the wire in a packet?
747 *
748 * In general, data that is sent by the application is limited by the
749 * bandwidth of the channel. If you send data faster than this, it must be
750 * queued and put on the wire at a metered rate. Even sending a small amount
751 * of data (e.g. a few MTU, say ~3k) will require some of the data to be
752 * delayed a bit.
753 *
754 * Ignoring multiple lanes,the estimated delay will be approximately equal to
755 *
756 * ( m_cbPendingUnreliable+m_cbPendingReliable ) /
757 * m_nSendRateBytesPerSecond
758 *
759 * plus or minus one MTU. It depends on how much time has elapsed since the
760 * last packet was put on the wire. For example, the queue might have *just*
761 * been emptied, and the last packet placed on the wire, and we are exactly
762 * up against the send rate limit. In that case we might need to wait for
763 * one packet's worth of time to elapse before we can send again. On the
764 * other extreme, the queue might have data in it waiting for Nagle. (This
765 * will always be less than one packet, because as soon as we have a complete
766 * packet we would send it.) In that case, we might be ready to send data
767 * now, and this value will be 0.
768 *
769 * This value is only valid if multiple lanes are not used. If multiple lanes
770 * are in use, then the queue time will be different for each lane, and you
771 * must use the value in SteamNetConnectionRealTimeLaneStatus_t.
772 *
773 * Nagle delay is ignored for the purposes of this calculation.
774 */
775 SteamNetworkingMicroseconds m_usecQueueTime;
776
777 // Internal stuff, room to change API easily
778 u32 reserved[16];
779 };
780
781 /*
782 * Callbacks
783 */
784
785 enum { k_iSteamNetConnectionStatusChangedCallBack =
786 k_iSteamNetworkingSocketsCallbacks + 1 };
787
788 typedef struct SteamNetConnectionStatusChangedCallback_t
789 SteamNetConnectionStatusChangedCallback_t;
790 struct SteamNetConnectionStatusChangedCallback_t
791 {
792 /// Connection handle
793 HSteamNetConnection m_hConn;
794
795 /// Full connection info
796 SteamNetConnectionInfo_t m_info;
797
798 /// Previous state. (Current state is in m_info.m_eState)
799 ESteamNetworkingConnectionState m_eOldState;
800 };
801
802 enum { k_iSteamNetAuthenticationStatus =
803 k_iSteamNetworkingSocketsCallbacks + 2 };
804
805 typedef struct SteamNetAuthenticationStatus_t SteamNetAuthenticationStatus_t;
806 struct SteamNetAuthenticationStatus_t
807 {
808 /// Status
809 ESteamNetworkingAvailability m_eAvail;
810
811 /// Non-localized English language status. For diagnostic/debugging
812 /// purposes only.
813 char m_debugMsg[ 256 ];
814 };
815
816 #pragma pack(pop)
817
818 /* This does not have packing specified in the steamnetworkingtypes.h, it seems
819 * to use default */
820 struct SteamNetworkingMessage_t
821 {
822 /*
823 * Message payload
824 */
825 void *m_pData;
826
827 /*
828 * Size of the payload.
829 */
830 int m_cbSize;
831
832 HSteamNetConnection m_conn;
833
834 /*
835 * For inbound messages: Who sent this to us?
836 * For outbound messages on connections: not used.
837 * For outbound messages on the ad-hoc ISteamNetworkingMessages interface:
838 * who should we send this to?
839 */
840 SteamNetworkingIdentity m_identityPeer;
841
842 /*
843 * For messages received on connections, this is the user data
844 * associated with the connection.
845 *
846 * This is *usually* the same as calling GetConnection() and then
847 * fetching the user data associated with that connection, but for
848 * the following subtle differences:
849 *
850 * - This user data will match the connection's user data at the time
851 * is captured at the time the message is returned by the API.
852 * If you subsequently change the userdata on the connection,
853 * this won't be updated.
854 * - This is an inline call, so it's *much* faster.
855 * - You might have closed the connection, so fetching the user data
856 * would not be possible.
857 *
858 * Not used when sending messages.
859 */
860 i64 m_nConnUserData;
861
862 /*
863 * Local timestamp when the message was received
864 * Not used for outbound messages.
865 */
866 SteamNetworkingMicroseconds m_usecTimeReceived;
867
868 /*
869 * Message number assigned by the sender. This is not used for outbound
870 * messages. Note that if multiple lanes are used, each lane has its own
871 * message numbers, which are assigned sequentially, so messages from
872 * different lanes will share the same numbers.
873 */
874 i64 m_nMessageNumber;
875
876 /*
877 * Function used to free up m_pData. This mechanism exists so that
878 * apps can create messages with buffers allocated from their own
879 * heap, and pass them into the library. This function will
880 * usually be something like:
881 *
882 * free( pMsg->m_pData );
883 */
884 void (*m_pfnFreeData)( SteamNetworkingMessage_t *pMsg );
885
886 /*
887 * Function to used to decrement the internal reference count and, if
888 * it's zero, release the message. You should not set this function pointer,
889 * or need to access this directly! Use the Release() function instead!
890 */
891 void (*m_pfnRelease)( SteamNetworkingMessage_t *pMsg );
892
893 /*
894 * When using ISteamNetworkingMessages, the channel number the message was
895 * received on (Not used for messages sent or received on "connections")
896 */
897 int m_nChannel;
898
899 /*
900 * Bitmask of k_nSteamNetworkingSend_xxx flags.
901 * For received messages, only the k_nSteamNetworkingSend_Reliable bit is
902 * valid.
903 * For outbound messages, all bits are relevant
904 */
905 int m_nFlags;
906
907 /*
908 * Arbitrary user data that you can use when sending messages using
909 * ISteamNetworkingUtils::AllocateMessage and
910 * ISteamNetworkingSockets::SendMessage.
911 * (The callback you set in m_pfnFreeData might use this field.)
912 *
913 * Not used for received messages.
914 */
915 i64 m_nUserData;
916
917 /*
918 * For outbound messages, which lane to use? See
919 * ISteamNetworkingSockets::ConfigureConnectionLanes.
920 * For inbound messages, what lane was the message received on?
921 */
922 u16 m_idxLane;
923 u16 _pad1__;
924 };
925
926 void SteamAPI_SteamNetworkingMessage_t_Release(SteamNetworkingMessage_t* self);
927
928
929
930
931 /*
932 * Utility
933 */
934
935 static inline const char *string_ESteamNetworkingConnectionState(
936 ESteamNetworkingConnectionState s )
937 {
938 switch(s)
939 {
940 case k_ESteamNetworkingConnectionState_None:
941 return "None";
942 break;
943 case k_ESteamNetworkingConnectionState_Connecting:
944 return "Connecting";
945 break;
946 case k_ESteamNetworkingConnectionState_FindingRoute:
947 return "Finding route";
948 break;
949 case k_ESteamNetworkingConnectionState_Connected:
950 return "Connected";
951 break;
952 case k_ESteamNetworkingConnectionState_ClosedByPeer:
953 return "Closed By Peer";
954 break;
955 case k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
956 return "Problem detected locally";
957 break;
958 case k_ESteamNetworkingConnectionState_FinWait:
959 return "Finwait";
960 break;
961 case k_ESteamNetworkingConnectionState_Linger:
962 return "Linger";
963 break;
964 case k_ESteamNetworkingConnectionState_Dead:
965 return "Dead";
966 break;
967 case k_ESteamNetworkingConnectionState__Force32Bit:
968 return "Force 32 Bit";
969 break;
970 }
971
972 return "Error";
973 }
974
975 static inline const char *string_ESteamNetworkingAvailability(
976 ESteamNetworkingAvailability s )
977 {
978 switch(s)
979 {
980 case k_ESteamNetworkingAvailability_CannotTry:
981 return "Cannot Try";
982 break;
983 case k_ESteamNetworkingAvailability_Failed:
984 return "Failed";
985 break;
986 case k_ESteamNetworkingAvailability_Previously:
987 return "Previously";
988 break;
989 case k_ESteamNetworkingAvailability_Retrying:
990 return "Retrying";
991 break;
992 case k_ESteamNetworkingAvailability_NeverTried:
993 return "Never tried";
994 break;
995 case k_ESteamNetworkingAvailability_Waiting:
996 return "Waiting";
997 break;
998 case k_ESteamNetworkingAvailability_Attempting:
999 return "Attempting";
1000 break;
1001 case k_ESteamNetworkingAvailability_Current:
1002 return "Current";
1003 break;
1004 case k_ESteamNetworkingAvailability_Unknown:
1005 return "Unknown";
1006 break;
1007 default:
1008 return "Error";
1009 break;
1010 }
1011 }