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

Side by Side Diff: webrtc/base/virtualsocketserver.h

Issue 1274013002: Bug 4865: Enable connectivity when the remote peer is on public internet. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 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/base/virtualsocketserver.cc » ('j') | webrtc/base/virtualsocketserver.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 25 matching lines...) Expand all
36 explicit VirtualSocketServer(SocketServer* ss); 36 explicit VirtualSocketServer(SocketServer* ss);
37 ~VirtualSocketServer() override; 37 ~VirtualSocketServer() override;
38 38
39 SocketServer* socketserver() { return server_; } 39 SocketServer* socketserver() { return server_; }
40 40
41 // Limits the network bandwidth (maximum bytes per second). Zero means that 41 // Limits the network bandwidth (maximum bytes per second). Zero means that
42 // all sends occur instantly. Defaults to 0. 42 // all sends occur instantly. Defaults to 0.
43 uint32 bandwidth() const { return bandwidth_; } 43 uint32 bandwidth() const { return bandwidth_; }
44 void set_bandwidth(uint32 bandwidth) { bandwidth_ = bandwidth; } 44 void set_bandwidth(uint32 bandwidth) { bandwidth_ = bandwidth; }
45 45
46 // Default interface will be used when a binding is done against the any
47 // address.
48 const IPAddress default_interface(int family) {
juberti1 2015/08/06 00:35:26 Style: if it takes arguments, it's usually not low
pthatcher1 2015/08/06 01:06:19 I think this should be GetDefaultRoute.
guoweis_webrtc 2015/08/06 08:50:06 Done.
49 if (family == AF_INET) {
50 return default_interface_v4_;
51 }
52 if (family == AF_INET6) {
53 return default_interface_v6_;
54 }
55 return IPAddress();
56 }
57 void set_default_interface(const IPAddress& ipaddr) {
pthatcher1 2015/08/06 01:06:19 And this should be SetDefaultRoute.
58 if (ipaddr.family() == AF_INET) {
59 default_interface_v4_ = ipaddr;
60 } else if (ipaddr.family() == AF_INET6) {
61 default_interface_v6_ = ipaddr;
62 }
63 }
64
46 // Limits the amount of data which can be in flight on the network without 65 // Limits the amount of data which can be in flight on the network without
47 // packet loss (on a per sender basis). Defaults to 64 KB. 66 // packet loss (on a per sender basis). Defaults to 64 KB.
48 uint32 network_capacity() const { return network_capacity_; } 67 uint32 network_capacity() const { return network_capacity_; }
49 void set_network_capacity(uint32 capacity) { 68 void set_network_capacity(uint32 capacity) {
50 network_capacity_ = capacity; 69 network_capacity_ = capacity;
51 } 70 }
52 71
53 // The amount of data which can be buffered by tcp on the sender's side 72 // The amount of data which can be buffered by tcp on the sender's side
54 uint32 send_buffer_capacity() const { return send_buffer_capacity_; } 73 uint32 send_buffer_capacity() const { return send_buffer_capacity_; }
55 void set_send_buffer_capacity(uint32 capacity) { 74 void set_send_buffer_capacity(uint32 capacity) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // Close a pair of Tcp connections by addresses. Both connections will have 136 // Close a pair of Tcp connections by addresses. Both connections will have
118 // its own OnClose invoked. 137 // its own OnClose invoked.
119 bool CloseTcpConnections(const SocketAddress& addr_local, 138 bool CloseTcpConnections(const SocketAddress& addr_local,
120 const SocketAddress& addr_remote); 139 const SocketAddress& addr_remote);
121 140
122 protected: 141 protected:
123 // Returns a new IP not used before in this network. 142 // Returns a new IP not used before in this network.
124 IPAddress GetNextIP(int family); 143 IPAddress GetNextIP(int family);
125 uint16 GetNextPort(); 144 uint16 GetNextPort();
126 145
146 // Helper function to return the binding from the any address to default
147 // interface.
148 const SocketAddress TryMapAnyAddressToDefault(const SocketAddress& addr);
149
127 VirtualSocket* CreateSocketInternal(int family, int type); 150 VirtualSocket* CreateSocketInternal(int family, int type);
128 151
129 // Binds the given socket to addr, assigning and IP and Port if necessary 152 // Binds the given socket to addr, assigning and IP and Port if necessary
130 int Bind(VirtualSocket* socket, SocketAddress* addr); 153 int Bind(VirtualSocket* socket, SocketAddress* addr);
131 154
132 // Binds the given socket to the given (fully-defined) address. 155 // Binds the given socket to the given (fully-defined) address.
133 int Bind(VirtualSocket* socket, const SocketAddress& addr); 156 int Bind(VirtualSocket* socket, const SocketAddress& addr);
134 157
135 // Find the socket bound to the given address 158 // Find the socket bound to the given address
136 VirtualSocket* LookupBinding(const SocketAddress& addr); 159 VirtualSocket* LookupBinding(const SocketAddress& addr);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 bool server_owned_; 240 bool server_owned_;
218 MessageQueue* msg_queue_; 241 MessageQueue* msg_queue_;
219 bool stop_on_idle_; 242 bool stop_on_idle_;
220 uint32 network_delay_; 243 uint32 network_delay_;
221 in_addr next_ipv4_; 244 in_addr next_ipv4_;
222 in6_addr next_ipv6_; 245 in6_addr next_ipv6_;
223 uint16 next_port_; 246 uint16 next_port_;
224 AddressMap* bindings_; 247 AddressMap* bindings_;
225 ConnectionMap* connections_; 248 ConnectionMap* connections_;
226 249
250 IPAddress default_interface_v4_;
251 IPAddress default_interface_v6_;
pthatcher1 2015/08/06 01:06:19 And this default_route_vX_;
252
227 uint32 bandwidth_; 253 uint32 bandwidth_;
228 uint32 network_capacity_; 254 uint32 network_capacity_;
229 uint32 send_buffer_capacity_; 255 uint32 send_buffer_capacity_;
230 uint32 recv_buffer_capacity_; 256 uint32 recv_buffer_capacity_;
231 uint32 delay_mean_; 257 uint32 delay_mean_;
232 uint32 delay_stddev_; 258 uint32 delay_stddev_;
233 uint32 delay_samples_; 259 uint32 delay_samples_;
234 Function* delay_dist_; 260 Function* delay_dist_;
235 CriticalSection delay_crit_; 261 CriticalSection delay_crit_;
236 262
237 double drop_prob_; 263 double drop_prob_;
238 DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer); 264 DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer);
239 }; 265 };
240 266
241 // Implements the socket interface using the virtual network. Packets are 267 // Implements the socket interface using the virtual network. Packets are
242 // passed as messages using the message queue of the socket server. 268 // passed as messages using the message queue of the socket server.
243 class VirtualSocket : public AsyncSocket, public MessageHandler { 269 class VirtualSocket : public AsyncSocket, public MessageHandler {
244 public: 270 public:
245 VirtualSocket(VirtualSocketServer* server, int family, int type, bool async); 271 VirtualSocket(VirtualSocketServer* server, int family, int type, bool async);
246 ~VirtualSocket() override; 272 ~VirtualSocket() override;
247 273
248 SocketAddress GetLocalAddress() const override; 274 SocketAddress GetLocalAddress() const override;
249 SocketAddress GetRemoteAddress() const override; 275 SocketAddress GetRemoteAddress() const override;
250 276
251 // Used by server sockets to set the local address without binding.
252 void SetLocalAddress(const SocketAddress& addr);
253
254 // Used by TurnPortTest to mimic a case where proxy returns local host address 277 // Used by TurnPortTest to mimic a case where proxy returns local host address
255 // instead of the original one TurnPort was bound against. Please see WebRTC 278 // instead of the original one TurnPort was bound against. Please see WebRTC
256 // issue 3927 for more detail. 279 // issue 3927 for more detail.
257 void SetAlternativeLocalAddress(const SocketAddress& addr); 280 void SetAlternativeLocalAddress(const SocketAddress& addr);
258 281
259 int Bind(const SocketAddress& addr) override; 282 int Bind(const SocketAddress& addr) override;
260 int Connect(const SocketAddress& addr) override; 283 int Connect(const SocketAddress& addr) override;
261 int Close() override; 284 int Close() override;
262 int Send(const void* pv, size_t cb) override; 285 int Send(const void* pv, size_t cb) override;
263 int SendTo(const void* pv, size_t cb, const SocketAddress& addr) override; 286 int SendTo(const void* pv, size_t cb, const SocketAddress& addr) override;
(...skipping 26 matching lines...) Expand all
290 typedef std::deque<NetworkEntry> NetworkQueue; 313 typedef std::deque<NetworkEntry> NetworkQueue;
291 typedef std::vector<char> SendBuffer; 314 typedef std::vector<char> SendBuffer;
292 typedef std::list<Packet*> RecvBuffer; 315 typedef std::list<Packet*> RecvBuffer;
293 typedef std::map<Option, int> OptionsMap; 316 typedef std::map<Option, int> OptionsMap;
294 317
295 int InitiateConnect(const SocketAddress& addr, bool use_delay); 318 int InitiateConnect(const SocketAddress& addr, bool use_delay);
296 void CompleteConnect(const SocketAddress& addr, bool notify); 319 void CompleteConnect(const SocketAddress& addr, bool notify);
297 int SendUdp(const void* pv, size_t cb, const SocketAddress& addr); 320 int SendUdp(const void* pv, size_t cb, const SocketAddress& addr);
298 int SendTcp(const void* pv, size_t cb); 321 int SendTcp(const void* pv, size_t cb);
299 322
323 // Used by server sockets to set the local address without binding.
324 void SetLocalAddress(const SocketAddress& addr);
325
300 VirtualSocketServer* server_; 326 VirtualSocketServer* server_;
301 int family_; 327 int family_;
302 int type_; 328 int type_;
303 bool async_; 329 bool async_;
304 ConnState state_; 330 ConnState state_;
305 int error_; 331 int error_;
306 SocketAddress local_addr_; 332 SocketAddress local_addr_;
307 SocketAddress alternative_local_addr_; 333 SocketAddress alternative_local_addr_;
308 SocketAddress remote_addr_; 334 SocketAddress remote_addr_;
309 335
(...skipping 27 matching lines...) Expand all
337 363
338 // Store the options that are set 364 // Store the options that are set
339 OptionsMap options_map_; 365 OptionsMap options_map_;
340 366
341 friend class VirtualSocketServer; 367 friend class VirtualSocketServer;
342 }; 368 };
343 369
344 } // namespace rtc 370 } // namespace rtc
345 371
346 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_ 372 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/virtualsocketserver.cc » ('j') | webrtc/base/virtualsocketserver.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698