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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 return NULL; | 80 return NULL; |
81 } | 81 } |
82 | 82 |
83 if (BindSocket(socket, local_address, min_port, max_port) < 0) { | 83 if (BindSocket(socket, local_address, min_port, max_port) < 0) { |
84 LOG(LS_ERROR) << "TCP bind failed with error " | 84 LOG(LS_ERROR) << "TCP bind failed with error " |
85 << socket->GetError(); | 85 << socket->GetError(); |
86 delete socket; | 86 delete socket; |
87 return NULL; | 87 return NULL; |
88 } | 88 } |
89 | 89 |
90 // If using fake TLS, wrap the TCP socket in a pseudo-SSL socket. | 90 // If using SSLTCP, wrap the TCP socket in a pseudo-SSL socket. |
91 if (opts & PacketSocketFactory::OPT_TLS_FAKE) { | 91 if (opts & PacketSocketFactory::OPT_SSLTCP) { |
92 ASSERT(!(opts & PacketSocketFactory::OPT_TLS)); | 92 ASSERT(!(opts & PacketSocketFactory::OPT_TLS)); |
93 socket = new AsyncSSLSocket(socket); | 93 socket = new AsyncSSLSocket(socket); |
94 } | 94 } |
95 | 95 |
96 // Set TCP_NODELAY (via OPT_NODELAY) for improved performance. | 96 // Set TCP_NODELAY (via OPT_NODELAY) for improved performance. |
97 // See http://go/gtalktcpnodelayexperiment | 97 // See http://go/gtalktcpnodelayexperiment |
98 socket->SetOption(Socket::OPT_NODELAY, 1); | 98 socket->SetOption(Socket::OPT_NODELAY, 1); |
99 | 99 |
100 if (opts & PacketSocketFactory::OPT_STUN) | 100 if (opts & PacketSocketFactory::OPT_STUN) |
101 return new cricket::AsyncStunTCPSocket(socket, true); | 101 return new cricket::AsyncStunTCPSocket(socket, true); |
(...skipping 20 matching lines...) Expand all Loading... |
122 // If using a proxy, wrap the socket in a proxy socket. | 122 // If using a proxy, wrap the socket in a proxy socket. |
123 if (proxy_info.type == PROXY_SOCKS5) { | 123 if (proxy_info.type == PROXY_SOCKS5) { |
124 socket = new AsyncSocksProxySocket( | 124 socket = new AsyncSocksProxySocket( |
125 socket, proxy_info.address, proxy_info.username, proxy_info.password); | 125 socket, proxy_info.address, proxy_info.username, proxy_info.password); |
126 } else if (proxy_info.type == PROXY_HTTPS) { | 126 } else if (proxy_info.type == PROXY_HTTPS) { |
127 socket = | 127 socket = |
128 new AsyncHttpsProxySocket(socket, user_agent, proxy_info.address, | 128 new AsyncHttpsProxySocket(socket, user_agent, proxy_info.address, |
129 proxy_info.username, proxy_info.password); | 129 proxy_info.username, proxy_info.password); |
130 } | 130 } |
131 | 131 |
132 // Assert that at most one TLS option is used. | 132 // If using TLS, wrap the socket in an SSL adapter. |
133 int tlsOpts = | 133 if (opts & PacketSocketFactory::OPT_TLS) { |
134 opts & (PacketSocketFactory::OPT_TLS | PacketSocketFactory::OPT_TLS_FAKE | | 134 ASSERT(!(opts & PacketSocketFactory::OPT_SSLTCP)); |
135 PacketSocketFactory::OPT_TLS_INSECURE); | |
136 ASSERT((tlsOpts & (tlsOpts - 1)) == 0); | |
137 | 135 |
138 if ((tlsOpts & PacketSocketFactory::OPT_TLS) || | |
139 (tlsOpts & PacketSocketFactory::OPT_TLS_INSECURE)) { | |
140 // Using TLS, wrap the socket in an SSL adapter. | |
141 SSLAdapter* ssl_adapter = SSLAdapter::Create(socket); | 136 SSLAdapter* ssl_adapter = SSLAdapter::Create(socket); |
142 if (!ssl_adapter) { | 137 if (!ssl_adapter) { |
143 return NULL; | 138 return NULL; |
144 } | 139 } |
145 | 140 |
146 if (tlsOpts & PacketSocketFactory::OPT_TLS_INSECURE) { | |
147 ssl_adapter->set_ignore_bad_cert(true); | |
148 } | |
149 | |
150 socket = ssl_adapter; | 141 socket = ssl_adapter; |
151 | 142 |
152 if (ssl_adapter->StartSSL(remote_address.hostname().c_str(), false) != 0) { | 143 if (ssl_adapter->StartSSL(remote_address.hostname().c_str(), false) != 0) { |
153 delete ssl_adapter; | 144 delete ssl_adapter; |
154 return NULL; | 145 return NULL; |
155 } | 146 } |
156 | 147 |
157 } else if (tlsOpts & PacketSocketFactory::OPT_TLS_FAKE) { | 148 // If using SSLTCP, wrap the TCP socket in a pseudo-SSL socket. |
158 // Using fake TLS, wrap the TCP socket in a pseudo-SSL socket. | 149 } else if (opts & PacketSocketFactory::OPT_SSLTCP) { |
| 150 ASSERT(!(opts & PacketSocketFactory::OPT_TLS)); |
159 socket = new AsyncSSLSocket(socket); | 151 socket = new AsyncSSLSocket(socket); |
160 } | 152 } |
161 | 153 |
162 if (socket->Connect(remote_address) < 0) { | 154 if (socket->Connect(remote_address) < 0) { |
163 LOG(LS_ERROR) << "TCP connect failed with error " | 155 LOG(LS_ERROR) << "TCP connect failed with error " |
164 << socket->GetError(); | 156 << socket->GetError(); |
165 delete socket; | 157 delete socket; |
166 return NULL; | 158 return NULL; |
167 } | 159 } |
168 | 160 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 SocketFactory* BasicPacketSocketFactory::socket_factory() { | 197 SocketFactory* BasicPacketSocketFactory::socket_factory() { |
206 if (thread_) { | 198 if (thread_) { |
207 ASSERT(thread_ == Thread::Current()); | 199 ASSERT(thread_ == Thread::Current()); |
208 return thread_->socketserver(); | 200 return thread_->socketserver(); |
209 } else { | 201 } else { |
210 return socket_factory_; | 202 return socket_factory_; |
211 } | 203 } |
212 } | 204 } |
213 | 205 |
214 } // namespace rtc | 206 } // namespace rtc |
OLD | NEW |