blob: 93ef28882668f3a85a86c8b827e2f175352dd853 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:261/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 17:11:0011#ifndef RTC_BASE_VIRTUAL_SOCKET_SERVER_H_
12#define RTC_BASE_VIRTUAL_SOCKET_SERVER_H_
henrike@webrtc.orgf0488722014-05-13 18:00:2613
Henrik Kjellanderec78f1c2017-06-29 05:52:5014#include <deque>
15#include <map>
Steve Antonf4172382020-01-27 23:45:0216#include <vector>
henrike@webrtc.orgf0488722014-05-13 18:00:2617
Danil Chapovalovbabdaa862022-09-16 10:41:1118#include "absl/types/optional.h"
19#include "api/make_ref_counted.h"
20#include "api/ref_counted_base.h"
21#include "api/scoped_refptr.h"
22#include "api/task_queue/task_queue_base.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3123#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3124#include "rtc_base/event.h"
Steve Anton10542f22019-01-11 17:11:0025#include "rtc_base/fake_clock.h"
Steve Anton10542f22019-01-11 17:11:0026#include "rtc_base/socket_server.h"
Niels Möllerc413c552021-06-22 08:03:1427#include "rtc_base/synchronization/mutex.h"
Henrik Kjellanderec78f1c2017-06-29 05:52:5028
29namespace rtc {
30
31class Packet;
Niels Möllerea423a52021-08-19 08:13:3132class VirtualSocketServer;
Henrik Kjellanderec78f1c2017-06-29 05:52:5033class SocketAddressPair;
34
Danil Chapovalovbabdaa862022-09-16 10:41:1135// Implements the socket interface using the virtual network. Packets are
36// passed in tasks using the thread of the socket server.
37class VirtualSocket : public Socket, public sigslot::has_slots<> {
Niels Möllerea423a52021-08-19 08:13:3138 public:
39 VirtualSocket(VirtualSocketServer* server, int family, int type);
40 ~VirtualSocket() override;
41
42 SocketAddress GetLocalAddress() const override;
43 SocketAddress GetRemoteAddress() const override;
44
45 int Bind(const SocketAddress& addr) override;
46 int Connect(const SocketAddress& addr) override;
47 int Close() override;
48 int Send(const void* pv, size_t cb) override;
49 int SendTo(const void* pv, size_t cb, const SocketAddress& addr) override;
50 int Recv(void* pv, size_t cb, int64_t* timestamp) override;
51 int RecvFrom(void* pv,
52 size_t cb,
53 SocketAddress* paddr,
54 int64_t* timestamp) override;
55 int Listen(int backlog) override;
56 VirtualSocket* Accept(SocketAddress* paddr) override;
57
58 int GetError() const override;
59 void SetError(int error) override;
60 ConnState GetState() const override;
61 int GetOption(Option opt, int* value) override;
62 int SetOption(Option opt, int value) override;
Niels Möllerea423a52021-08-19 08:13:3163
64 size_t recv_buffer_size() const { return recv_buffer_size_; }
65 size_t send_buffer_size() const { return send_buffer_.size(); }
66 const char* send_buffer_data() const { return send_buffer_.data(); }
67
68 // Used by server sockets to set the local address without binding.
69 void SetLocalAddress(const SocketAddress& addr);
70
71 bool was_any() { return was_any_; }
72 void set_was_any(bool was_any) { was_any_ = was_any; }
73
74 void SetToBlocked();
75
76 void UpdateRecv(size_t data_size);
77 void UpdateSend(size_t data_size);
78
79 void MaybeSignalWriteEvent(size_t capacity);
80
81 // Adds a packet to be sent. Returns delay, based on network_size_.
82 uint32_t AddPacket(int64_t cur_time, size_t packet_size);
83
84 int64_t UpdateOrderedDelivery(int64_t ts);
85
86 // Removes stale packets from the network. Returns current size.
87 size_t PurgeNetworkPackets(int64_t cur_time);
88
Danil Chapovalovbabdaa862022-09-16 10:41:1189 void PostPacket(webrtc::TimeDelta delay, std::unique_ptr<Packet> packet);
90 void PostConnect(webrtc::TimeDelta delay, const SocketAddress& remote_addr);
91 void PostDisconnect(webrtc::TimeDelta delay);
92
Niels Möllerea423a52021-08-19 08:13:3193 private:
Danil Chapovalovbabdaa862022-09-16 10:41:1194 // Struct shared with pending tasks that may outlive VirtualSocket.
95 class SafetyBlock : public RefCountedNonVirtual<SafetyBlock> {
96 public:
97 explicit SafetyBlock(VirtualSocket* socket);
98 SafetyBlock(const SafetyBlock&) = delete;
99 SafetyBlock& operator=(const SafetyBlock&) = delete;
100 ~SafetyBlock();
101
102 // Prohibits posted delayed task to access owning VirtualSocket and
103 // cleanups members protected by the `mutex`.
104 void SetNotAlive();
105 bool IsAlive();
106
107 // Copies up to `size` bytes into buffer from the next received packet
108 // and fills `addr` with remote address of that received packet.
109 // Returns number of bytes copied or negative value on failure.
110 int RecvFrom(void* buffer, size_t size, SocketAddress& addr);
111
112 void Listen();
113
114 struct AcceptResult {
115 int error = 0;
116 std::unique_ptr<VirtualSocket> socket;
117 SocketAddress remote_addr;
118 };
119 AcceptResult Accept();
120
121 bool AddPacket(std::unique_ptr<Packet> packet);
122 void PostConnect(webrtc::TimeDelta delay, const SocketAddress& remote_addr);
123
124 private:
125 enum class Signal { kNone, kReadEvent, kConnectEvent };
126 // `PostConnect` rely on the fact that std::list iterators are not
127 // invalidated on any changes to other elements in the container.
128 using PostedConnects = std::list<SocketAddress>;
129
130 void PostSignalReadEvent() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
131 void MaybeSignalReadEvent();
132 Signal Connect(PostedConnects::iterator remote_addr_it);
133
134 webrtc::Mutex mutex_;
135 VirtualSocket& socket_;
136 bool alive_ RTC_GUARDED_BY(mutex_) = true;
137 // Flag indicating if async Task to signal SignalReadEvent is posted.
138 // To avoid posting multiple such tasks.
139 bool pending_read_signal_event_ RTC_GUARDED_BY(mutex_) = false;
140
141 // Members below do not need to outlive VirtualSocket, but are used by the
142 // posted tasks. Keeping them in the VirtualSocket confuses thread
143 // annotations because they can't detect that locked mutex is the same mutex
144 // this members are guarded by.
145
146 // Addresses of the sockets for potential connect. For each address there
147 // is a posted task that should finilze the connect.
148 PostedConnects posted_connects_ RTC_GUARDED_BY(mutex_);
149
150 // Data which has been received from the network
151 std::list<std::unique_ptr<Packet>> recv_buffer_ RTC_GUARDED_BY(mutex_);
152
153 // Pending sockets which can be Accepted
154 absl::optional<std::deque<SocketAddress>> listen_queue_
155 RTC_GUARDED_BY(mutex_);
156 };
157
Niels Möllerea423a52021-08-19 08:13:31158 struct NetworkEntry {
159 size_t size;
160 int64_t done_time;
161 };
162
Niels Möllerea423a52021-08-19 08:13:31163 typedef std::deque<NetworkEntry> NetworkQueue;
164 typedef std::vector<char> SendBuffer;
Niels Möllerea423a52021-08-19 08:13:31165 typedef std::map<Option, int> OptionsMap;
166
167 int InitiateConnect(const SocketAddress& addr, bool use_delay);
168 void CompleteConnect(const SocketAddress& addr);
169 int SendUdp(const void* pv, size_t cb, const SocketAddress& addr);
170 int SendTcp(const void* pv, size_t cb);
171
172 void OnSocketServerReadyToSend();
173
174 VirtualSocketServer* const server_;
175 const int type_;
176 ConnState state_;
177 int error_;
178 SocketAddress local_addr_;
179 SocketAddress remote_addr_;
180
Danil Chapovalovbabdaa862022-09-16 10:41:11181 const scoped_refptr<SafetyBlock> safety_ =
182 make_ref_counted<SafetyBlock>(this);
Niels Möllerea423a52021-08-19 08:13:31183
184 // Data which tcp has buffered for sending
185 SendBuffer send_buffer_;
186 // Set to false if the last attempt to send resulted in EWOULDBLOCK.
187 // Set back to true when the socket can send again.
188 bool ready_to_send_ = true;
189
Niels Möllerea423a52021-08-19 08:13:31190 // Network model that enforces bandwidth and capacity constraints
191 NetworkQueue network_;
192 size_t network_size_;
193 // The scheduled delivery time of the last packet sent on this socket.
194 // It is used to ensure ordered delivery of packets sent on this socket.
195 int64_t last_delivery_time_ = 0;
196
Niels Möllerea423a52021-08-19 08:13:31197 // The amount of data which is in flight or in recv_buffer_
198 size_t recv_buffer_size_;
199
200 // Is this socket bound?
201 bool bound_;
202
203 // When we bind a socket to Any, VSS's Bind gives it another address. For
204 // dual-stack sockets, we want to distinguish between sockets that were
205 // explicitly given a particular address and sockets that had one picked
206 // for them by VSS.
207 bool was_any_;
208
209 // Store the options that are set
210 OptionsMap options_map_;
211};
212
Henrik Kjellanderec78f1c2017-06-29 05:52:50213// Simulates a network in the same manner as a loopback interface. The
214// interface can create as many addresses as you want. All of the sockets
215// created by this network will be able to communicate with one another, unless
216// they are bound to addresses from incompatible families.
Niels Möller9bd24572021-04-19 10:18:27217class VirtualSocketServer : public SocketServer {
Henrik Kjellanderec78f1c2017-06-29 05:52:50218 public:
219 VirtualSocketServer();
220 // This constructor needs to be used if the test uses a fake clock and
221 // ProcessMessagesUntilIdle, since ProcessMessagesUntilIdle needs a way of
222 // advancing time.
Sebastian Janssond624c392019-04-17 08:36:03223 explicit VirtualSocketServer(ThreadProcessingFakeClock* fake_clock);
Henrik Kjellanderec78f1c2017-06-29 05:52:50224 ~VirtualSocketServer() override;
225
Byoungchan Lee14af7622022-01-11 20:24:58226 VirtualSocketServer(const VirtualSocketServer&) = delete;
227 VirtualSocketServer& operator=(const VirtualSocketServer&) = delete;
228
Niels Möller84d15952021-09-01 08:50:34229 // The default source address specifies which local address to use when a
230 // socket is bound to the 'any' address, e.g. 0.0.0.0. (If not set, the 'any'
231 // address is used as the source address on outgoing virtual packets, exposed
232 // to recipient's RecvFrom).
233 IPAddress GetDefaultSourceAddress(int family);
234 void SetDefaultSourceAddress(const IPAddress& from_addr);
Henrik Kjellanderec78f1c2017-06-29 05:52:50235
236 // Limits the network bandwidth (maximum bytes per second). Zero means that
237 // all sends occur instantly. Defaults to 0.
Florent Castellif94c0532021-11-16 12:29:53238 void set_bandwidth(uint32_t bandwidth) RTC_LOCKS_EXCLUDED(mutex_);
Henrik Kjellanderec78f1c2017-06-29 05:52:50239
240 // Limits the amount of data which can be in flight on the network without
241 // packet loss (on a per sender basis). Defaults to 64 KB.
Florent Castellif94c0532021-11-16 12:29:53242 void set_network_capacity(uint32_t capacity) RTC_LOCKS_EXCLUDED(mutex_);
Henrik Kjellanderec78f1c2017-06-29 05:52:50243
244 // The amount of data which can be buffered by tcp on the sender's side
Florent Castellif94c0532021-11-16 12:29:53245 uint32_t send_buffer_capacity() const RTC_LOCKS_EXCLUDED(mutex_);
246 void set_send_buffer_capacity(uint32_t capacity) RTC_LOCKS_EXCLUDED(mutex_);
Henrik Kjellanderec78f1c2017-06-29 05:52:50247
248 // The amount of data which can be buffered by tcp on the receiver's side
Florent Castellif94c0532021-11-16 12:29:53249 uint32_t recv_buffer_capacity() const RTC_LOCKS_EXCLUDED(mutex_);
250 void set_recv_buffer_capacity(uint32_t capacity) RTC_LOCKS_EXCLUDED(mutex_);
Henrik Kjellanderec78f1c2017-06-29 05:52:50251
252 // Controls the (transit) delay for packets sent in the network. This does
253 // not inclue the time required to sit in the send queue. Both of these
254 // values are measured in milliseconds. Defaults to no delay.
Florent Castellif94c0532021-11-16 12:29:53255 void set_delay_mean(uint32_t delay_mean) RTC_LOCKS_EXCLUDED(mutex_);
256 void set_delay_stddev(uint32_t delay_stddev) RTC_LOCKS_EXCLUDED(mutex_);
257 void set_delay_samples(uint32_t delay_samples) RTC_LOCKS_EXCLUDED(mutex_);
Henrik Kjellanderec78f1c2017-06-29 05:52:50258
259 // If the (transit) delay parameters are modified, this method should be
260 // called to recompute the new distribution.
Florent Castellif94c0532021-11-16 12:29:53261 void UpdateDelayDistribution() RTC_LOCKS_EXCLUDED(mutex_);
Henrik Kjellanderec78f1c2017-06-29 05:52:50262
263 // Controls the (uniform) probability that any sent packet is dropped. This
264 // is separate from calculations to drop based on queue size.
Florent Castellif94c0532021-11-16 12:29:53265 void set_drop_probability(double drop_prob) RTC_LOCKS_EXCLUDED(mutex_);
Henrik Kjellanderec78f1c2017-06-29 05:52:50266
Harald Alvestrand3d792e92021-03-10 07:29:28267 // Controls the maximum UDP payload for the networks simulated
268 // by this server. Any UDP payload sent that is larger than this will
269 // be dropped.
Florent Castellif94c0532021-11-16 12:29:53270 void set_max_udp_payload(size_t payload_size) RTC_LOCKS_EXCLUDED(mutex_);
Harald Alvestrand3d792e92021-03-10 07:29:28271
Artem Titov96e3b992021-07-26 14:03:14272 // If `blocked` is true, subsequent attempts to send will result in -1 being
Henrik Kjellanderec78f1c2017-06-29 05:52:50273 // returned, with the socket error set to EWOULDBLOCK.
274 //
Artem Titov96e3b992021-07-26 14:03:14275 // If this method is later called with `blocked` set to false, any sockets
Henrik Kjellanderec78f1c2017-06-29 05:52:50276 // that previously failed to send with EWOULDBLOCK will emit SignalWriteEvent.
277 //
278 // This can be used to simulate the send buffer on a network interface being
279 // full, and test functionality related to EWOULDBLOCK/SignalWriteEvent.
Florent Castellif94c0532021-11-16 12:29:53280 void SetSendingBlocked(bool blocked) RTC_LOCKS_EXCLUDED(mutex_);
Henrik Kjellanderec78f1c2017-06-29 05:52:50281
282 // SocketFactory:
Niels Möllerea423a52021-08-19 08:13:31283 VirtualSocket* CreateSocket(int family, int type) override;
Henrik Kjellanderec78f1c2017-06-29 05:52:50284
285 // SocketServer:
Sebastian Jansson290de822020-01-09 13:20:23286 void SetMessageQueue(Thread* queue) override;
Markus Handell9a21c492022-08-25 11:40:13287 bool Wait(webrtc::TimeDelta max_wait_duration, bool process_io) override;
Henrik Kjellanderec78f1c2017-06-29 05:52:50288 void WakeUp() override;
289
290 void SetDelayOnAddress(const rtc::SocketAddress& address, int delay_ms) {
291 delay_by_ip_[address.ipaddr()] = delay_ms;
292 }
293
deadbeef5c3c1042017-08-04 22:01:57294 // Used by TurnPortTest and TcpPortTest (for example), to mimic a case where
295 // a proxy returns the local host address instead of the original one the
296 // port was bound against. Please see WebRTC issue 3927 for more detail.
297 //
298 // If SetAlternativeLocalAddress(A, B) is called, then when something
299 // attempts to bind a socket to address A, it will get a socket bound to
300 // address B instead.
301 void SetAlternativeLocalAddress(const rtc::IPAddress& address,
302 const rtc::IPAddress& alternative);
303
Henrik Kjellanderec78f1c2017-06-29 05:52:50304 typedef std::pair<double, double> Point;
305 typedef std::vector<Point> Function;
306
Niels Möller983627c2021-02-09 14:12:28307 static std::unique_ptr<Function> CreateDistribution(uint32_t mean,
308 uint32_t stddev,
309 uint32_t samples);
Henrik Kjellanderec78f1c2017-06-29 05:52:50310
311 // Similar to Thread::ProcessMessages, but it only processes messages until
312 // there are no immediate messages or pending network traffic. Returns false
313 // if Thread::Stop() was called.
314 bool ProcessMessagesUntilIdle();
315
316 // Sets the next port number to use for testing.
317 void SetNextPortForTesting(uint16_t port);
318
319 // Close a pair of Tcp connections by addresses. Both connections will have
320 // its own OnClose invoked.
321 bool CloseTcpConnections(const SocketAddress& addr_local,
322 const SocketAddress& addr_remote);
323
Taylor Brandstetter389a97c2018-01-04 00:26:06324 // Number of packets that clients have attempted to send through this virtual
325 // socket server. Intended to be used for test assertions.
Florent Castellif94c0532021-11-16 12:29:53326 uint32_t sent_packets() const RTC_LOCKS_EXCLUDED(mutex_);
Taylor Brandstetter389a97c2018-01-04 00:26:06327
Niels Möllerc2d8f1e2021-08-24 13:49:34328 // Assign IP and Port if application's address is unspecified. Also apply
329 // `alternative_address_mapping_`.
330 SocketAddress AssignBindAddress(const SocketAddress& app_addr);
Henrik Kjellanderec78f1c2017-06-29 05:52:50331
332 // Binds the given socket to the given (fully-defined) address.
333 int Bind(VirtualSocket* socket, const SocketAddress& addr);
334
Henrik Kjellanderec78f1c2017-06-29 05:52:50335 int Unbind(const SocketAddress& addr, VirtualSocket* socket);
336
337 // Adds a mapping between this socket pair and the socket.
338 void AddConnection(const SocketAddress& client,
339 const SocketAddress& server,
340 VirtualSocket* socket);
341
Henrik Kjellanderec78f1c2017-06-29 05:52:50342 // Connects the given socket to the socket at the given address
Yves Gerey665174f2018-06-19 13:03:05343 int Connect(VirtualSocket* socket,
344 const SocketAddress& remote_addr,
Henrik Kjellanderec78f1c2017-06-29 05:52:50345 bool use_delay);
346
347 // Sends a disconnect message to the socket at the given address
348 bool Disconnect(VirtualSocket* socket);
349
Niels Möllerc79bd432021-02-16 08:25:52350 // Lookup address, and disconnect corresponding socket.
351 bool Disconnect(const SocketAddress& addr);
352
353 // Lookup connection, close corresponding socket.
354 bool Disconnect(const SocketAddress& local_addr,
355 const SocketAddress& remote_addr);
356
Henrik Kjellanderec78f1c2017-06-29 05:52:50357 // Sends the given packet to the socket at the given address (if one exists).
Yves Gerey665174f2018-06-19 13:03:05358 int SendUdp(VirtualSocket* socket,
359 const char* data,
360 size_t data_size,
Henrik Kjellanderec78f1c2017-06-29 05:52:50361 const SocketAddress& remote_addr);
362
363 // Moves as much data as possible from the sender's buffer to the network
Florent Castellif94c0532021-11-16 12:29:53364 void SendTcp(VirtualSocket* socket) RTC_LOCKS_EXCLUDED(mutex_);
Henrik Kjellanderec78f1c2017-06-29 05:52:50365
Niels Möllerc79bd432021-02-16 08:25:52366 // Like above, but lookup sender by address.
Florent Castellif94c0532021-11-16 12:29:53367 void SendTcp(const SocketAddress& addr) RTC_LOCKS_EXCLUDED(mutex_);
Niels Möllerc79bd432021-02-16 08:25:52368
369 // Computes the number of milliseconds required to send a packet of this size.
Florent Castellif94c0532021-11-16 12:29:53370 uint32_t SendDelay(uint32_t size) RTC_LOCKS_EXCLUDED(mutex_);
Niels Möllerc79bd432021-02-16 08:25:52371
Niels Möllerc79bd432021-02-16 08:25:52372 // Sending was previously blocked, but now isn't.
373 sigslot::signal0<> SignalReadyToSend;
374
375 protected:
376 // Returns a new IP not used before in this network.
377 IPAddress GetNextIP(int family);
378
379 // Find the socket bound to the given address
380 VirtualSocket* LookupBinding(const SocketAddress& addr);
381
382 private:
Danil Chapovalovbabdaa862022-09-16 10:41:11383 friend VirtualSocket;
Niels Möllerc79bd432021-02-16 08:25:52384 uint16_t GetNextPort();
385
Niels Möllerc79bd432021-02-16 08:25:52386 // Find the socket pair corresponding to this server address.
387 VirtualSocket* LookupConnection(const SocketAddress& client,
388 const SocketAddress& server);
389
390 void RemoveConnection(const SocketAddress& client,
391 const SocketAddress& server);
392
Henrik Kjellanderec78f1c2017-06-29 05:52:50393 // Places a packet on the network.
394 void AddPacketToNetwork(VirtualSocket* socket,
395 VirtualSocket* recipient,
396 int64_t cur_time,
397 const char* data,
398 size_t data_size,
399 size_t header_size,
400 bool ordered);
401
Henrik Kjellanderec78f1c2017-06-29 05:52:50402 // If the delay has been set for the address of the socket, returns the set
403 // delay. Otherwise, returns a random transit delay chosen from the
404 // appropriate distribution.
405 uint32_t GetTransitDelay(Socket* socket);
406
Niels Möller983627c2021-02-09 14:12:28407 // Basic operations on functions.
408 static std::unique_ptr<Function> Accumulate(std::unique_ptr<Function> f);
409 static std::unique_ptr<Function> Invert(std::unique_ptr<Function> f);
410 static std::unique_ptr<Function> Resample(std::unique_ptr<Function> f,
411 double x1,
412 double x2,
413 uint32_t samples);
414 static double Evaluate(const Function* f, double x);
Henrik Kjellanderec78f1c2017-06-29 05:52:50415
Henrik Kjellanderec78f1c2017-06-29 05:52:50416 // Determine if two sockets should be able to communicate.
417 // We don't (currently) specify an address family for sockets; instead,
418 // the currently bound address is used to infer the address family.
419 // Any socket that is not explicitly bound to an IPv4 address is assumed to be
420 // dual-stack capable.
421 // This function tests if two addresses can communicate, as well as the
422 // sockets to which they may be bound (the addresses may or may not yet be
423 // bound to the sockets).
424 // First the addresses are tested (after normalization):
425 // If both have the same family, then communication is OK.
426 // If only one is IPv4 then false, unless the other is bound to ::.
427 // This applies even if the IPv4 address is 0.0.0.0.
428 // The socket arguments are optional; the sockets are checked to see if they
429 // were explicitly bound to IPv6-any ('::'), and if so communication is
430 // permitted.
431 // NB: This scheme doesn't permit non-dualstack IPv6 sockets.
432 static bool CanInteractWith(VirtualSocket* local, VirtualSocket* remote);
433
Henrik Kjellanderec78f1c2017-06-29 05:52:50434 typedef std::map<SocketAddress, VirtualSocket*> AddressMap;
435 typedef std::map<SocketAddressPair, VirtualSocket*> ConnectionMap;
436
437 // May be null if the test doesn't use a fake clock, or it does but doesn't
438 // use ProcessMessagesUntilIdle.
Sebastian Janssond624c392019-04-17 08:36:03439 ThreadProcessingFakeClock* fake_clock_ = nullptr;
Henrik Kjellanderec78f1c2017-06-29 05:52:50440
441 // Used to implement Wait/WakeUp.
442 Event wakeup_;
Sebastian Jansson290de822020-01-09 13:20:23443 Thread* msg_queue_;
Henrik Kjellanderec78f1c2017-06-29 05:52:50444 bool stop_on_idle_;
445 in_addr next_ipv4_;
446 in6_addr next_ipv6_;
447 uint16_t next_port_;
448 AddressMap* bindings_;
449 ConnectionMap* connections_;
450
Niels Möller84d15952021-09-01 08:50:34451 IPAddress default_source_address_v4_;
452 IPAddress default_source_address_v6_;
Henrik Kjellanderec78f1c2017-06-29 05:52:50453
Florent Castellif94c0532021-11-16 12:29:53454 mutable webrtc::Mutex mutex_;
455
456 uint32_t bandwidth_ RTC_GUARDED_BY(mutex_);
457 uint32_t network_capacity_ RTC_GUARDED_BY(mutex_);
458 uint32_t send_buffer_capacity_ RTC_GUARDED_BY(mutex_);
459 uint32_t recv_buffer_capacity_ RTC_GUARDED_BY(mutex_);
460 uint32_t delay_mean_ RTC_GUARDED_BY(mutex_);
461 uint32_t delay_stddev_ RTC_GUARDED_BY(mutex_);
462 uint32_t delay_samples_ RTC_GUARDED_BY(mutex_);
Henrik Kjellanderec78f1c2017-06-29 05:52:50463
Taylor Brandstetter389a97c2018-01-04 00:26:06464 // Used for testing.
Florent Castellif94c0532021-11-16 12:29:53465 uint32_t sent_packets_ RTC_GUARDED_BY(mutex_) = 0;
Taylor Brandstetter389a97c2018-01-04 00:26:06466
Henrik Kjellanderec78f1c2017-06-29 05:52:50467 std::map<rtc::IPAddress, int> delay_by_ip_;
deadbeef5c3c1042017-08-04 22:01:57468 std::map<rtc::IPAddress, rtc::IPAddress> alternative_address_mapping_;
Henrik Kjellanderec78f1c2017-06-29 05:52:50469 std::unique_ptr<Function> delay_dist_;
470
Florent Castellif94c0532021-11-16 12:29:53471 double drop_prob_ RTC_GUARDED_BY(mutex_);
Harald Alvestrand3d792e92021-03-10 07:29:28472 // The largest UDP payload permitted on this virtual socket server.
473 // The default is the max size of IPv4 fragmented UDP packet payload:
474 // 65535 bytes - 8 bytes UDP header - 20 bytes IP header.
Florent Castellif94c0532021-11-16 12:29:53475 size_t max_udp_payload_ RTC_GUARDED_BY(mutex_) = 65507;
Harald Alvestrand3d792e92021-03-10 07:29:28476
Florent Castellif94c0532021-11-16 12:29:53477 bool sending_blocked_ RTC_GUARDED_BY(mutex_) = false;
Henrik Kjellanderec78f1c2017-06-29 05:52:50478};
479
Henrik Kjellanderec78f1c2017-06-29 05:52:50480} // namespace rtc
henrike@webrtc.orgf0488722014-05-13 18:00:26481
Steve Anton10542f22019-01-11 17:11:00482#endif // RTC_BASE_VIRTUAL_SOCKET_SERVER_H_