OLD | NEW |
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 Socket* CreateSocket(int family, int type) override; | 105 Socket* CreateSocket(int family, int type) override; |
106 | 106 |
107 AsyncSocket* CreateAsyncSocket(int type) override; | 107 AsyncSocket* CreateAsyncSocket(int type) override; |
108 AsyncSocket* CreateAsyncSocket(int family, int type) override; | 108 AsyncSocket* CreateAsyncSocket(int family, int type) override; |
109 | 109 |
110 // SocketServer: | 110 // SocketServer: |
111 void SetMessageQueue(MessageQueue* queue) override; | 111 void SetMessageQueue(MessageQueue* queue) override; |
112 bool Wait(int cms, bool process_io) override; | 112 bool Wait(int cms, bool process_io) override; |
113 void WakeUp() override; | 113 void WakeUp() override; |
114 | 114 |
| 115 void SetDelayOnSocketAddress(const rtc::SocketAddress& address, |
| 116 int delay_ms) { |
| 117 delays_[address] = delay_ms; |
| 118 } |
| 119 |
115 typedef std::pair<double, double> Point; | 120 typedef std::pair<double, double> Point; |
116 typedef std::vector<Point> Function; | 121 typedef std::vector<Point> Function; |
117 | 122 |
118 static Function* CreateDistribution(uint32_t mean, | 123 static Function* CreateDistribution(uint32_t mean, |
119 uint32_t stddev, | 124 uint32_t stddev, |
120 uint32_t samples); | 125 uint32_t samples); |
121 | 126 |
122 // Similar to Thread::ProcessMessages, but it only processes messages until | 127 // Similar to Thread::ProcessMessages, but it only processes messages until |
123 // there are no immediate messages or pending network traffic. Returns false | 128 // there are no immediate messages or pending network traffic. Returns false |
124 // if Thread::Stop() was called. | 129 // if Thread::Stop() was called. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 size_t data_size, | 192 size_t data_size, |
188 size_t header_size, | 193 size_t header_size, |
189 bool ordered); | 194 bool ordered); |
190 | 195 |
191 // Removes stale packets from the network | 196 // Removes stale packets from the network |
192 void PurgeNetworkPackets(VirtualSocket* socket, int64_t cur_time); | 197 void PurgeNetworkPackets(VirtualSocket* socket, int64_t cur_time); |
193 | 198 |
194 // Computes the number of milliseconds required to send a packet of this size. | 199 // Computes the number of milliseconds required to send a packet of this size. |
195 uint32_t SendDelay(uint32_t size); | 200 uint32_t SendDelay(uint32_t size); |
196 | 201 |
197 // Returns a random transit delay chosen from the appropriate distribution. | 202 // If the delay has been set for the address of the socket, returns the set |
198 uint32_t GetRandomTransitDelay(); | 203 // delay. Otherwise, returns a random transit delay chosen from the |
| 204 // appropriate distribution. |
| 205 uint32_t GetTransitDelay(Socket* socket); |
199 | 206 |
200 // Basic operations on functions. Those that return a function also take | 207 // Basic operations on functions. Those that return a function also take |
201 // ownership of the function given (and hence, may modify or delete it). | 208 // ownership of the function given (and hence, may modify or delete it). |
202 static Function* Accumulate(Function* f); | 209 static Function* Accumulate(Function* f); |
203 static Function* Invert(Function* f); | 210 static Function* Invert(Function* f); |
204 static Function* Resample(Function* f, | 211 static Function* Resample(Function* f, |
205 double x1, | 212 double x1, |
206 double x2, | 213 double x2, |
207 uint32_t samples); | 214 uint32_t samples); |
208 static double Evaluate(Function* f, double x); | 215 static double Evaluate(Function* f, double x); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 IPAddress default_route_v4_; | 260 IPAddress default_route_v4_; |
254 IPAddress default_route_v6_; | 261 IPAddress default_route_v6_; |
255 | 262 |
256 uint32_t bandwidth_; | 263 uint32_t bandwidth_; |
257 uint32_t network_capacity_; | 264 uint32_t network_capacity_; |
258 uint32_t send_buffer_capacity_; | 265 uint32_t send_buffer_capacity_; |
259 uint32_t recv_buffer_capacity_; | 266 uint32_t recv_buffer_capacity_; |
260 uint32_t delay_mean_; | 267 uint32_t delay_mean_; |
261 uint32_t delay_stddev_; | 268 uint32_t delay_stddev_; |
262 uint32_t delay_samples_; | 269 uint32_t delay_samples_; |
263 Function* delay_dist_; | 270 |
| 271 std::map<rtc::SocketAddress, int> delays_; |
| 272 std::unique_ptr<Function> delay_dist_; |
| 273 |
264 CriticalSection delay_crit_; | 274 CriticalSection delay_crit_; |
265 | 275 |
266 double drop_prob_; | 276 double drop_prob_; |
267 bool sending_blocked_ = false; | 277 bool sending_blocked_ = false; |
268 RTC_DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer); | 278 RTC_DISALLOW_COPY_AND_ASSIGN(VirtualSocketServer); |
269 }; | 279 }; |
270 | 280 |
271 // Implements the socket interface using the virtual network. Packets are | 281 // Implements the socket interface using the virtual network. Packets are |
272 // passed as messages using the message queue of the socket server. | 282 // passed as messages using the message queue of the socket server. |
273 class VirtualSocket : public AsyncSocket, | 283 class VirtualSocket : public AsyncSocket, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 385 |
376 // Store the options that are set | 386 // Store the options that are set |
377 OptionsMap options_map_; | 387 OptionsMap options_map_; |
378 | 388 |
379 friend class VirtualSocketServer; | 389 friend class VirtualSocketServer; |
380 }; | 390 }; |
381 | 391 |
382 } // namespace rtc | 392 } // namespace rtc |
383 | 393 |
384 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_ | 394 #endif // WEBRTC_BASE_VIRTUALSOCKETSERVER_H_ |
OLD | NEW |