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

Side by Side Diff: webrtc/p2p/base/transport.h

Issue 1351673003: Replace readable with receiving where receiving means receiving anything (stun ping, response or da… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: One line comment change in the dtlstransportchannel.cc Created 5 years, 3 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
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 namespace cricket { 49 namespace cricket {
50 50
51 class PortAllocator; 51 class PortAllocator;
52 class TransportChannel; 52 class TransportChannel;
53 class TransportChannelImpl; 53 class TransportChannelImpl;
54 54
55 typedef std::vector<Candidate> Candidates; 55 typedef std::vector<Candidate> Candidates;
56 56
57 // For "writable", "readable", and "receiving", we need to differentiate between 57 // For "writable" and "receiving", we need to differentiate between
58 // none, all, and some. 58 // none, all, and some.
59 enum TransportState { 59 enum TransportState {
60 TRANSPORT_STATE_NONE = 0, 60 TRANSPORT_STATE_NONE = 0,
61 TRANSPORT_STATE_SOME, 61 TRANSPORT_STATE_SOME,
62 TRANSPORT_STATE_ALL 62 TRANSPORT_STATE_ALL
63 }; 63 };
64 64
65 // When checking transport state, we need to differentiate between 65 // When checking transport state, we need to differentiate between
66 // "readable", "writable", or "receiving" check. 66 // "writable" or "receiving" check.
67 enum TransportStateType { 67 enum TransportStateType {
68 TRANSPORT_READABLE_STATE = 0, 68 TRANSPORT_WRITABLE_STATE = 0,
69 TRANSPORT_WRITABLE_STATE,
70 TRANSPORT_RECEIVING_STATE 69 TRANSPORT_RECEIVING_STATE
71 }; 70 };
72 71
73 // Stats that we can return about the connections for a transport channel. 72 // Stats that we can return about the connections for a transport channel.
74 // TODO(hta): Rename to ConnectionStats 73 // TODO(hta): Rename to ConnectionStats
75 struct ConnectionInfo { 74 struct ConnectionInfo {
76 ConnectionInfo() 75 ConnectionInfo()
77 : best_connection(false), 76 : best_connection(false),
78 writable(false), 77 writable(false),
79 readable(false),
80 timeout(false), 78 timeout(false),
81 new_connection(false), 79 new_connection(false),
82 rtt(0), 80 rtt(0),
83 sent_total_bytes(0), 81 sent_total_bytes(0),
84 sent_bytes_second(0), 82 sent_bytes_second(0),
85 sent_discarded_packets(0), 83 sent_discarded_packets(0),
86 sent_total_packets(0), 84 sent_total_packets(0),
87 recv_total_bytes(0), 85 recv_total_bytes(0),
88 recv_bytes_second(0), 86 recv_bytes_second(0),
89 key(NULL) {} 87 key(NULL) {}
90 88
91 bool best_connection; // Is this the best connection we have? 89 bool best_connection; // Is this the best connection we have?
92 bool writable; // Has this connection received a STUN response? 90 bool writable; // Has this connection received a STUN response?
93 bool readable; // Has this connection received a STUN request? 91 bool receiving; // Has this connection received anything?
94 bool timeout; // Has this connection timed out? 92 bool timeout; // Has this connection timed out?
95 bool new_connection; // Is this a newly created connection? 93 bool new_connection; // Is this a newly created connection?
96 size_t rtt; // The STUN RTT for this connection. 94 size_t rtt; // The STUN RTT for this connection.
97 size_t sent_total_bytes; // Total bytes sent on this connection. 95 size_t sent_total_bytes; // Total bytes sent on this connection.
98 size_t sent_bytes_second; // Bps over the last measurement interval. 96 size_t sent_bytes_second; // Bps over the last measurement interval.
99 size_t sent_discarded_packets; // Number of outgoing packets discarded due to 97 size_t sent_discarded_packets; // Number of outgoing packets discarded due to
100 // socket errors. 98 // socket errors.
101 size_t sent_total_packets; // Number of total outgoing packets attempted for 99 size_t sent_total_packets; // Number of total outgoing packets attempted for
102 // sending. 100 // sending.
103 101
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 rtc::Thread* signaling_thread() const { return signaling_thread_; } 147 rtc::Thread* signaling_thread() const { return signaling_thread_; }
150 // Returns the worker thread. The actual networking is done on this thread. 148 // Returns the worker thread. The actual networking is done on this thread.
151 rtc::Thread* worker_thread() const { return worker_thread_; } 149 rtc::Thread* worker_thread() const { return worker_thread_; }
152 150
153 // Returns the content_name of this transport. 151 // Returns the content_name of this transport.
154 const std::string& content_name() const { return content_name_; } 152 const std::string& content_name() const { return content_name_; }
155 153
156 // Returns the port allocator object for this transport. 154 // Returns the port allocator object for this transport.
157 PortAllocator* port_allocator() { return allocator_; } 155 PortAllocator* port_allocator() { return allocator_; }
158 156
159 // Returns the readable and states of this manager. These bits are the ORs 157 // Returns the states of this manager. These bits are the ORs
160 // of the corresponding bits on the managed channels. Each time one of these 158 // of the corresponding bits on the managed channels. Each time one of these
161 // states changes, a signal is raised. 159 // states changes, a signal is raised.
162 // TODO: Replace uses of readable() and writable() with
163 // any_channels_readable() and any_channels_writable().
164 bool readable() const { return any_channels_readable(); }
165 bool writable() const { return any_channels_writable(); }
166 bool was_writable() const { return was_writable_; } 160 bool was_writable() const { return was_writable_; }
167 bool any_channels_readable() const {
168 return (readable_ == TRANSPORT_STATE_SOME ||
169 readable_ == TRANSPORT_STATE_ALL);
170 }
171 bool any_channels_writable() const { 161 bool any_channels_writable() const {
172 return (writable_ == TRANSPORT_STATE_SOME || 162 return (writable_ == TRANSPORT_STATE_SOME ||
173 writable_ == TRANSPORT_STATE_ALL); 163 writable_ == TRANSPORT_STATE_ALL);
174 } 164 }
175 bool all_channels_readable() const {
176 return (readable_ == TRANSPORT_STATE_ALL);
177 }
178 bool all_channels_writable() const { 165 bool all_channels_writable() const {
179 return (writable_ == TRANSPORT_STATE_ALL); 166 return (writable_ == TRANSPORT_STATE_ALL);
180 } 167 }
181 bool any_channel_receiving() const { 168 bool any_channel_receiving() const {
182 return (receiving_ == TRANSPORT_STATE_SOME || 169 return (receiving_ == TRANSPORT_STATE_SOME ||
183 receiving_ == TRANSPORT_STATE_ALL); 170 receiving_ == TRANSPORT_STATE_ALL);
184 } 171 }
185 172
186 sigslot::signal1<Transport*> SignalReadableState;
187 sigslot::signal1<Transport*> SignalWritableState; 173 sigslot::signal1<Transport*> SignalWritableState;
188 sigslot::signal1<Transport*> SignalReceivingState; 174 sigslot::signal1<Transport*> SignalReceivingState;
189 sigslot::signal1<Transport*> SignalCompleted; 175 sigslot::signal1<Transport*> SignalCompleted;
190 sigslot::signal1<Transport*> SignalFailed; 176 sigslot::signal1<Transport*> SignalFailed;
191 177
192 // Returns whether the client has requested the channels to connect. 178 // Returns whether the client has requested the channels to connect.
193 bool connect_requested() const { return connect_requested_; } 179 bool connect_requested() const { return connect_requested_; }
194 180
195 void SetIceRole(IceRole role); 181 void SetIceRole(IceRole role);
196 IceRole ice_role() const { return ice_role_; } 182 IceRole ice_role() const { return ice_role_; }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 353
368 private: 354 private:
369 TransportChannelImpl *impl_; 355 TransportChannelImpl *impl_;
370 bool candidates_allocated_; 356 bool candidates_allocated_;
371 int ref_; 357 int ref_;
372 }; 358 };
373 359
374 // Candidate component => ChannelMapEntry 360 // Candidate component => ChannelMapEntry
375 typedef std::map<int, ChannelMapEntry> ChannelMap; 361 typedef std::map<int, ChannelMapEntry> ChannelMap;
376 362
377 // Called when the state of a channel changes. 363 // Called when the write state of a channel changes.
378 void OnChannelReadableState(TransportChannel* channel);
379 void OnChannelWritableState(TransportChannel* channel); 364 void OnChannelWritableState(TransportChannel* channel);
380 365
381 // Called when the receiving state of a channel changes. 366 // Called when the receiving state of a channel changes.
382 void OnChannelReceivingState(TransportChannel* channel); 367 void OnChannelReceivingState(TransportChannel* channel);
383 368
384 // Called when a channel requests signaling. 369 // Called when a channel requests signaling.
385 void OnChannelRequestSignaling(TransportChannelImpl* channel); 370 void OnChannelRequestSignaling(TransportChannelImpl* channel);
386 371
387 // Called when a candidate is ready from remote peer. 372 // Called when a candidate is ready from remote peer.
388 void OnRemoteCandidate(const Candidate& candidate); 373 void OnRemoteCandidate(const Candidate& candidate);
(...skipping 13 matching lines...) Expand all
402 387
403 // These are versions of the above methods that are called only on a 388 // These are versions of the above methods that are called only on a
404 // particular thread (s = signaling, w = worker). The above methods post or 389 // particular thread (s = signaling, w = worker). The above methods post or
405 // send a message to invoke this version. 390 // send a message to invoke this version.
406 TransportChannelImpl* CreateChannel_w(int component); 391 TransportChannelImpl* CreateChannel_w(int component);
407 void DestroyChannel_w(int component); 392 void DestroyChannel_w(int component);
408 void ConnectChannels_w(); 393 void ConnectChannels_w();
409 void ResetChannels_w(); 394 void ResetChannels_w();
410 void DestroyAllChannels_w(); 395 void DestroyAllChannels_w();
411 void OnRemoteCandidate_w(const Candidate& candidate); 396 void OnRemoteCandidate_w(const Candidate& candidate);
412 void OnChannelReadableState_s();
413 void OnChannelWritableState_s(); 397 void OnChannelWritableState_s();
414 void OnChannelReceivingState_s(); 398 void OnChannelReceivingState_s();
415 void OnChannelRequestSignaling_s(); 399 void OnChannelRequestSignaling_s();
416 void OnConnecting_s(); 400 void OnConnecting_s();
417 void OnChannelRouteChange_s(const TransportChannel* channel, 401 void OnChannelRouteChange_s(const TransportChannel* channel,
418 const Candidate& remote_candidate); 402 const Candidate& remote_candidate);
419 void OnChannelCandidatesAllocationDone_s(); 403 void OnChannelCandidatesAllocationDone_s();
420 404
421 // Helper function that invokes the given function on every channel. 405 // Helper function that invokes the given function on every channel.
422 typedef void (TransportChannelImpl::* TransportChannelFunc)(); 406 typedef void (TransportChannelImpl::* TransportChannelFunc)();
(...skipping 19 matching lines...) Expand all
442 void SetChannelReceivingTimeout_w(int timeout_ms); 426 void SetChannelReceivingTimeout_w(int timeout_ms);
443 427
444 // Sends SignalCompleted if we are now in that state. 428 // Sends SignalCompleted if we are now in that state.
445 void MaybeCompleted_w(); 429 void MaybeCompleted_w();
446 430
447 rtc::Thread* const signaling_thread_; 431 rtc::Thread* const signaling_thread_;
448 rtc::Thread* const worker_thread_; 432 rtc::Thread* const worker_thread_;
449 const std::string content_name_; 433 const std::string content_name_;
450 PortAllocator* const allocator_; 434 PortAllocator* const allocator_;
451 bool destroyed_; 435 bool destroyed_;
452 TransportState readable_;
453 TransportState writable_; 436 TransportState writable_;
454 TransportState receiving_; 437 TransportState receiving_;
455 bool was_writable_; 438 bool was_writable_;
456 bool connect_requested_; 439 bool connect_requested_;
457 IceRole ice_role_; 440 IceRole ice_role_;
458 uint64 tiebreaker_; 441 uint64 tiebreaker_;
459 IceMode remote_ice_mode_; 442 IceMode remote_ice_mode_;
460 int channel_receiving_timeout_; 443 int channel_receiving_timeout_;
461 rtc::scoped_ptr<TransportDescription> local_description_; 444 rtc::scoped_ptr<TransportDescription> local_description_;
462 rtc::scoped_ptr<TransportDescription> remote_description_; 445 rtc::scoped_ptr<TransportDescription> remote_description_;
463 446
464 // TODO(tommi): Make sure we only use this on the worker thread. 447 // TODO(tommi): Make sure we only use this on the worker thread.
465 ChannelMap channels_; 448 ChannelMap channels_;
466 // Buffers the ready_candidates so that SignalCanidatesReady can 449 // Buffers the ready_candidates so that SignalCanidatesReady can
467 // provide them in multiples. 450 // provide them in multiples.
468 std::vector<Candidate> ready_candidates_; 451 std::vector<Candidate> ready_candidates_;
469 // Protects changes to channels and messages 452 // Protects changes to channels and messages
470 rtc::CriticalSection crit_; 453 rtc::CriticalSection crit_;
471 454
472 DISALLOW_COPY_AND_ASSIGN(Transport); 455 DISALLOW_COPY_AND_ASSIGN(Transport);
473 }; 456 };
474 457
475 458
476 } // namespace cricket 459 } // namespace cricket
477 460
478 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ 461 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698