Stun Server  Compliant with the latest RFCs including 5389, 5769, and 5780
discover the local host's own external IP address
server.h
Go to the documentation of this file.
1 /*
2  Copyright 2011 John Selbie
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 
18 #ifndef STUN_SERVER_H
19 #define STUN_SERVER_H
20 
21 #include "stunsocket.h"
22 #include "stunsocketthread.h"
23 #include "stunauth.h"
24 #include "messagehandler.h"
25 
26 
27 
28 
30 {
31 public:
32 
33  bool fHasPP; // PP: Primary ip, Primary port
34  bool fHasPA; // PA: Primary ip, Alternate port
35  bool fHasAP; // AP: Alternate ip, Primary port
36  bool fHasAA; // AA: Alternate ip, Alternate port
37 
38  bool fMultiThreadedMode; // if true, one thread for each socket
39 
40  bool fTCP; // if true, then use TCP instead of UDP
41  uint32_t nMaxConnections; // only valid for TCP (on a per-thread basis)
42 
43  CSocketAddress addrPP; // address for PP
44  CSocketAddress addrPA; // address for PA
45  CSocketAddress addrAP; // address for AP
46  CSocketAddress addrAA; // address for AA
47 
48  CSocketAddress addrPrimaryAdvertised; // public-IP for PP and PA (port is ignored)
49  CSocketAddress addrAlternateAdvertised; // public-IP for AP and AA (port is ignored)
50 
51  bool fEnableDosProtection; // enable denial of service protection
52 
54 };
55 
56 
57 class CStunServer :
58 public CBasicRefCount,
59 public CObjectFactory<CStunServer>,
60 public IRefCounted
61 {
62 private:
63  CStunSocket _arrSockets[4];
64 
65  std::vector<CStunSocketThread*> _threads;
66 
67  CStunServer();
68  ~CStunServer();
69 
70  friend class CObjectFactory<CStunServer>;
71 
73 
74  HRESULT AddSocket(TransportAddressSet* pTSA, SocketRole role, const CSocketAddress& addrListen, const CSocketAddress& addrAdvertise);
75 
76 public:
77 
78  HRESULT Initialize(const CStunServerConfig& config);
79  HRESULT Shutdown();
80 
81  HRESULT Start();
82  HRESULT Stop();
83 
85 };
86 
87 
88 
89 #endif /* SERVER_H */
90 
CSocketAddress addrAlternateAdvertised
Definition: server.h:49
#define ADDREF_AND_RELEASE_IMPL()
std::vector< CStunSocketThread * > _threads
Definition: server.h:65
CRefCountedPtr< IStunAuth > _spAuth
Definition: server.h:72
CSocketAddress addrPA
Definition: server.h:44
CSocketAddress addrAA
Definition: server.h:46
SocketRole
Definition: socketrole.h:22
int32_t HRESULT
Definition: hresult.h:22
bool fMultiThreadedMode
Definition: server.h:38
uint32_t nMaxConnections
Definition: server.h:41
CSocketAddress addrPrimaryAdvertised
Definition: server.h:48
bool fEnableDosProtection
Definition: server.h:51
CSocketAddress addrAP
Definition: server.h:45
CSocketAddress addrPP
Definition: server.h:43