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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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), | 78 receiving(false), |
80 timeout(false), | 79 timeout(false), |
81 new_connection(false), | 80 new_connection(false), |
82 rtt(0), | 81 rtt(0), |
83 sent_total_bytes(0), | 82 sent_total_bytes(0), |
84 sent_bytes_second(0), | 83 sent_bytes_second(0), |
85 sent_discarded_packets(0), | 84 sent_discarded_packets(0), |
86 sent_total_packets(0), | 85 sent_total_packets(0), |
87 recv_total_bytes(0), | 86 recv_total_bytes(0), |
88 recv_bytes_second(0), | 87 recv_bytes_second(0), |
89 key(NULL) {} | 88 key(NULL) {} |
90 | 89 |
91 bool best_connection; // Is this the best connection we have? | 90 bool best_connection; // Is this the best connection we have? |
92 bool writable; // Has this connection received a STUN response? | 91 bool writable; // Has this connection received a STUN response? |
93 bool readable; // Has this connection received a STUN request? | 92 bool receiving; // Has this connection received anything? |
94 bool timeout; // Has this connection timed out? | 93 bool timeout; // Has this connection timed out? |
95 bool new_connection; // Is this a newly created connection? | 94 bool new_connection; // Is this a newly created connection? |
96 size_t rtt; // The STUN RTT for this connection. | 95 size_t rtt; // The STUN RTT for this connection. |
97 size_t sent_total_bytes; // Total bytes sent on this connection. | 96 size_t sent_total_bytes; // Total bytes sent on this connection. |
98 size_t sent_bytes_second; // Bps over the last measurement interval. | 97 size_t sent_bytes_second; // Bps over the last measurement interval. |
99 size_t sent_discarded_packets; // Number of outgoing packets discarded due to | 98 size_t sent_discarded_packets; // Number of outgoing packets discarded due to |
100 // socket errors. | 99 // socket errors. |
101 size_t sent_total_packets; // Number of total outgoing packets attempted for | 100 size_t sent_total_packets; // Number of total outgoing packets attempted for |
102 // sending. | 101 // sending. |
103 | 102 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 rtc::Thread* signaling_thread() const { return signaling_thread_; } | 148 rtc::Thread* signaling_thread() const { return signaling_thread_; } |
150 // Returns the worker thread. The actual networking is done on this thread. | 149 // Returns the worker thread. The actual networking is done on this thread. |
151 rtc::Thread* worker_thread() const { return worker_thread_; } | 150 rtc::Thread* worker_thread() const { return worker_thread_; } |
152 | 151 |
153 // Returns the content_name of this transport. | 152 // Returns the content_name of this transport. |
154 const std::string& content_name() const { return content_name_; } | 153 const std::string& content_name() const { return content_name_; } |
155 | 154 |
156 // Returns the port allocator object for this transport. | 155 // Returns the port allocator object for this transport. |
157 PortAllocator* port_allocator() { return allocator_; } | 156 PortAllocator* port_allocator() { return allocator_; } |
158 | 157 |
159 // Returns the readable and states of this manager. These bits are the ORs | 158 // 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 | 159 // of the corresponding bits on the managed channels. Each time one of these |
161 // states changes, a signal is raised. | 160 // states changes, a signal is raised. |
162 // TODO: Replace uses of readable() and writable() with | 161 // TODO(honghaiz): Replace uses of writable() with any_channels_writable(). |
163 // any_channels_readable() and any_channels_writable(). | |
164 bool readable() const { return any_channels_readable(); } | |
165 bool writable() const { return any_channels_writable(); } | 162 bool writable() const { return any_channels_writable(); } |
166 bool was_writable() const { return was_writable_; } | 163 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 { | 164 bool any_channels_writable() const { |
172 return (writable_ == TRANSPORT_STATE_SOME || | 165 return (writable_ == TRANSPORT_STATE_SOME || |
173 writable_ == TRANSPORT_STATE_ALL); | 166 writable_ == TRANSPORT_STATE_ALL); |
174 } | 167 } |
175 bool all_channels_readable() const { | |
176 return (readable_ == TRANSPORT_STATE_ALL); | |
177 } | |
178 bool all_channels_writable() const { | 168 bool all_channels_writable() const { |
179 return (writable_ == TRANSPORT_STATE_ALL); | 169 return (writable_ == TRANSPORT_STATE_ALL); |
180 } | 170 } |
181 bool any_channel_receiving() const { | 171 bool any_channel_receiving() const { |
182 return (receiving_ == TRANSPORT_STATE_SOME || | 172 return (receiving_ == TRANSPORT_STATE_SOME || |
183 receiving_ == TRANSPORT_STATE_ALL); | 173 receiving_ == TRANSPORT_STATE_ALL); |
184 } | 174 } |
185 | 175 |
186 sigslot::signal1<Transport*> SignalReadableState; | |
187 sigslot::signal1<Transport*> SignalWritableState; | 176 sigslot::signal1<Transport*> SignalWritableState; |
188 sigslot::signal1<Transport*> SignalReceivingState; | 177 sigslot::signal1<Transport*> SignalReceivingState; |
189 sigslot::signal1<Transport*> SignalCompleted; | 178 sigslot::signal1<Transport*> SignalCompleted; |
190 sigslot::signal1<Transport*> SignalFailed; | 179 sigslot::signal1<Transport*> SignalFailed; |
191 | 180 |
192 // Returns whether the client has requested the channels to connect. | 181 // Returns whether the client has requested the channels to connect. |
193 bool connect_requested() const { return connect_requested_; } | 182 bool connect_requested() const { return connect_requested_; } |
194 | 183 |
195 void SetIceRole(IceRole role); | 184 void SetIceRole(IceRole role); |
196 IceRole ice_role() const { return ice_role_; } | 185 IceRole ice_role() const { return ice_role_; } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 | 356 |
368 private: | 357 private: |
369 TransportChannelImpl *impl_; | 358 TransportChannelImpl *impl_; |
370 bool candidates_allocated_; | 359 bool candidates_allocated_; |
371 int ref_; | 360 int ref_; |
372 }; | 361 }; |
373 | 362 |
374 // Candidate component => ChannelMapEntry | 363 // Candidate component => ChannelMapEntry |
375 typedef std::map<int, ChannelMapEntry> ChannelMap; | 364 typedef std::map<int, ChannelMapEntry> ChannelMap; |
376 | 365 |
377 // Called when the state of a channel changes. | 366 // Called when the write state of a channel changes. |
378 void OnChannelReadableState(TransportChannel* channel); | |
379 void OnChannelWritableState(TransportChannel* channel); | 367 void OnChannelWritableState(TransportChannel* channel); |
380 | 368 |
381 // Called when the receiving state of a channel changes. | 369 // Called when the receiving state of a channel changes. |
382 void OnChannelReceivingState(TransportChannel* channel); | 370 void OnChannelReceivingState(TransportChannel* channel); |
383 | 371 |
384 // Called when a channel requests signaling. | 372 // Called when a channel requests signaling. |
385 void OnChannelRequestSignaling(TransportChannelImpl* channel); | 373 void OnChannelRequestSignaling(TransportChannelImpl* channel); |
386 | 374 |
387 // Called when a candidate is ready from remote peer. | 375 // Called when a candidate is ready from remote peer. |
388 void OnRemoteCandidate(const Candidate& candidate); | 376 void OnRemoteCandidate(const Candidate& candidate); |
(...skipping 13 matching lines...) Expand all Loading... |
402 | 390 |
403 // These are versions of the above methods that are called only on a | 391 // 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 | 392 // particular thread (s = signaling, w = worker). The above methods post or |
405 // send a message to invoke this version. | 393 // send a message to invoke this version. |
406 TransportChannelImpl* CreateChannel_w(int component); | 394 TransportChannelImpl* CreateChannel_w(int component); |
407 void DestroyChannel_w(int component); | 395 void DestroyChannel_w(int component); |
408 void ConnectChannels_w(); | 396 void ConnectChannels_w(); |
409 void ResetChannels_w(); | 397 void ResetChannels_w(); |
410 void DestroyAllChannels_w(); | 398 void DestroyAllChannels_w(); |
411 void OnRemoteCandidate_w(const Candidate& candidate); | 399 void OnRemoteCandidate_w(const Candidate& candidate); |
412 void OnChannelReadableState_s(); | |
413 void OnChannelWritableState_s(); | 400 void OnChannelWritableState_s(); |
414 void OnChannelReceivingState_s(); | 401 void OnChannelReceivingState_s(); |
415 void OnChannelRequestSignaling_s(); | 402 void OnChannelRequestSignaling_s(); |
416 void OnConnecting_s(); | 403 void OnConnecting_s(); |
417 void OnChannelRouteChange_s(const TransportChannel* channel, | 404 void OnChannelRouteChange_s(const TransportChannel* channel, |
418 const Candidate& remote_candidate); | 405 const Candidate& remote_candidate); |
419 void OnChannelCandidatesAllocationDone_s(); | 406 void OnChannelCandidatesAllocationDone_s(); |
420 | 407 |
421 // Helper function that invokes the given function on every channel. | 408 // Helper function that invokes the given function on every channel. |
422 typedef void (TransportChannelImpl::* TransportChannelFunc)(); | 409 typedef void (TransportChannelImpl::* TransportChannelFunc)(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // Protects changes to channels and messages | 456 // Protects changes to channels and messages |
470 rtc::CriticalSection crit_; | 457 rtc::CriticalSection crit_; |
471 | 458 |
472 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); | 459 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); |
473 }; | 460 }; |
474 | 461 |
475 | 462 |
476 } // namespace cricket | 463 } // namespace cricket |
477 | 464 |
478 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ | 465 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ |
OLD | NEW |