Debian Codegraph @

Source/Core/Common/TraversalProto.h

raw symbols SCIP
1 // SPDX-License-Identifier: CC0-1.0
2
3 #pragma once
4
5 #include <array>
6 #include <cstddef>
7 #include "Common/CommonTypes.h"
8
9 namespace Common
10 {
11 constexpr size_t NETPLAY_CODE_SIZE = 8;
12 using TraversalHostId = std::array<char, NETPLAY_CODE_SIZE>;
13 using TraversalRequestId = u64;
14
15 enum class TraversalPacketType : u8
16 {
17 // [*->*]
18 Ack = 0,
19 // [c->s]
20 Ping = 1,
21 // [c->s]
22 HelloFromClient = 2,
23 // [s->c]
24 HelloFromServer = 3,
25 // [c->s] When connecting, first the client asks the central server...
26 ConnectPlease = 4,
27 // [s->c] ...who asks the game host to send a UDP packet to the
28 // client... (an ack implies success)
29 PleaseSendPacket = 5,
30 // [s->c] ...which the central server relays back to the client.
31 ConnectReady = 6,
32 // [s->c] Alternately, the server might not have heard of this host.
33 ConnectFailed = 7,
34 // [c->s] Perform a traversal test. This will send two acks:
35 // one via the server's alt port, and one to the address corresponding to
36 // the given host ID.
37 TestPlease = 8,
38 };
39
40 constexpr u8 TraversalProtoVersion = 0;
41
42 enum class TraversalConnectFailedReason : u8
43 {
44 ClientDidntRespond = 0,
45 ClientFailure,
46 NoSuchClient,
47 };
48
49 #pragma pack(push, 1)
50 struct TraversalInetAddress
51 {
52 u8 isIPV6;
53 u32 address[4];
54 u16 port;
55 };
56 struct TraversalPacket
57 {
58 TraversalPacketType type;
59 TraversalRequestId requestId;
60 union
61 {
62 struct
63 {
64 u8 ok;
65 } ack;
66 struct
67 {
68 TraversalHostId hostId;
69 } ping;
70 struct
71 {
72 u8 protoVersion;
73 } helloFromClient;
74 struct
75 {
76 u8 ok;
77 TraversalHostId yourHostId;
78 TraversalInetAddress yourAddress;
79 } helloFromServer;
80 struct
81 {
82 TraversalHostId hostId;
83 } connectPlease;
84 struct
85 {
86 TraversalInetAddress address;
87 } pleaseSendPacket;
88 struct
89 {
90 TraversalRequestId requestId;
91 TraversalInetAddress address;
92 } connectReady;
93 struct
94 {
95 TraversalRequestId requestId;
96 TraversalConnectFailedReason reason;
97 } connectFailed;
98 struct
99 {
100 TraversalHostId hostId;
101 } testPlease;
102 };
103 };
104 #pragma pack(pop)
105 } // namespace Common