Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: webrtc/p2p/stunprober/stunprober.h

Issue 1162263012: Add SocketFactoryInterface::Prepare and fix how symmetric NAT is determined (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/p2p/stunprober/stunprober.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 // Chrome has client and server socket. Client socket supports Connect but not 49 // Chrome has client and server socket. Client socket supports Connect but not
50 // Bind. Server is opposite. 50 // Bind. Server is opposite.
51 class SocketInterface { 51 class SocketInterface {
52 public: 52 public:
53 enum { 53 enum {
54 IO_PENDING = -1, 54 IO_PENDING = -1,
55 FAILED = -2, 55 FAILED = -2,
56 }; 56 };
57 SocketInterface() {} 57 SocketInterface() {}
58 virtual int GetLocalAddress(rtc::SocketAddress* local_address) = 0;
59 virtual void Close() = 0; 58 virtual void Close() = 0;
60 virtual ~SocketInterface() {} 59 virtual ~SocketInterface() {}
61 60
62 private: 61 private:
63 DISALLOW_COPY_AND_ASSIGN(SocketInterface); 62 DISALLOW_COPY_AND_ASSIGN(SocketInterface);
64 }; 63 };
65 64
66 class ClientSocketInterface : public SocketInterface { 65 class ClientSocketInterface : public SocketInterface {
67 public: 66 public:
68 ClientSocketInterface() {} 67 ClientSocketInterface() {}
69 // Even though we have SendTo and RecvFrom, if Connect is not called first, 68 // Even though we have SendTo and RecvFrom, if Connect is not called first,
70 // getsockname will only return 0.0.0.0. 69 // getsockname will only return 0.0.0.0.
71 virtual int Connect(const rtc::SocketAddress& addr) = 0; 70 virtual int Connect(const rtc::SocketAddress& addr) = 0;
72 71
72 virtual int GetLocalAddress(rtc::SocketAddress* local_address) = 0;
73
73 private: 74 private:
74 DISALLOW_COPY_AND_ASSIGN(ClientSocketInterface); 75 DISALLOW_COPY_AND_ASSIGN(ClientSocketInterface);
75 }; 76 };
76 77
77 class ServerSocketInterface : public SocketInterface { 78 class ServerSocketInterface : public SocketInterface {
78 public: 79 public:
79 ServerSocketInterface() {} 80 ServerSocketInterface() {}
80 virtual int Bind(const rtc::SocketAddress& addr) = 0;
81 81
82 virtual int SendTo(const rtc::SocketAddress& addr, 82 virtual int SendTo(const rtc::SocketAddress& addr,
83 char* buf, 83 char* buf,
84 size_t buf_len, 84 size_t buf_len,
85 AsyncCallback callback) = 0; 85 AsyncCallback callback) = 0;
86 86
87 // If the returned value is positive, it means that buf has been 87 // If the returned value is positive, it means that buf has been
88 // sent. Otherwise, it should return IO_PENDING. Callback will be invoked 88 // sent. Otherwise, it should return IO_PENDING. Callback will be invoked
89 // after the data is successfully read into buf. 89 // after the data is successfully read into buf.
90 virtual int RecvFrom(char* buf, 90 virtual int RecvFrom(char* buf,
91 size_t buf_len, 91 size_t buf_len,
92 rtc::SocketAddress* addr, 92 rtc::SocketAddress* addr,
93 AsyncCallback callback) = 0; 93 AsyncCallback callback) = 0;
94 94
95 private: 95 private:
96 DISALLOW_COPY_AND_ASSIGN(ServerSocketInterface); 96 DISALLOW_COPY_AND_ASSIGN(ServerSocketInterface);
97 }; 97 };
98 98
99 class SocketFactoryInterface { 99 class SocketFactoryInterface {
100 public: 100 public:
101 SocketFactoryInterface() {} 101 SocketFactoryInterface() {}
102 // To provide a chance to prepare the sockets that we need. This is
103 // implemented for chrome renderer process as the socket needs to be ready to
104 // use in browser process.
105 virtual void Prepare(size_t total_client_socket,
106 size_t total_server_socket,
107 AsyncCallback callback) {
108 callback(0);
109 }
102 virtual ClientSocketInterface* CreateClientSocket() = 0; 110 virtual ClientSocketInterface* CreateClientSocket() = 0;
103 virtual ServerSocketInterface* CreateServerSocket( 111 virtual ServerSocketInterface* CreateServerSocket(
104 size_t send_buffer_size, 112 size_t send_buffer_size,
105 size_t receive_buffer_size) = 0; 113 size_t receive_buffer_size) = 0;
106 virtual ~SocketFactoryInterface() {} 114 virtual ~SocketFactoryInterface() {}
107 115
108 private: 116 private:
109 DISALLOW_COPY_AND_ASSIGN(SocketFactoryInterface); 117 DISALLOW_COPY_AND_ASSIGN(SocketFactoryInterface);
110 }; 118 };
111 119
(...skipping 15 matching lines...) Expand all
127 RESOLVE_FAILED, // Host resolution failed. 135 RESOLVE_FAILED, // Host resolution failed.
128 WRITE_FAILED, // Sending a message to the server failed. 136 WRITE_FAILED, // Sending a message to the server failed.
129 READ_FAILED, // Reading the reply from the server failed. 137 READ_FAILED, // Reading the reply from the server failed.
130 }; 138 };
131 139
132 struct Stats { 140 struct Stats {
133 Stats() {} 141 Stats() {}
134 int num_request_sent = 0; 142 int num_request_sent = 0;
135 int num_response_received = 0; 143 int num_response_received = 0;
136 bool behind_nat = false; 144 bool behind_nat = false;
145 bool symmetric_nat = false;
137 int average_rtt_ms = -1; 146 int average_rtt_ms = -1;
138 int success_percent = 0; 147 int success_percent = 0;
139 int target_request_interval_ns = 0; 148 int target_request_interval_ns = 0;
140 int actual_request_interval_ns = 0; 149 int actual_request_interval_ns = 0;
141 150
142 // Also report whether this trial can't be considered truly as shared 151 // Also report whether this trial can't be considered truly as shared
143 // mode. Share mode only makes sense when we have multiple IP resolved and 152 // mode. Share mode only makes sense when we have multiple IP resolved and
144 // successfully probed. 153 // successfully probed.
145 bool shared_socket_mode = false; 154 bool shared_socket_mode = false;
146 155
147 std::string host_ip; 156 std::string host_ip;
148 157
149 // If the srflx_addrs has more than 1 element, the NAT is symmetric. 158 // If the srflx_addrs has more than 1 element, the NAT is symmetric.
150 std::set<std::string> srflx_addrs; 159 std::set<std::string> srflx_addrs;
151
152 bool symmetric_nat() { return srflx_addrs.size() > 1; }
153 }; 160 };
154 161
155 // StunProber is not thread safe. It's task_runner's responsibility to ensure 162 // StunProber is not thread safe. It's task_runner's responsibility to ensure
156 // all calls happen sequentially. 163 // all calls happen sequentially.
157 StunProber(HostNameResolverInterface* host_name_resolver, 164 StunProber(HostNameResolverInterface* host_name_resolver,
158 SocketFactoryInterface* socket_factory, 165 SocketFactoryInterface* socket_factory,
159 TaskRunnerInterface* task_runner); 166 TaskRunnerInterface* task_runner);
160 virtual ~StunProber(); 167 virtual ~StunProber();
161 168
162 // Begin performing the probe test against the |servers|. If 169 // Begin performing the probe test against the |servers|. If
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 DISALLOW_COPY_AND_ASSIGN(Requester); 265 DISALLOW_COPY_AND_ASSIGN(Requester);
259 }; 266 };
260 267
261 private: 268 private:
262 void OnServerResolved(int index, int result); 269 void OnServerResolved(int index, int result);
263 270
264 bool Done() { 271 bool Done() {
265 return num_request_sent_ >= requests_per_ip_ * all_servers_ips_.size(); 272 return num_request_sent_ >= requests_per_ip_ * all_servers_ips_.size();
266 } 273 }
267 274
275 int GetTotalClientSockets() { return 1; }
276 int GetTotalServerSockets() {
277 return (shared_socket_mode_ ? 1 : all_servers_ips_.size()) *
278 requests_per_ip_;
279 }
280
268 bool SendNextRequest(); 281 bool SendNextRequest();
269 282
270 // Will be invoked in 1ms intervals and schedule the next request from the 283 // Will be invoked in 1ms intervals and schedule the next request from the
271 // |current_requester_| if the time has passed for another request. 284 // |current_requester_| if the time has passed for another request.
272 void MaybeScheduleStunRequests(); 285 void MaybeScheduleStunRequests();
273 286
274 // End the probe with the given |status|. Invokes |fininsh_callback|, which 287 // End the probe with the given |status|. Invokes |fininsh_callback|, which
275 // may destroy the class. 288 // may destroy the class.
276 void End(StunProber::Status status, int result); 289 void End(StunProber::Status status, int result);
277 290
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 std::vector<Requester*> requesters_; 341 std::vector<Requester*> requesters_;
329 342
330 rtc::ThreadChecker thread_checker_; 343 rtc::ThreadChecker thread_checker_;
331 344
332 DISALLOW_COPY_AND_ASSIGN(StunProber); 345 DISALLOW_COPY_AND_ASSIGN(StunProber);
333 }; 346 };
334 347
335 } // namespace stunprober 348 } // namespace stunprober
336 349
337 #endif // WEBRTC_P2P_STUNPROBER_STUNPROBER_H_ 350 #endif // WEBRTC_P2P_STUNPROBER_STUNPROBER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/p2p/stunprober/stunprober.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698