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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 LOCAL_PORT_TYPE, | 85 LOCAL_PORT_TYPE, |
86 factory, | 86 factory, |
87 network, | 87 network, |
88 ip, | 88 ip, |
89 min_port, | 89 min_port, |
90 max_port, | 90 max_port, |
91 username, | 91 username, |
92 password), | 92 password), |
93 incoming_only_(false), | 93 incoming_only_(false), |
94 allow_listen_(allow_listen), | 94 allow_listen_(allow_listen), |
95 socket_(NULL), | 95 socket_(nullptr), |
96 error_(0) { | 96 error_(0) { |
97 // TODO(mallinath) - Set preference value as per RFC 6544. | 97 // TODO(mallinath) - Set preference value as per RFC 6544. |
98 // http://b/issue?id=7141794 | 98 // http://b/issue?id=7141794 |
99 } | 99 } |
100 | 100 |
101 bool TCPPort::Init() { | 101 bool TCPPort::Init() { |
102 if (allow_listen_) { | 102 if (allow_listen_) { |
103 // Treat failure to create or bind a TCP socket as fatal. This | 103 // Treat failure to create or bind a TCP socket as fatal. This |
104 // should never happen. | 104 // should never happen. |
105 socket_ = socket_factory()->CreateServerTcpSocket( | 105 socket_ = socket_factory()->CreateServerTcpSocket( |
(...skipping 13 matching lines...) Expand all Loading... |
119 delete socket_; | 119 delete socket_; |
120 std::list<Incoming>::iterator it; | 120 std::list<Incoming>::iterator it; |
121 for (it = incoming_.begin(); it != incoming_.end(); ++it) | 121 for (it = incoming_.begin(); it != incoming_.end(); ++it) |
122 delete it->socket; | 122 delete it->socket; |
123 incoming_.clear(); | 123 incoming_.clear(); |
124 } | 124 } |
125 | 125 |
126 Connection* TCPPort::CreateConnection(const Candidate& address, | 126 Connection* TCPPort::CreateConnection(const Candidate& address, |
127 CandidateOrigin origin) { | 127 CandidateOrigin origin) { |
128 if (!SupportsProtocol(address.protocol())) { | 128 if (!SupportsProtocol(address.protocol())) { |
129 return NULL; | 129 return nullptr; |
130 } | 130 } |
131 | 131 |
132 if (address.tcptype() == TCPTYPE_ACTIVE_STR || | 132 if (address.tcptype() == TCPTYPE_ACTIVE_STR || |
133 (address.tcptype().empty() && address.address().port() == 0)) { | 133 (address.tcptype().empty() && address.address().port() == 0)) { |
134 // It's active only candidate, we should not try to create connections | 134 // It's active only candidate, we should not try to create connections |
135 // for these candidates. | 135 // for these candidates. |
136 return NULL; | 136 return nullptr; |
137 } | 137 } |
138 | 138 |
139 // We can't accept TCP connections incoming on other ports | 139 // We can't accept TCP connections incoming on other ports |
140 if (origin == ORIGIN_OTHER_PORT) | 140 if (origin == ORIGIN_OTHER_PORT) |
141 return NULL; | 141 return nullptr; |
142 | 142 |
143 // Check if we are allowed to make outgoing TCP connections | 143 // Check if we are allowed to make outgoing TCP connections |
144 if (incoming_only_ && (origin == ORIGIN_MESSAGE)) | 144 if (incoming_only_ && (origin == ORIGIN_MESSAGE)) |
145 return NULL; | 145 return nullptr; |
146 | 146 |
147 // We don't know how to act as an ssl server yet | 147 // We don't know how to act as an ssl server yet |
148 if ((address.protocol() == SSLTCP_PROTOCOL_NAME) && | 148 if ((address.protocol() == SSLTCP_PROTOCOL_NAME) && |
149 (origin == ORIGIN_THIS_PORT)) { | 149 (origin == ORIGIN_THIS_PORT)) { |
150 return NULL; | 150 return nullptr; |
151 } | 151 } |
152 | 152 |
153 if (!IsCompatibleAddress(address.address())) { | 153 if (!IsCompatibleAddress(address.address())) { |
154 return NULL; | 154 return nullptr; |
155 } | 155 } |
156 | 156 |
157 TCPConnection* conn = NULL; | 157 TCPConnection* conn = nullptr; |
158 if (rtc::AsyncPacketSocket* socket = | 158 if (rtc::AsyncPacketSocket* socket = |
159 GetIncoming(address.address(), true)) { | 159 GetIncoming(address.address(), true)) { |
160 socket->SignalReadPacket.disconnect(this); | 160 socket->SignalReadPacket.disconnect(this); |
161 conn = new TCPConnection(this, address, socket); | 161 conn = new TCPConnection(this, address, socket); |
162 } else { | 162 } else { |
163 conn = new TCPConnection(this, address); | 163 conn = new TCPConnection(this, address); |
164 } | 164 } |
165 AddOrReplaceConnection(conn); | 165 AddOrReplaceConnection(conn); |
166 return conn; | 166 return conn; |
167 } | 167 } |
(...skipping 21 matching lines...) Expand all Loading... |
189 rtc::SocketAddress(ip(), 0), rtc::SocketAddress(), | 189 rtc::SocketAddress(ip(), 0), rtc::SocketAddress(), |
190 TCP_PROTOCOL_NAME, "", TCPTYPE_ACTIVE_STR, LOCAL_PORT_TYPE, | 190 TCP_PROTOCOL_NAME, "", TCPTYPE_ACTIVE_STR, LOCAL_PORT_TYPE, |
191 ICE_TYPE_PREFERENCE_HOST_TCP, 0, true); | 191 ICE_TYPE_PREFERENCE_HOST_TCP, 0, true); |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 int TCPPort::SendTo(const void* data, size_t size, | 195 int TCPPort::SendTo(const void* data, size_t size, |
196 const rtc::SocketAddress& addr, | 196 const rtc::SocketAddress& addr, |
197 const rtc::PacketOptions& options, | 197 const rtc::PacketOptions& options, |
198 bool payload) { | 198 bool payload) { |
199 rtc::AsyncPacketSocket * socket = NULL; | 199 rtc::AsyncPacketSocket* socket = nullptr; |
200 TCPConnection* conn = static_cast<TCPConnection*>(GetConnection(addr)); | 200 TCPConnection* conn = static_cast<TCPConnection*>(GetConnection(addr)); |
201 | 201 |
202 // For Connection, this is the code path used by Ping() to establish | 202 // For Connection, this is the code path used by Ping() to establish |
203 // WRITABLE. It has to send through the socket directly as TCPConnection::Send | 203 // WRITABLE. It has to send through the socket directly as TCPConnection::Send |
204 // checks writability. | 204 // checks writability. |
205 if (conn) { | 205 if (conn) { |
206 if (!conn->connected()) { | 206 if (!conn->connected()) { |
207 conn->MaybeReconnect(); | 207 conn->MaybeReconnect(); |
208 return SOCKET_ERROR; | 208 return SOCKET_ERROR; |
209 } | 209 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 incoming.socket->SignalReadyToSend.connect(this, &TCPPort::OnReadyToSend); | 260 incoming.socket->SignalReadyToSend.connect(this, &TCPPort::OnReadyToSend); |
261 incoming.socket->SignalSentPacket.connect(this, &TCPPort::OnSentPacket); | 261 incoming.socket->SignalSentPacket.connect(this, &TCPPort::OnSentPacket); |
262 | 262 |
263 LOG_J(LS_VERBOSE, this) << "Accepted connection from " | 263 LOG_J(LS_VERBOSE, this) << "Accepted connection from " |
264 << incoming.addr.ToSensitiveString(); | 264 << incoming.addr.ToSensitiveString(); |
265 incoming_.push_back(incoming); | 265 incoming_.push_back(incoming); |
266 } | 266 } |
267 | 267 |
268 rtc::AsyncPacketSocket* TCPPort::GetIncoming( | 268 rtc::AsyncPacketSocket* TCPPort::GetIncoming( |
269 const rtc::SocketAddress& addr, bool remove) { | 269 const rtc::SocketAddress& addr, bool remove) { |
270 rtc::AsyncPacketSocket* socket = NULL; | 270 rtc::AsyncPacketSocket* socket = nullptr; |
271 for (std::list<Incoming>::iterator it = incoming_.begin(); | 271 for (std::list<Incoming>::iterator it = incoming_.begin(); |
272 it != incoming_.end(); ++it) { | 272 it != incoming_.end(); ++it) { |
273 if (it->addr == addr) { | 273 if (it->addr == addr) { |
274 socket = it->socket; | 274 socket = it->socket; |
275 if (remove) | 275 if (remove) |
276 incoming_.erase(it); | 276 incoming_.erase(it); |
277 break; | 277 break; |
278 } | 278 } |
279 } | 279 } |
280 return socket; | 280 return socket; |
(...skipping 21 matching lines...) Expand all Loading... |
302 TCPTYPE_PASSIVE_STR, LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST_TCP, | 302 TCPTYPE_PASSIVE_STR, LOCAL_PORT_TYPE, ICE_TYPE_PREFERENCE_HOST_TCP, |
303 0, true); | 303 0, true); |
304 } | 304 } |
305 | 305 |
306 TCPConnection::TCPConnection(TCPPort* port, | 306 TCPConnection::TCPConnection(TCPPort* port, |
307 const Candidate& candidate, | 307 const Candidate& candidate, |
308 rtc::AsyncPacketSocket* socket) | 308 rtc::AsyncPacketSocket* socket) |
309 : Connection(port, 0, candidate), | 309 : Connection(port, 0, candidate), |
310 socket_(socket), | 310 socket_(socket), |
311 error_(0), | 311 error_(0), |
312 outgoing_(socket == NULL), | 312 outgoing_(socket == nullptr), |
313 connection_pending_(false), | 313 connection_pending_(false), |
314 pretending_to_be_writable_(false), | 314 pretending_to_be_writable_(false), |
315 reconnection_timeout_(cricket::CONNECTION_WRITE_CONNECT_TIMEOUT) { | 315 reconnection_timeout_(cricket::CONNECTION_WRITE_CONNECT_TIMEOUT) { |
316 if (outgoing_) { | 316 if (outgoing_) { |
317 CreateOutgoingTcpSocket(); | 317 CreateOutgoingTcpSocket(); |
318 } else { | 318 } else { |
319 // Incoming connections should match the network address. | 319 // Incoming connections should match the network address. |
320 LOG_J(LS_VERBOSE, this) | 320 LOG_J(LS_VERBOSE, this) |
321 << "socket ipaddr: " << socket_->GetLocalAddress().ToString() | 321 << "socket ipaddr: " << socket_->GetLocalAddress().ToString() |
322 << ",port() ip:" << port->ip().ToString(); | 322 << ",port() ip:" << port->ip().ToString(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { | 512 void TCPConnection::ConnectSocketSignals(rtc::AsyncPacketSocket* socket) { |
513 if (outgoing_) { | 513 if (outgoing_) { |
514 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); | 514 socket->SignalConnect.connect(this, &TCPConnection::OnConnect); |
515 } | 515 } |
516 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); | 516 socket->SignalReadPacket.connect(this, &TCPConnection::OnReadPacket); |
517 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); | 517 socket->SignalReadyToSend.connect(this, &TCPConnection::OnReadyToSend); |
518 socket->SignalClose.connect(this, &TCPConnection::OnClose); | 518 socket->SignalClose.connect(this, &TCPConnection::OnClose); |
519 } | 519 } |
520 | 520 |
521 } // namespace cricket | 521 } // namespace cricket |
OLD | NEW |