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