ReplicaNet and RNLobby  1
TransportNATUDP.h
1 /* START_LICENSE_HEADER
2 
3 Copyright (C) 2000 Martin Piper, original design and program code
4 Copyright (C) 2001 Replica Software
5 
6 This program file is copyright (C) Replica Software and can only be used under license.
7 For more information visit: http://www.replicanet.com/
8 Or email: info@replicanet.com
9 
10 END_LICENSE_HEADER */
11 #include "RNPlatform/Inc/MemoryTracking.h"
12 #ifndef __TRANSPORTNATUDP_H__
13 #define __TRANSPORTNATUDP_H__
14 #include "RNXPURL/Inc/Transport.h"
15 #include "RNXPSockets/Inc/XPSocket.h"
16 
17 namespace RNReplicaNet
18 {
19 
20 namespace RNLobby
21 {
22 
28 class TransportNATUDP : public Transport
29 {
30 public:
35 
39  virtual ~TransportNATUDP();
40 
41  // Optional implementation of Transport virtual functions.
42  int GetPacketsSent(const bool reset);
43 
44  int GetPacketsSentMerged(const bool reset);
45 
46  int GetPacketsSentSize(const bool reset);
47 
48  int GetPacketsReceived(const bool reset);
49 
50  int GetPacketsReceivedMerged(const bool reset);
51 
52  int GetPacketsReceivedSize(const bool reset);
53 
54  int GetPacketsLost(const bool reset);
55 
56  void SetBandwidthLimit(const Bandwidth enable);
57 
58  Bandwidth GetBandwidthLimit();
59 
60  void SetMaximumOutputBandwidth(const int bytesPerSecond);
61 
62  int GetMaximumOutputBandwidth(void);
63 
64  void SetMaximumInputBandwidth(const int bytesPerSecond);
65 
66  int GetMaximumInputBandwidth(void);
67 
68  std::string GetPeerURL(void);
69 
70  bool GetTransportClosed(void);
71 
72  void SetEnableLANDiscovery(const bool enable);
73 
74  bool GetEnableLANDiscovery(void);
75 
76  // These pure virtual functions are the minimum feature set the transport has to support.
77 
78  std::string CanAccept(void);
79 
80  std::string CanRoute(void);
81 
82  std::string ExportURL(void);
83 
84  Transport *Allocate(void);
85 
86  Error Listen(const int channel);
87 
88  Error Listen(const std::string &address);
89 
90  void CommonListen(void);
91 
92  Error Connect(const std::string address);
93 
94  Transport *Accept(void);
95 
96  Error Send(const char *data,const int len);
97 
98  Error SendOrdered(const char *data,const int len,const unsigned int band = 0);
99 
100  Error SendReliable(const char *data,const int len,const unsigned int band = 0);
101 
102  Error SendCertain(const char *data,const int len);
103 
104  int Recv(char *const data,const int maxlen);
105 
106  int GetMaxPacketSize(void);
107 
108  std::string HandleDiscovery(void);
109 
110  void HandleDiscoveryReply(const std::string reply);
111 
112  void BeginDiscovery(void);
113 
114  std::string GetNextDiscovery(void);
115 
116  Error GetStatus(void);
117 
118  void SetBaseTransport(Transport *baseTransport);
119 
120  // Extension API for this transport type. Normally this wouldn't need to be used.
125  bool SetNATValues(const bool isAdvertised,const int globalID,const int sessionID);
126  void GetNATValues(bool &isAdvertised,int &globalID,int &sessionID);
127 
130  static void SetServer(const XPAddress &address);
132  static void ClearServer(void);
133 
134 
135 private:
136 friend class MyNATResolver;
137  void SetError(void);
138 
139  bool mAllocated;
140  Transport *mBaseTransport;
141  bool mIsResolved;
142  int mMyNOnceUsed;
143  bool mKnowExternalAddress;
144  XPAddress mExternalAddress;
145  bool mIsListen;
146  bool mIsUsed;
147 
148  bool mStateIsAdvertised;
149  int mStateGlobalID;
150  int mStateSessionID;
151 // bool mBeginResolveCalled;
152 // SysTime mBeginResolveCalledTime;
153 };
154 
155 } // namespace RNLobby
156 
157 } // namespace RNReplicaNet
158 
159 #endif
Error
Definition: Transport.h:42
int GetPacketsLost(const bool reset)
Error SendCertain(const char *data, const int len)
bool SetNATValues(const bool isAdvertised, const int globalID, const int sessionID)
Definition: Transport.h:35
int GetPacketsSentSize(const bool reset)
Error Send(const char *data, const int len)
int GetPacketsReceivedMerged(const bool reset)
int GetPacketsReceived(const bool reset)
int GetPacketsSentMerged(const bool reset)
Definition: XPSocket.h:91
void HandleDiscoveryReply(const std::string reply)
int Recv(char *const data, const int maxlen)
Error SendOrdered(const char *data, const int len, const unsigned int band=0)
static void ClearServer(void)
Clears any server set by SetServer().
void SetMaximumInputBandwidth(const int bytesPerSecond)
void SetEnableLANDiscovery(const bool enable)
void SetBandwidthLimit(const Bandwidth enable)
Definition: TransportNATUDP.h:28
int GetPacketsSent(const bool reset)
Error SendReliable(const char *data, const int len, const unsigned int band=0)
static void SetServer(const XPAddress &address)
void SetMaximumOutputBandwidth(const int bytesPerSecond)
Error Listen(const int channel)
int GetPacketsReceivedSize(const bool reset)
Error Connect(const std::string address)