SLikeNet  0.1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Router2.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 
21 #include "NativeFeatureIncludes.h"
22 #if _RAKNET_SUPPORT_Router2==1 && _RAKNET_SUPPORT_UDPForwarder==1
23 
24 #ifndef __ROUTER_2_PLUGIN_H
25 #define __ROUTER_2_PLUGIN_H
26 
27 #include "types.h"
28 #include "PluginInterface2.h"
29 #include "PacketPriority.h"
30 #include "Export.h"
31 #include "UDPForwarder.h"
32 #include "MessageIdentifiers.h"
33 #include "DS_List.h"
34 #include "SimpleMutex.h"
35 
36 namespace SLNet
37 {
39 class RakPeerInterface;
40 
42 {
45  virtual void ShowFailure(const char *message);
46  virtual void ShowDiagnostic(const char *message);
47 };
48 
55 
60 {
61 public:
62  // GetInstance() and DestroyInstance(instance*)
64 
65  Router2();
66  virtual ~Router2();
67 
70  void SetSocketFamily(unsigned short _socketFamily);
71 
90  void EstablishRouting(RakNetGUID endpointGuid);
91 
94  void SetMaximumForwardingRequests(int max);
95 
97  void SetDebugInterface(Router2DebugInterface *_debugInterface);
98 
100  Router2DebugInterface *GetDebugInterface(void) const;
101 
102  // --------------------------------------------------------------------------------------------
103  // Packet handling functions
104  // --------------------------------------------------------------------------------------------
105  virtual PluginReceiveResult OnReceive(Packet *packet);
106  virtual void Update(void);
107  virtual void OnClosedConnection(const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason );
108  virtual void OnFailedConnectionAttempt(Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason);
109  virtual void OnRakPeerShutdown(void);
110 
111 
113  {
116  };
117 
119  {
122  unsigned short usedForwardingEntries;
123  };
124 
126  {
127  ConnnectRequest();
128  ~ConnnectRequest();
129 
137  unsigned int GetGuidIndex(RakNetGUID guid);
138  };
139 
140  unsigned int GetConnectionRequestIndex(RakNetGUID endpointGuid);
141 
143  {
152  unsigned short forwardingPort;
154  };
155 
157  {
163  };
164 
165 protected:
166 
167  bool UpdateForwarding(ConnnectRequest* connectionRequest);
168  void RemoveConnectionRequest(unsigned int connectionRequestIndex);
169  void RequestForwarding(ConnnectRequest* connectionRequest);
170  void OnQueryForwarding(Packet *packet);
171  void OnQueryForwardingReply(Packet *packet);
172  void OnRequestForwarding(Packet *packet);
173  void OnRerouted(Packet *packet);
174  void OnMiniPunchReply(Packet *packet);
175  void OnMiniPunchReplyBounce(Packet *packet);
176  bool OnForwardingSuccess(Packet *packet);
177  int GetLargestPingAmongConnectedSystems(void) const;
178  void ReturnToUser(MessageID messageId, RakNetGUID endpointGuid, const SystemAddress &systemAddress, bool wasGeneratedLocally);
179  bool ConnectInternal(RakNetGUID endpointGuid, bool returnConnectionLostOnFailure);
180 
183  SimpleMutex connectionRequestsMutex, miniPunchesInProgressMutex, forwardedConnectionListMutex;
186  // Forwarding we have initiated
188 
189  void ClearConnectionRequests(void);
190  void ClearMinipunches(void);
191  void ClearForwardedConnections(void);
192  void ClearAll(void);
193  int ReturnFailureOnCannotForward(RakNetGUID sourceGuid, RakNetGUID endpointGuid);
194  void SendFailureOnCannotForward(RakNetGUID sourceGuid, RakNetGUID endpointGuid);
195  void SendForwardingSuccess(MessageID messageId, RakNetGUID sourceGuid, RakNetGUID endpointGuid, unsigned short sourceToDstPort);
196  void SendOOBFromRakNetPort(OutOfBandIdentifiers oob, BitStream *extraData, SystemAddress sa);
197  void SendOOBFromSpecifiedSocket(OutOfBandIdentifiers oob, SystemAddress sa, __UDPSOCKET__ socket);
198  void SendOOBMessages(MiniPunchRequest *mpr);
199 
201  unsigned short socketFamily;
202 };
203 
204 }
205 
206 #endif
207 
208 #endif // _RAKNET_SUPPORT_*