NatTypeDetectionCommon.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * 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. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \defgroup NAT_TYPE_DETECTION_GROUP NatTypeDetection
  11. /// \brief Use a remote server with multiple IP addresses to determine what type of NAT your router is using
  12. /// \details
  13. /// \ingroup PLUGINS_GROUP
  14. #ifndef __NAT_TYPE_DETECTION_COMMON_H
  15. #define __NAT_TYPE_DETECTION_COMMON_H
  16. #include "NativeFeatureIncludes.h"
  17. #if _RAKNET_SUPPORT_NatTypeDetectionServer==1 || _RAKNET_SUPPORT_NatTypeDetectionClient==1
  18. #include "SocketIncludes.h"
  19. #include "RakNetTypes.h"
  20. #include "RakNetSocket2.h"
  21. namespace RakNet
  22. {
  23. /// All possible types of NATs (except NAT_TYPE_COUNT, which is an internal value)
  24. enum NATTypeDetectionResult
  25. {
  26. /// Works with anyone
  27. NAT_TYPE_NONE,
  28. /// Accepts any datagrams to a port that has been previously used. Will accept the first datagram from the remote peer.
  29. NAT_TYPE_FULL_CONE,
  30. /// Accepts datagrams to a port as long as the datagram source IP address is a system we have already sent to. Will accept the first datagram if both systems send simultaneously. Otherwise, will accept the first datagram after we have sent one datagram.
  31. NAT_TYPE_ADDRESS_RESTRICTED,
  32. /// Same as address-restricted cone NAT, but we had to send to both the correct remote IP address and correct remote port. The same source address and port to a different destination uses the same mapping.
  33. NAT_TYPE_PORT_RESTRICTED,
  34. /// A different port is chosen for every remote destination. The same source address and port to a different destination uses a different mapping. Since the port will be different, the first external punchthrough attempt will fail. For this to work it requires port-prediction (MAX_PREDICTIVE_PORT_RANGE>1) and that the router chooses ports sequentially.
  35. NAT_TYPE_SYMMETRIC,
  36. /// Hasn't been determined. NATTypeDetectionClient does not use this, but other plugins might
  37. NAT_TYPE_UNKNOWN,
  38. /// In progress. NATTypeDetectionClient does not use this, but other plugins might
  39. NAT_TYPE_DETECTION_IN_PROGRESS,
  40. /// Didn't bother figuring it out, as we support UPNP, so it is equivalent to NAT_TYPE_NONE. NATTypeDetectionClient does not use this, but other plugins might
  41. NAT_TYPE_SUPPORTS_UPNP,
  42. /// \internal Must be last
  43. NAT_TYPE_COUNT
  44. };
  45. /// \return Can one system with NATTypeDetectionResult \a type1 connect to \a type2
  46. bool RAK_DLL_EXPORT CanConnect(NATTypeDetectionResult type1, NATTypeDetectionResult type2);
  47. /// Return a technical string representin the enumeration
  48. RAK_DLL_EXPORT const char * NATTypeDetectionResultToString(NATTypeDetectionResult type);
  49. /// Return a friendly string representing the enumeration
  50. /// None and relaxed can connect to anything
  51. /// Moderate can connect to moderate or less
  52. /// Strict can connect to relaxed or less
  53. RAK_DLL_EXPORT const char * NATTypeDetectionResultToStringFriendly(NATTypeDetectionResult type);
  54. /// \internal
  55. RAK_DLL_EXPORT RakNetSocket2* CreateNonblockingBoundSocket(const char *bindAddr
  56. #ifdef __native_client__
  57. ,_PP_Instance_ chromeInstance
  58. #endif
  59. , RNS2EventHandler *eventHandler
  60. );
  61. /// \internal
  62. //int NatTypeRecvFrom(char *data, RakNetSocket2* socket, SystemAddress &sender, RNS2EventHandler *eventHandler);
  63. }
  64. #endif // #if _RAKNET_SUPPORT_NatTypeDetectionServer==1 || _RAKNET_SUPPORT_NatTypeDetectionClient==1
  65. #endif
粤ICP备19079148号