@@ -233,31 +233,121 @@ namespace SteamNetworkingSocketsLib {
233233 };
234234
235235 CSteamNetworkingICESessionCallbacks *m_pCallbacks;
236+
237+ // ICE defines two asymmetric roles: the controlling agent drives candidate
238+ // nomination (picks which path wins), the controlled agent follows its lead.
239+ // Roles are assigned by the signaling layer before ICE starts and stay fixed
240+ // unless a role-conflict packet forces a swap.
236241 EICERole m_role;
242+
243+ // Random 64-bit value generated fresh each session, included in every
244+ // outgoing connectivity check. When both sides accidentally claim the same
245+ // role, whichever has the numerically larger tiebreaker keeps that role and
246+ // the other side switches.
237247 uint64 m_nRoleTiebreaker;
248+
249+ // Set to true whenever the local network topology might have changed (e.g.
250+ // at startup, or on a network-change notification). The next Think() pass
251+ // will re-enumerate interfaces and rebuild candidates, then clear this flag.
238252 bool m_bInterfaceListStale;
253+
254+ // Bitmask of kSTUNPacketEncodingFlags_* controlling STUN wire format quirks:
255+ // whether to include a fingerprint, whether to use legacy MappedAddress vs
256+ // XOR-MappedAddress, and whether to sign with HMAC-SHA1 (MessageIntegrity)
257+ // vs HMAC-SHA256. Set to MessageIntegrity at construction for compatibility
258+ // with peers that don't support SHA256.
239259 int m_nEncoding;
260+
261+ // Our ICE credentials for this session, generated once at startup from the
262+ // connection ID and a random block. The username fragment identifies us;
263+ // the password is the HMAC key used to sign and verify connectivity checks.
240264 std::string m_strLocalUsernameFragment;
241265 std::string m_strLocalPassword;
266+
267+ // The remote peer's ICE credentials, delivered via signaling. Empty until
268+ // the first auth message arrives; connectivity checks cannot be validated
269+ // or sent until both are populated.
242270 std::string m_strRemoteUsernameFragment;
243271 std::string m_strRemotePassword;
244- std::string m_strIncomingUsername;
245- std::string m_strOutgoingUsername;
272+
273+ // Pre-built USERNAME attribute strings derived from the two ufrag values above.
274+ // ICE mandates the format "recipient:sender" — so the direction reverses
275+ // depending on whether a packet is inbound or outbound. Caching them avoids
276+ // repeated string concatenation in the hot path.
277+ // Both are empty until remote credentials have arrived via signaling.
278+ std::string m_strIncomingUsername; // local:remote — expected in packets we receive
279+ std::string m_strOutgoingUsername; // remote:local — placed in packets we send
280+
281+ // Dirty flag set whenever a local or remote candidate is added or removed.
282+ // The next Think() pass rebuilds m_vecCandidatePairs from the current
283+ // cross-product, then clears this flag.
246284 bool m_bCandidatePairsNeedUpdate;
247- int m_nPermittedCandidateTypes;
248285
286+ // Bitmask of k_EICECandidate_* types the caller has authorized us to gather
287+ // and use. Host-only vs reflexive vs relay, IPv4 vs IPv6, are all controlled
288+ // here. A candidate whose type bit is absent is silently dropped during
289+ // gathering rather than advertised to the peer.
290+ int m_nPermittedCandidateTypes;
291+
292+ // Timestamp of the next keepalive to send on the selected path. Zero means
293+ // "send immediately on the next Think()." Only meaningful once
294+ // m_pSelectedCandidatePair is non-null.
249295 SteamNetworkingMicroseconds m_nextKeepalive;
296+
297+ // The candidate pair currently in use for sending and receiving application
298+ // data. Null until ICE nominates a winner. Once set, changes only if the
299+ // selected path fails and a new one is nominated.
300+ // m_pSelectedSocket is the pre-looked-up raw socket for the local candidate
301+ // in that pair, kept here to avoid the per-send lookup overhead.
250302 ICECandidatePair *m_pSelectedCandidatePair;
251- IRawUDPSocket *m_pSelectedSocket;
303+ IRawUDPSocket *m_pSelectedSocket;
304+
305+ // Local network interfaces discovered during the most recent enumeration.
306+ // Each entry represents one usable local address. Rebuilt whenever
307+ // m_bInterfaceListStale is set.
252308 std_vector< Interface > m_vecInterfaces;
309+
310+ // Raw UDP sockets bound for host candidates, one per kICECandidateType_Host
311+ // entry in m_vecCandidates. Kept alive for the session lifetime so incoming
312+ // packets on any of these addresses are dispatched to us.
253313 std_vector< IRawUDPSocket* > m_vecHostCandidateSockets;
314+
315+ // Resolved addresses of STUN servers, populated once at construction from the
316+ // config string. Used to discover server-reflexive candidates and to dispatch
317+ // STUN responses back to the correct server.
254318 std_vector< SteamNetworkingIPAddr > m_vecSTUNServers;
319+
320+ // All local candidates gathered so far (host and server-reflexive), advertised
321+ // to the peer via signaling. Rebuilt on every interface re-enumeration and
322+ // grows as STUN responses arrive.
255323 std_vector< ICECandidate > m_vecCandidates;
324+
325+ // In-flight STUN Binding requests sent to STUN servers for initial
326+ // server-reflexive discovery. An entry is removed when its response arrives
327+ // (success or timeout) and the resulting candidate is added to m_vecCandidates.
328+ // The keepalive vector holds analogous follow-up requests sent periodically to
329+ // refresh the NAT mapping after a candidate is established.
256330 std_vector< CSteamNetworkingSocketsSTUNRequest* > m_vecPendingServerReflexiveRequests;
257331 std_vector< CSteamNetworkingSocketsSTUNRequest* > m_vecPendingServerReflexiveKeepAliveRequests;
332+
333+ // Candidates received from the remote peer via signaling. Paired with
334+ // m_vecCandidates to form m_vecCandidatePairs.
258335 std_vector< ICEPeerCandidate > m_vecPeerCandidates;
336+
337+ // In-flight STUN Binding requests being used as ICE connectivity checks,
338+ // one per candidate pair currently under active test.
259339 std_vector< CSteamNetworkingSocketsSTUNRequest* > m_vecPendingPeerRequests;
340+
341+ // All formed candidate pairs (cross-product of local × remote candidates,
342+ // pruned for duplicates). Checked in priority order during Think(); each
343+ // pair tracks its own state (waiting, in-progress, succeeded, failed).
260344 std_vector< ICECandidatePair* > m_vecCandidatePairs;
345+
346+ // Pairs needing an immediate out-of-turn connectivity check, bypassing the
347+ // normal paced schedule. Used when the controlling agent nominates a pair
348+ // (one final check with USE-CANDIDATE must be sent) or when an incoming check
349+ // reveals a new valid pair that should be verified promptly. Drained LIFO on
350+ // each Think() pass before the regular check list.
261351 std_vector< ICECandidatePair* > m_vecTriggeredCheckQueue;
262352
263353 IRawUDPSocket *FindSocketForCandidate ( const SteamNetworkingIPAddr& addr );
0 commit comments