PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pstunsrvr.h
Go to the documentation of this file.
1 /*
2  * pstunsrvr.h
3  *
4  * STUN server
5  *
6  * Portable Tools Library
7  *
8  * Copyright (c) 2011 Post Increment.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Tools Library.
21  *
22  * The Initial Developer of the Original Code is Post Increment.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  */
27 
28 #ifndef PTLIB_PSTUNSRVR_H
29 #define PTLIB_PSTUNSRVR_H
30 
31 #ifdef P_USE_PRAGMA
32 #pragma interface
33 #endif
34 
35 #include <ptlib.h>
36 
37 #if P_STUNSRVR
38 
39 #include <ptclib/pstun.h>
40 
41 
42 class PSTUNServer : public PObject, public PSTUN
43 {
44  PCLASSINFO(PSTUNServer, PObject)
45  public:
46  PSTUNServer();
47 
48  bool Open(WORD port = DefaultPort);
49  bool Open(PUDPSocket * socket1, PUDPSocket * socket2 = NULL);
50 
51  bool IsOpen() const;
52 
53  bool Close();
54 
55  struct SocketInfo {
56  SocketInfo(PUDPSocket * socket = NULL);
57 
58  PUDPSocket * m_socket;
59  PIPSocketAddressAndPort m_socketAddress;
60  PIPSocketAddressAndPort m_alternateAddressAndPort;
61 
62  PUDPSocket * m_alternatePortSocket;
63  PUDPSocket * m_alternateAddressSocket;
64  PUDPSocket * m_alternateAddressAndPortSocket;
65  };
66 
67  virtual bool Read(
68  PSTUNMessage & message,
69  SocketInfo & socketInfo
70  );
71 
72  virtual bool Process();
73 
74  virtual bool OnReceiveMessage(
75  const PSTUNMessage & message,
76  const SocketInfo & socketInfo
77  );
78 
79  virtual bool OnBindingRequest(
80  const PSTUNMessage & request,
81  const SocketInfo & socketInfo
82  );
83 
84  virtual void OnBindingResponse(
85  const PSTUNMessage & request,
86  PSTUNMessage & response
87  );
88 
89  virtual bool OnUnknownRequest(
90  const PSTUNMessage & request,
91  const SocketInfo & socketInfo
92  );
93 
94  protected:
95  void PopulateInfo(PUDPSocket * socket, const PIPSocket::Address & alternateAddress, WORD alternatePort,
96  PUDPSocket * alternatePortSocket, PUDPSocket * alternateAddressSocket, PUDPSocket * alternateAddressAndPortSocket);
97 
98  SocketInfo * CreateAndAddSocket(const PIPSocket::Address & addess, WORD port);
99 
100  typedef std::map<PUDPSocket *, SocketInfo> SocketToSocketInfoMap;
101  SocketToSocketInfoMap m_socketToSocketInfoMap;
102  PSocket::SelectList m_sockets;
103  PSocket::SelectList m_selectList;
104 
105  bool m_autoDelete;
106 
107  PTRACE_THROTTLE(m_throttleReceivedPacket, 3, 30000, 5);
108 };
109 
110 
111 #endif // P_STUNSRVR
112 
113 #endif // PTLIB_PSTUNSRVR_H
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
A socket channel that uses the UDP transport on the Internet Protocol.
Definition: udpsock.h:42
Definition: pstun.h:48
List of sockets used for Select() function.
Definition: socket.h:312
Definition: pstun.h:451
A class describing an IP address and port number combination.
Definition: ipsock.h:278
#define PTRACE_THROTTLE(var,...)
Definition: object.h:1082
A class describing an IP address.
Definition: ipsock.h:59
Ultimate parent class for all objects in the class library.
Definition: object.h:2204