SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NatTypeDetectionServer.h
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
19
20 #include "NativeFeatureIncludes.h"
21 #if _RAKNET_SUPPORT_NatTypeDetectionServer==1
22
23 #ifndef __NAT_TYPE_DETECTION_SERVER_H
24 #define __NAT_TYPE_DETECTION_SERVER_H
25
26 #include "types.h"
27 #include "Export.h"
28 #include "PluginInterface2.h"
29 #include "PacketPriority.h"
30 #include "SocketIncludes.h"
31 #include "DS_OrderedList.h"
32 #include "string.h"
33 #include "NatTypeDetectionCommon.h"
34
35
36 namespace SLNet
37 {
39 class RakPeerInterface;
40 struct Packet;
41
60 class RAK_DLL_EXPORT NatTypeDetectionServer : public PluginInterface2, public RNS2EventHandler
61 {
62 public:
63
64 // GetInstance() and DestroyInstance(instance*)
65 STATIC_FACTORY_DECLARATIONS(NatTypeDetectionServer)
66
67 // Constructor
68 NatTypeDetectionServer();
69
70 // Destructor
71 virtual ~NatTypeDetectionServer();
72
77 void Startup(
78 const char *nonRakNetIP2,
79 const char *nonRakNetIP3,
80 const char *nonRakNetIP4
81 #ifdef __native_client__
82 ,_PP_Instance_ chromeInstance
83 #endif
84 );
85
86 // Releases the sockets created in Startup();
87 void Shutdown(void);
88
90 virtual void Update(void);
91
93 virtual PluginReceiveResult OnReceive(Packet *packet);
94 virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
95
96 enum NATDetectionState
97 {
98 STATE_NONE,
99 STATE_TESTING_NONE_1,
100 STATE_TESTING_NONE_2,
101 STATE_TESTING_FULL_CONE_1,
102 STATE_TESTING_FULL_CONE_2,
103 STATE_TESTING_ADDRESS_RESTRICTED_1,
104 STATE_TESTING_ADDRESS_RESTRICTED_2,
105 STATE_TESTING_PORT_RESTRICTED_1,
106 STATE_TESTING_PORT_RESTRICTED_2,
107 STATE_DONE,
108 };
109
110 struct NATDetectionAttempt
111 {
112 SystemAddress systemAddress;
113 NATDetectionState detectionState;
114 SLNet::TimeMS nextStateTime;
115 SLNet::TimeMS timeBetweenAttempts;
116 unsigned short c2Port;
117 RakNetGUID guid;
118 };
119
120 virtual void OnRNS2Recv(RNS2RecvStruct *recvStruct);
121 virtual void DeallocRNS2RecvStruct(RNS2RecvStruct *s, const char *file, unsigned int line);
122 virtual RNS2RecvStruct *AllocRNS2RecvStruct(const char *file, unsigned int line);
123 protected:
124 DataStructures::Queue<RNS2RecvStruct*> bufferedPackets;
125 SimpleMutex bufferedPacketsMutex;
126
127 void OnDetectionRequest(Packet *packet);
128 DataStructures::List<NATDetectionAttempt> natDetectionAttempts;
129 unsigned int GetDetectionAttemptIndex(const SystemAddress &sa);
130 unsigned int GetDetectionAttemptIndex(RakNetGUID guid);
131
132 // s1p1 is rakpeer itself
133 RakNetSocket2 *s1p2,*s2p3,*s3p4,*s4p5;
134 //unsigned short s1p2Port, s2p3Port, s3p4Port, s4p5Port;
135 char s3p4Address[64];
136 };
137 }
138
139
140 #endif
141
142 #endif // _RAKNET_SUPPORT_*