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

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 20 matching lines...) Expand all
31 // they are bound to addresses from incompatible families. 31 // they are bound to addresses from incompatible families.
32 class VirtualSocketServer : public SocketServer, public sigslot::has_slots<> { 32 class VirtualSocketServer : public SocketServer, public sigslot::has_slots<> {
33 public: 33 public:
34 // TODO: Add "owned" parameter. 34 // TODO: Add "owned" parameter.
35 // If "owned" is set, the supplied socketserver will be deleted later. 35 // If "owned" is set, the supplied socketserver will be deleted later.
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 // Default route will be used when a binding is done against the any address.
juberti1 2015/08/06 23:43:21 // The default route indicates which local address
guoweis_webrtc 2015/08/07 18:03:43 Done.
42 const IPAddress GetDefaultRoute(int family);
juberti1 2015/08/06 23:43:21 'const' not useful on by-value types
guoweis_webrtc 2015/08/07 18:03:43 Done.
43 void SetDefaultRoute(const IPAddress& ipaddr);
juberti1 2015/08/06 23:43:21 Make it clear this is the source address, i.e. cal
guoweis_webrtc 2015/08/07 18:03:43 Done.
44
41 // Limits the network bandwidth (maximum bytes per second). Zero means that 45 // Limits the network bandwidth (maximum bytes per second). Zero means that
42 // all sends occur instantly. Defaults to 0. 46 // all sends occur instantly. Defaults to 0.
43 uint32 bandwidth() const { return bandwidth_; } 47 uint32 bandwidth() const { return bandwidth_; }
44 void set_bandwidth(uint32 bandwidth) { bandwidth_ = bandwidth; } 48 void set_bandwidth(uint32 bandwidth) { bandwidth_ = bandwidth; }
45 49
46 // Limits the amount of data which can be in flight on the network without 50 // 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. 51 // packet loss (on a per sender basis). Defaults to 64 KB.
48 uint32 network_capacity() const { return network_capacity_; } 52 uint32 network_capacity() const { return network_capacity_; }
49 void set_network_capacity(uint32 capacity) { 53 void set_network_capacity(uint32 capacity) {
50 network_capacity_ = capacity; 54 network_capacity_ = capacity;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // Close a pair of Tcp connections by addresses. Both connections will have 121 // Close a pair of Tcp connections by addresses. Both connections will have
118 // its own OnClose invoked. 122 // its own OnClose invoked.
119 bool CloseTcpConnections(const SocketAddress& addr_local, 123 bool CloseTcpConnections(const SocketAddress& addr_local,
120 const SocketAddress& addr_remote); 124 const SocketAddress& addr_remote);
121 125
122 protected: 126 protected:
123 // Returns a new IP not used before in this network. 127 // Returns a new IP not used before in this network.
124 IPAddress GetNextIP(int family); 128 IPAddress GetNextIP(int family);
125 uint16 GetNextPort(); 129 uint16 GetNextPort();
126 130
131 // Helper function to return the binding from the any address to default
132 // interface.
133 const SocketAddress GetDefaultRouteIfNecessary(const SocketAddress& addr);
juberti1 2015/08/06 23:43:21 see comment above about const
guoweis_webrtc 2015/08/07 18:03:43 Done.
134
127 VirtualSocket* CreateSocketInternal(int family, int type); 135 VirtualSocket* CreateSocketInternal(int family, int type);
128 136
129 // Binds the given socket to addr, assigning and IP and Port if necessary 137 // Binds the given socket to addr, assigning and IP and Port if necessary
130 int Bind(VirtualSocket* socket, SocketAddress* addr); 138 int Bind(VirtualSocket* socket, SocketAddress* addr);
131 139
132 // Binds the given socket to the given (fully-defined) address. 140 // Binds the given socket to the given (fully-defined) address.
133 int Bind(VirtualSocket* socket, const SocketAddress& addr); 141 int Bind(VirtualSocket* socket, const SocketAddress& addr);
134 142
135 // Find the socket bound to the given address 143 // Find the socket bound to the given address
136 VirtualSocket* LookupBinding(const SocketAddress& addr); 144 VirtualSocket* LookupBinding(const SocketAddress& addr);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 bool server_owned_; 225 bool server_owned_;
218 MessageQueue* msg_queue_; 226 MessageQueue* msg_queue_;
219 bool stop_on_idle_; 227 bool stop_on_idle_;
220 uint32 network_delay_; 228 uint32 network_delay_;
221 in_addr next_ipv4_; 229 in_addr next_ipv4_;
222 in6_addr next_ipv6_; 230 in6_addr next_ipv6_;
223 uint16 next_port_; 231 uint16 next_port_;
224 AddressMap* bindings_; 232 AddressMap* bindings_;
225 ConnectionMap* connections_; 233 ConnectionMap* connections_;
226 234
235 IPAddress default_route_v4_;
236 IPAddress default_route_v6_;
237
227 uint32 bandwidth_; 238 uint32 bandwidth_;
228 uint32 network_capacity_; 239 uint32 network_capacity_;
229 uint32 send_buffer_capacity_; 240 uint32 send_buffer_capacity_;
230 uint32 recv_buffer_capacity_; 241 uint32 recv_buffer_capacity_;
231 uint32 delay_mean_; 242 uint32 delay_mean_;
232 uint32 delay_stddev_; 243 uint32 delay_stddev_;
233 uint32 delay_samples_; 244 uint32 delay_samples_;
234 Function* delay_dist_; 245 Function* delay_dist_;
235 CriticalSection delay_crit_; 246 CriticalSection delay_crit_;
236 247
237 double drop_prob_; 248 double drop_prob_;
238 DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer); 249 DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer);
239 }; 250 };
240 251
241 // Implements the socket interface using the virtual network. Packets are 252 // Implements the socket interface using the virtual network. Packets are
242 // passed as messages using the message queue of the socket server. 253 // passed as messages using the message queue of the socket server.
243 class VirtualSocket : public AsyncSocket, public MessageHandler { 254 class VirtualSocket : public AsyncSocket, public MessageHandler {
244 public: 255 public:
245 VirtualSocket(VirtualSocketServer* server, int family, int type, bool async); 256 VirtualSocket(VirtualSocketServer* server, int family, int type, bool async);
246 ~VirtualSocket() override; 257 ~VirtualSocket() override;
247 258
248 SocketAddress GetLocalAddress() const override; 259 SocketAddress GetLocalAddress() const override;
249 SocketAddress GetRemoteAddress() const override; 260 SocketAddress GetRemoteAddress() const override;
250 261
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 262 // 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 263 // instead of the original one TurnPort was bound against. Please see WebRTC
256 // issue 3927 for more detail. 264 // issue 3927 for more detail.
257 void SetAlternativeLocalAddress(const SocketAddress& addr); 265 void SetAlternativeLocalAddress(const SocketAddress& addr);
258 266
259 int Bind(const SocketAddress& addr) override; 267 int Bind(const SocketAddress& addr) override;
260 int Connect(const SocketAddress& addr) override; 268 int Connect(const SocketAddress& addr) override;
261 int Close() override; 269 int Close() override;
262 int Send(const void* pv, size_t cb) override; 270 int Send(const void* pv, size_t cb) override;
263 int SendTo(const void* pv, size_t cb, const SocketAddress& addr) override; 271 int SendTo(const void* pv, size_t cb, const SocketAddress& addr) override;
(...skipping 26 matching lines...) Expand all
290 typedef std::deque<NetworkEntry> NetworkQueue; 298 typedef std::deque<NetworkEntry> NetworkQueue;
291 typedef std::vector<char> SendBuffer; 299 typedef std::vector<char> SendBuffer;
292 typedef std::list<Packet*> RecvBuffer; 300 typedef std::list<Packet*> RecvBuffer;
293 typedef std::map<Option, int> OptionsMap; 301 typedef std::map<Option, int> OptionsMap;
294 302
295 int InitiateConnect(const SocketAddress& addr, bool use_delay); 303 int InitiateConnect(const SocketAddress& addr, bool use_delay);
296 void CompleteConnect(const SocketAddress& addr, bool notify); 304 void CompleteConnect(const SocketAddress& addr, bool notify);
297 int SendUdp(const void* pv, size_t cb, const SocketAddress& addr); 305 int SendUdp(const void* pv, size_t cb, const SocketAddress& addr);
298 int SendTcp(const void* pv, size_t cb); 306 int SendTcp(const void* pv, size_t cb);
299 307
308 // Used by server sockets to set the local address without binding.
309 void SetLocalAddress(const SocketAddress& addr);
310
300 VirtualSocketServer* server_; 311 VirtualSocketServer* server_;
301 int family_; 312 int family_;
302 int type_; 313 int type_;
303 bool async_; 314 bool async_;
304 ConnState state_; 315 ConnState state_;
305 int error_; 316 int error_;
306 SocketAddress local_addr_; 317 SocketAddress local_addr_;
307 SocketAddress alternative_local_addr_; 318 SocketAddress alternative_local_addr_;
308 SocketAddress remote_addr_; 319 SocketAddress remote_addr_;
309 320
(...skipping 27 matching lines...) Expand all
337 348
338 // Store the options that are set 349 // Store the options that are set
339 OptionsMap options_map_; 350 OptionsMap options_map_;
340 351
341 friend class VirtualSocketServer; 352 friend class VirtualSocketServer;
342 }; 353 };
343 354
344 } // namespace rtc 355 } // namespace rtc
345 356
346 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_ 357 #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