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

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

Issue 2989303002: Make Port (and subclasses) fully "Network"-based, instead of IP-based. (Closed)
Patch Set: Add back Port constructor that takes IP for backwards compatibility. Created 3 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 | « webrtc/p2p/client/basicportallocator.cc ('k') | webrtc/rtc_base/virtualsocketserver.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 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 // SocketServer: 112 // SocketServer:
113 void SetMessageQueue(MessageQueue* queue) override; 113 void SetMessageQueue(MessageQueue* queue) override;
114 bool Wait(int cms, bool process_io) override; 114 bool Wait(int cms, bool process_io) override;
115 void WakeUp() override; 115 void WakeUp() override;
116 116
117 void SetDelayOnAddress(const rtc::SocketAddress& address, int delay_ms) { 117 void SetDelayOnAddress(const rtc::SocketAddress& address, int delay_ms) {
118 delay_by_ip_[address.ipaddr()] = delay_ms; 118 delay_by_ip_[address.ipaddr()] = delay_ms;
119 } 119 }
120 120
121 // Used by TurnPortTest and TcpPortTest (for example), to mimic a case where
122 // a proxy returns the local host address instead of the original one the
123 // port was bound against. Please see WebRTC issue 3927 for more detail.
124 //
125 // If SetAlternativeLocalAddress(A, B) is called, then when something
126 // attempts to bind a socket to address A, it will get a socket bound to
127 // address B instead.
128 void SetAlternativeLocalAddress(const rtc::IPAddress& address,
129 const rtc::IPAddress& alternative);
130
121 typedef std::pair<double, double> Point; 131 typedef std::pair<double, double> Point;
122 typedef std::vector<Point> Function; 132 typedef std::vector<Point> Function;
123 133
124 static Function* CreateDistribution(uint32_t mean, 134 static Function* CreateDistribution(uint32_t mean,
125 uint32_t stddev, 135 uint32_t stddev,
126 uint32_t samples); 136 uint32_t samples);
127 137
128 // Similar to Thread::ProcessMessages, but it only processes messages until 138 // Similar to Thread::ProcessMessages, but it only processes messages until
129 // there are no immediate messages or pending network traffic. Returns false 139 // there are no immediate messages or pending network traffic. Returns false
130 // if Thread::Stop() was called. 140 // if Thread::Stop() was called.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 276
267 uint32_t bandwidth_; 277 uint32_t bandwidth_;
268 uint32_t network_capacity_; 278 uint32_t network_capacity_;
269 uint32_t send_buffer_capacity_; 279 uint32_t send_buffer_capacity_;
270 uint32_t recv_buffer_capacity_; 280 uint32_t recv_buffer_capacity_;
271 uint32_t delay_mean_; 281 uint32_t delay_mean_;
272 uint32_t delay_stddev_; 282 uint32_t delay_stddev_;
273 uint32_t delay_samples_; 283 uint32_t delay_samples_;
274 284
275 std::map<rtc::IPAddress, int> delay_by_ip_; 285 std::map<rtc::IPAddress, int> delay_by_ip_;
286 std::map<rtc::IPAddress, rtc::IPAddress> alternative_address_mapping_;
276 std::unique_ptr<Function> delay_dist_; 287 std::unique_ptr<Function> delay_dist_;
277 288
278 CriticalSection delay_crit_; 289 CriticalSection delay_crit_;
279 290
280 double drop_prob_; 291 double drop_prob_;
281 bool sending_blocked_ = false; 292 bool sending_blocked_ = false;
282 RTC_DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer); 293 RTC_DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer);
283 }; 294 };
284 295
285 // Implements the socket interface using the virtual network. Packets are 296 // Implements the socket interface using the virtual network. Packets are
286 // passed as messages using the message queue of the socket server. 297 // passed as messages using the message queue of the socket server.
287 class VirtualSocket : public AsyncSocket, 298 class VirtualSocket : public AsyncSocket,
288 public MessageHandler, 299 public MessageHandler,
289 public sigslot::has_slots<> { 300 public sigslot::has_slots<> {
290 public: 301 public:
291 VirtualSocket(VirtualSocketServer* server, int family, int type, bool async); 302 VirtualSocket(VirtualSocketServer* server, int family, int type, bool async);
292 ~VirtualSocket() override; 303 ~VirtualSocket() override;
293 304
294 SocketAddress GetLocalAddress() const override; 305 SocketAddress GetLocalAddress() const override;
295 SocketAddress GetRemoteAddress() const override; 306 SocketAddress GetRemoteAddress() const override;
296 307
297 // Used by TurnPortTest to mimic a case where proxy returns local host address
298 // instead of the original one TurnPort was bound against. Please see WebRTC
299 // issue 3927 for more detail.
300 void SetAlternativeLocalAddress(const SocketAddress& addr);
301
302 int Bind(const SocketAddress& addr) override; 308 int Bind(const SocketAddress& addr) override;
303 int Connect(const SocketAddress& addr) override; 309 int Connect(const SocketAddress& addr) override;
304 int Close() override; 310 int Close() override;
305 int Send(const void* pv, size_t cb) override; 311 int Send(const void* pv, size_t cb) override;
306 int SendTo(const void* pv, size_t cb, const SocketAddress& addr) override; 312 int SendTo(const void* pv, size_t cb, const SocketAddress& addr) override;
307 int Recv(void* pv, size_t cb, int64_t* timestamp) override; 313 int Recv(void* pv, size_t cb, int64_t* timestamp) override;
308 int RecvFrom(void* pv, 314 int RecvFrom(void* pv,
309 size_t cb, 315 size_t cb,
310 SocketAddress* paddr, 316 SocketAddress* paddr,
311 int64_t* timestamp) override; 317 int64_t* timestamp) override;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 void SetLocalAddress(const SocketAddress& addr); 352 void SetLocalAddress(const SocketAddress& addr);
347 353
348 void OnSocketServerReadyToSend(); 354 void OnSocketServerReadyToSend();
349 355
350 VirtualSocketServer* server_; 356 VirtualSocketServer* server_;
351 int type_; 357 int type_;
352 bool async_; 358 bool async_;
353 ConnState state_; 359 ConnState state_;
354 int error_; 360 int error_;
355 SocketAddress local_addr_; 361 SocketAddress local_addr_;
356 SocketAddress alternative_local_addr_;
357 SocketAddress remote_addr_; 362 SocketAddress remote_addr_;
358 363
359 // Pending sockets which can be Accepted 364 // Pending sockets which can be Accepted
360 ListenQueue* listen_queue_; 365 ListenQueue* listen_queue_;
361 366
362 // Data which tcp has buffered for sending 367 // Data which tcp has buffered for sending
363 SendBuffer send_buffer_; 368 SendBuffer send_buffer_;
364 // Set to false if the last attempt to send resulted in EWOULDBLOCK. 369 // Set to false if the last attempt to send resulted in EWOULDBLOCK.
365 // Set back to true when the socket can send again. 370 // Set back to true when the socket can send again.
366 bool ready_to_send_ = true; 371 bool ready_to_send_ = true;
(...skipping 24 matching lines...) Expand all
391 396
392 // Store the options that are set 397 // Store the options that are set
393 OptionsMap options_map_; 398 OptionsMap options_map_;
394 399
395 friend class VirtualSocketServer; 400 friend class VirtualSocketServer;
396 }; 401 };
397 402
398 } // namespace rtc 403 } // namespace rtc
399 404
400 #endif // WEBRTC_RTC_BASE_VIRTUALSOCKETSERVER_H_ 405 #endif // WEBRTC_RTC_BASE_VIRTUALSOCKETSERVER_H_
OLDNEW
« no previous file with comments | « webrtc/p2p/client/basicportallocator.cc ('k') | webrtc/rtc_base/virtualsocketserver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698