Stun Server  Compliant with the latest RFCs including 5389, 5769, and 5780
discover the local host's own external IP address
stunclientlogic.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 STUNCLIENTLOGIC_H
19 #define STUNCLIENTLOGIC_H
20 
21 
22 #include "stunclienttests.h"
23 
24 
25 
27 {
29 
30  bool fTimeoutIsInstant; // if true, then timeoutSeconds is ignored and assumed to be zero
31  uint32_t timeoutSeconds; // if fTimeoutIsInstant is false, then "0" implies to use the default
32  uint32_t uMaxAttempts;
33 
36 };
37 
38 
40 {
42  DirectMapping, // IP address and port are the same between client and server view (NO NAT)
43  EndpointIndependentMapping, // same mapping regardless of IP:port original packet sent to (the kind of NAT we like)
44  AddressDependentMapping, // mapping changes for local socket based on remote IP address only, but remote port can change (partially symmetric, not great)
45  AddressAndPortDependentMapping // different port mapping if the ip address or port change (symmetric NAT, difficult to predict port mappings)
46 };
47 
49 {
52  EndpointIndependentFiltering, // shouldn't be common unless connection is already direct (can receive on mapped address from anywhere regardless of where the original send went)
53  AddressDependentFiltering, // IP-restricted NAT
54  AddressAndPortDependentFiltering // port-restricted NAT
55 };
56 
58 {
59  // basic binding test will set these results
61  bool fIsDirect; // true if addrLocal == addrMapped
62  CSocketAddress addrLocal; // local address
63  CSocketAddress addrMapped; // mapped address from PP for local address
64  bool fHasOtherAddress; // set to true if the basic binding request got an "other adddress" back from the server
65  CSocketAddress addrPA; // the other address (with primary IP) as identified by the basic binding request
66  CSocketAddress addrAP; // the other address (with primary port) as identified by the basic binding request
67  CSocketAddress addrAA; // the other address as identified by the basic binding request
68  // -----------------------------------------
69 
70  // behavior state test --------------------------
73  CSocketAddress addrMappingAP; // result of binding request for AP (behavior test 2)
74  CSocketAddress addrMappingAA; // result of binding request for AA (behavior test 3)
75  // -----------------------------------------
76 
77  // filtering state test --------------------------
82  // -----------------------------------------
83 
84  uint32_t errorBitmask;
85  static const uint32_t SCR_TIMEOUT = 0x0001; // a timeout occurred waiting for an expected response
86  static const uint32_t SCR_NO_OTHER = 0x0002; // the server doesn't offer an alternate address/port
87 
89  void Init();
90 };
91 
92 
93 #define FACILITY_STUN_CLIENT_LOGIC_ERR 0x101
94 #define E_STUNCLIENT_STILL_WAITING ((HRESULT)0x81010001)
95 #define E_STUNCLIENT_RESULTS_READY ((HRESULT)0x81010002)
96 #define E_STUNCLIENT_TIMEOUT ((HRESULT)0x81010003)
97 #define E_STUNCLIENT_BUFFER_TOO_SMALL ((HRESULT)0x81010004)
98 
99 
100 
101 
103 {
104 private:
105 
108 
110 
112  uint32_t _sendCount;
114 
120 
121  std::vector<IStunClientTest*> _testlist;
122  size_t _nTestIndex;
123 
124 public:
126 
127  HRESULT Initialize(StunClientLogicConfig& config);
128 
129  HRESULT GetNextMessage(CRefCountedBuffer& spMsg, CSocketAddress* pAddrDest, uint32_t timeCurrentMilliseconds);
130 
131  HRESULT ProcessResponse(CRefCountedBuffer& spMsg, CSocketAddress& addrRemote, CSocketAddress& addrLocal);
132 
133  HRESULT GetResults(StunClientResults* pResults);
134 };
135 
136 
137 
138 
139 
140 
141 #endif /* STUNCLIENTLOGIC_H */
142 
CSocketAddress addrAP
CBasicBindingTest _test1
CBehaviorTest _testBehavior2
CFilteringTest _testFiltering2
NatBehavior behavior
CSocketAddress addrMapped
int32_t HRESULT
Definition: hresult.h:22
CFilteringTest _testFiltering3
CSocketAddress addrLocal
std::vector< IStunClientTest * > _testlist
CSocketAddress addrMappingAA
NatFiltering filtering
NatBehavior
CSocketAddress addrPA
boost::shared_ptr< CBuffer > CRefCountedBuffer
Definition: buffer.h:65
StunClientLogicConfig _config
NatFiltering
StunClientResults _results
uint32_t _timeLastMessageSent
CSocketAddress addrMappingAP
CSocketAddress addrServer
CSocketAddress addrAA
CBehaviorTest _testBehavior3