| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 socket->SetOption(Socket::OPT_NODELAY, 1); | 99 socket->SetOption(Socket::OPT_NODELAY, 1); |
| 100 | 100 |
| 101 if (opts & PacketSocketFactory::OPT_STUN) | 101 if (opts & PacketSocketFactory::OPT_STUN) |
| 102 return new cricket::AsyncStunTCPSocket(socket, true); | 102 return new cricket::AsyncStunTCPSocket(socket, true); |
| 103 | 103 |
| 104 return new AsyncTCPSocket(socket, true); | 104 return new AsyncTCPSocket(socket, true); |
| 105 } | 105 } |
| 106 | 106 |
| 107 AsyncPacketSocket* BasicPacketSocketFactory::CreateClientTcpSocket( | 107 AsyncPacketSocket* BasicPacketSocketFactory::CreateClientTcpSocket( |
| 108 const SocketAddress& local_address, const SocketAddress& remote_address, | 108 const SocketAddress& local_address, const SocketAddress& remote_address, |
| 109 const ProxyInfo& proxy_info, const std::string& user_agent, int opts) { | 109 const ProxyInfo& proxy_info, const std::string& user_agent, |
| 110 const PacketSocketTcpOptions& tcp_options) { |
| 110 AsyncSocket* socket = | 111 AsyncSocket* socket = |
| 111 socket_factory()->CreateAsyncSocket(local_address.family(), SOCK_STREAM); | 112 socket_factory()->CreateAsyncSocket(local_address.family(), SOCK_STREAM); |
| 112 if (!socket) { | 113 if (!socket) { |
| 113 return NULL; | 114 return NULL; |
| 114 } | 115 } |
| 115 | 116 |
| 116 if (BindSocket(socket, local_address, 0, 0) < 0) { | 117 if (BindSocket(socket, local_address, 0, 0) < 0) { |
| 117 // Allow BindSocket to fail if we're binding to the ANY address, since this | 118 // Allow BindSocket to fail if we're binding to the ANY address, since this |
| 118 // is mostly redundant in the first place. The socket will be bound when we | 119 // is mostly redundant in the first place. The socket will be bound when we |
| 119 // call Connect() instead. | 120 // call Connect() instead. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 132 socket = new AsyncSocksProxySocket( | 133 socket = new AsyncSocksProxySocket( |
| 133 socket, proxy_info.address, proxy_info.username, proxy_info.password); | 134 socket, proxy_info.address, proxy_info.username, proxy_info.password); |
| 134 } else if (proxy_info.type == PROXY_HTTPS) { | 135 } else if (proxy_info.type == PROXY_HTTPS) { |
| 135 socket = | 136 socket = |
| 136 new AsyncHttpsProxySocket(socket, user_agent, proxy_info.address, | 137 new AsyncHttpsProxySocket(socket, user_agent, proxy_info.address, |
| 137 proxy_info.username, proxy_info.password); | 138 proxy_info.username, proxy_info.password); |
| 138 } | 139 } |
| 139 | 140 |
| 140 // Assert that at most one TLS option is used. | 141 // Assert that at most one TLS option is used. |
| 141 int tlsOpts = | 142 int tlsOpts = |
| 142 opts & (PacketSocketFactory::OPT_TLS | PacketSocketFactory::OPT_TLS_FAKE | | 143 tcp_options.opts & (PacketSocketFactory::OPT_TLS | |
| 143 PacketSocketFactory::OPT_TLS_INSECURE); | 144 PacketSocketFactory::OPT_TLS_FAKE | |
| 145 PacketSocketFactory::OPT_TLS_INSECURE); |
| 144 RTC_DCHECK((tlsOpts & (tlsOpts - 1)) == 0); | 146 RTC_DCHECK((tlsOpts & (tlsOpts - 1)) == 0); |
| 145 | 147 |
| 146 if ((tlsOpts & PacketSocketFactory::OPT_TLS) || | 148 if ((tlsOpts & PacketSocketFactory::OPT_TLS) || |
| 147 (tlsOpts & PacketSocketFactory::OPT_TLS_INSECURE)) { | 149 (tlsOpts & PacketSocketFactory::OPT_TLS_INSECURE)) { |
| 148 // Using TLS, wrap the socket in an SSL adapter. | 150 // Using TLS, wrap the socket in an SSL adapter. |
| 149 SSLAdapter* ssl_adapter = SSLAdapter::Create(socket); | 151 SSLAdapter* ssl_adapter = SSLAdapter::Create(socket); |
| 150 if (!ssl_adapter) { | 152 if (!ssl_adapter) { |
| 151 return NULL; | 153 return NULL; |
| 152 } | 154 } |
| 153 | 155 |
| 154 if (tlsOpts & PacketSocketFactory::OPT_TLS_INSECURE) { | 156 if (tlsOpts & PacketSocketFactory::OPT_TLS_INSECURE) { |
| 155 ssl_adapter->set_ignore_bad_cert(true); | 157 ssl_adapter->SetIgnoreBadCert(true); |
| 156 } | 158 } |
| 157 | 159 |
| 160 ssl_adapter->SetAlpnProtocols(tcp_options.tls_alpn_protocols); |
| 161 |
| 158 socket = ssl_adapter; | 162 socket = ssl_adapter; |
| 159 | 163 |
| 160 if (ssl_adapter->StartSSL(remote_address.hostname().c_str(), false) != 0) { | 164 if (ssl_adapter->StartSSL(remote_address.hostname().c_str(), false) != 0) { |
| 161 delete ssl_adapter; | 165 delete ssl_adapter; |
| 162 return NULL; | 166 return NULL; |
| 163 } | 167 } |
| 164 | 168 |
| 165 } else if (tlsOpts & PacketSocketFactory::OPT_TLS_FAKE) { | 169 } else if (tlsOpts & PacketSocketFactory::OPT_TLS_FAKE) { |
| 166 // Using fake TLS, wrap the TCP socket in a pseudo-SSL socket. | 170 // Using fake TLS, wrap the TCP socket in a pseudo-SSL socket. |
| 167 socket = new AsyncSSLSocket(socket); | 171 socket = new AsyncSSLSocket(socket); |
| 168 } | 172 } |
| 169 | 173 |
| 170 if (socket->Connect(remote_address) < 0) { | 174 if (socket->Connect(remote_address) < 0) { |
| 171 LOG(LS_ERROR) << "TCP connect failed with error " | 175 LOG(LS_ERROR) << "TCP connect failed with error " |
| 172 << socket->GetError(); | 176 << socket->GetError(); |
| 173 delete socket; | 177 delete socket; |
| 174 return NULL; | 178 return NULL; |
| 175 } | 179 } |
| 176 | 180 |
| 177 // Finally, wrap that socket in a TCP or STUN TCP packet socket. | 181 // Finally, wrap that socket in a TCP or STUN TCP packet socket. |
| 178 AsyncPacketSocket* tcp_socket; | 182 AsyncPacketSocket* tcp_socket; |
| 179 if (opts & PacketSocketFactory::OPT_STUN) { | 183 if (tcp_options.opts & PacketSocketFactory::OPT_STUN) { |
| 180 tcp_socket = new cricket::AsyncStunTCPSocket(socket, false); | 184 tcp_socket = new cricket::AsyncStunTCPSocket(socket, false); |
| 181 } else { | 185 } else { |
| 182 tcp_socket = new AsyncTCPSocket(socket, false); | 186 tcp_socket = new AsyncTCPSocket(socket, false); |
| 183 } | 187 } |
| 184 | 188 |
| 185 // Set TCP_NODELAY (via OPT_NODELAY) for improved performance. | 189 // Set TCP_NODELAY (via OPT_NODELAY) for improved performance. |
| 186 // See http://go/gtalktcpnodelayexperiment | 190 // See http://go/gtalktcpnodelayexperiment |
| 187 tcp_socket->SetOption(Socket::OPT_NODELAY, 1); | 191 tcp_socket->SetOption(Socket::OPT_NODELAY, 1); |
| 188 | 192 |
| 189 return tcp_socket; | 193 return tcp_socket; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 213 SocketFactory* BasicPacketSocketFactory::socket_factory() { | 217 SocketFactory* BasicPacketSocketFactory::socket_factory() { |
| 214 if (thread_) { | 218 if (thread_) { |
| 215 RTC_DCHECK(thread_ == Thread::Current()); | 219 RTC_DCHECK(thread_ == Thread::Current()); |
| 216 return thread_->socketserver(); | 220 return thread_->socketserver(); |
| 217 } else { | 221 } else { |
| 218 return socket_factory_; | 222 return socket_factory_; |
| 219 } | 223 } |
| 220 } | 224 } |
| 221 | 225 |
| 222 } // namespace rtc | 226 } // namespace rtc |
| OLD | NEW |