| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 // Didn't read anything; return error from socket | 91 // Didn't read anything; return error from socket |
| 92 return res; | 92 return res; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void BufferedReadAdapter::BufferInput(bool on) { | 95 void BufferedReadAdapter::BufferInput(bool on) { |
| 96 buffering_ = on; | 96 buffering_ = on; |
| 97 } | 97 } |
| 98 | 98 |
| 99 void BufferedReadAdapter::OnReadEvent(AsyncSocket * socket) { | 99 void BufferedReadAdapter::OnReadEvent(AsyncSocket * socket) { |
| 100 ASSERT(socket == socket_); | 100 RTC_DCHECK(socket == socket_); |
| 101 | 101 |
| 102 if (!buffering_) { | 102 if (!buffering_) { |
| 103 AsyncSocketAdapter::OnReadEvent(socket); | 103 AsyncSocketAdapter::OnReadEvent(socket); |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 | 106 |
| 107 if (data_len_ >= buffer_size_) { | 107 if (data_len_ >= buffer_size_) { |
| 108 LOG(INFO) << "Input buffer overflow"; | 108 LOG(INFO) << "Input buffer overflow"; |
| 109 RTC_NOTREACHED(); | 109 RTC_NOTREACHED(); |
| 110 data_len_ = 0; | 110 data_len_ = 0; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 | 178 |
| 179 int AsyncSSLSocket::Connect(const SocketAddress& addr) { | 179 int AsyncSSLSocket::Connect(const SocketAddress& addr) { |
| 180 // Begin buffering before we connect, so that there isn't a race condition | 180 // Begin buffering before we connect, so that there isn't a race condition |
| 181 // between potential senders and receiving the OnConnectEvent signal | 181 // between potential senders and receiving the OnConnectEvent signal |
| 182 BufferInput(true); | 182 BufferInput(true); |
| 183 return BufferedReadAdapter::Connect(addr); | 183 return BufferedReadAdapter::Connect(addr); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void AsyncSSLSocket::OnConnectEvent(AsyncSocket * socket) { | 186 void AsyncSSLSocket::OnConnectEvent(AsyncSocket * socket) { |
| 187 ASSERT(socket == socket_); | 187 RTC_DCHECK(socket == socket_); |
| 188 // TODO: we could buffer output too... | 188 // TODO: we could buffer output too... |
| 189 VERIFY(sizeof(kSslClientHello) == | 189 VERIFY(sizeof(kSslClientHello) == |
| 190 DirectSend(kSslClientHello, sizeof(kSslClientHello))); | 190 DirectSend(kSslClientHello, sizeof(kSslClientHello))); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void AsyncSSLSocket::ProcessInput(char* data, size_t* len) { | 193 void AsyncSSLSocket::ProcessInput(char* data, size_t* len) { |
| 194 if (*len < sizeof(kSslServerHello)) | 194 if (*len < sizeof(kSslServerHello)) |
| 195 return; | 195 return; |
| 196 | 196 |
| 197 if (memcmp(kSslServerHello, data, sizeof(kSslServerHello)) != 0) { | 197 if (memcmp(kSslServerHello, data, sizeof(kSslServerHello)) != 0) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 227 | 227 |
| 228 if (memcmp(kSslClientHello, data, sizeof(kSslClientHello)) != 0) { | 228 if (memcmp(kSslClientHello, data, sizeof(kSslClientHello)) != 0) { |
| 229 Close(); | 229 Close(); |
| 230 SignalCloseEvent(this, 0); | 230 SignalCloseEvent(this, 0); |
| 231 return; | 231 return; |
| 232 } | 232 } |
| 233 | 233 |
| 234 *len -= sizeof(kSslClientHello); | 234 *len -= sizeof(kSslClientHello); |
| 235 | 235 |
| 236 // Clients should not send more data until the handshake is completed. | 236 // Clients should not send more data until the handshake is completed. |
| 237 ASSERT(*len == 0); | 237 RTC_DCHECK(*len == 0); |
| 238 | 238 |
| 239 // Send a server hello back to the client. | 239 // Send a server hello back to the client. |
| 240 DirectSend(kSslServerHello, sizeof(kSslServerHello)); | 240 DirectSend(kSslServerHello, sizeof(kSslServerHello)); |
| 241 | 241 |
| 242 // Handshake completed for us, redirect input to our parent. | 242 // Handshake completed for us, redirect input to our parent. |
| 243 BufferInput(false); | 243 BufferInput(false); |
| 244 } | 244 } |
| 245 | 245 |
| 246 /////////////////////////////////////////////////////////////////////////////// | 246 /////////////////////////////////////////////////////////////////////////////// |
| 247 | 247 |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 } else { | 550 } else { |
| 551 return CS_CLOSED; | 551 return CS_CLOSED; |
| 552 } | 552 } |
| 553 } | 553 } |
| 554 | 554 |
| 555 void AsyncSocksProxySocket::OnConnectEvent(AsyncSocket* socket) { | 555 void AsyncSocksProxySocket::OnConnectEvent(AsyncSocket* socket) { |
| 556 SendHello(); | 556 SendHello(); |
| 557 } | 557 } |
| 558 | 558 |
| 559 void AsyncSocksProxySocket::ProcessInput(char* data, size_t* len) { | 559 void AsyncSocksProxySocket::ProcessInput(char* data, size_t* len) { |
| 560 ASSERT(state_ < SS_TUNNEL); | 560 RTC_DCHECK(state_ < SS_TUNNEL); |
| 561 | 561 |
| 562 ByteBufferReader response(data, *len); | 562 ByteBufferReader response(data, *len); |
| 563 | 563 |
| 564 if (state_ == SS_HELLO) { | 564 if (state_ == SS_HELLO) { |
| 565 uint8_t ver, method; | 565 uint8_t ver, method; |
| 566 if (!response.ReadUInt8(&ver) || | 566 if (!response.ReadUInt8(&ver) || |
| 567 !response.ReadUInt8(&method)) | 567 !response.ReadUInt8(&method)) |
| 568 return; | 568 return; |
| 569 | 569 |
| 570 if (ver != 5) { | 570 if (ver != 5) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 SignalCloseEvent(this, error); | 708 SignalCloseEvent(this, error); |
| 709 } | 709 } |
| 710 | 710 |
| 711 AsyncSocksProxyServerSocket::AsyncSocksProxyServerSocket(AsyncSocket* socket) | 711 AsyncSocksProxyServerSocket::AsyncSocksProxyServerSocket(AsyncSocket* socket) |
| 712 : AsyncProxyServerSocket(socket, kBufferSize), state_(SS_HELLO) { | 712 : AsyncProxyServerSocket(socket, kBufferSize), state_(SS_HELLO) { |
| 713 BufferInput(true); | 713 BufferInput(true); |
| 714 } | 714 } |
| 715 | 715 |
| 716 void AsyncSocksProxyServerSocket::ProcessInput(char* data, size_t* len) { | 716 void AsyncSocksProxyServerSocket::ProcessInput(char* data, size_t* len) { |
| 717 // TODO: See if the whole message has arrived | 717 // TODO: See if the whole message has arrived |
| 718 ASSERT(state_ < SS_CONNECT_PENDING); | 718 RTC_DCHECK(state_ < SS_CONNECT_PENDING); |
| 719 | 719 |
| 720 ByteBufferReader response(data, *len); | 720 ByteBufferReader response(data, *len); |
| 721 if (state_ == SS_HELLO) { | 721 if (state_ == SS_HELLO) { |
| 722 HandleHello(&response); | 722 HandleHello(&response); |
| 723 } else if (state_ == SS_AUTH) { | 723 } else if (state_ == SS_AUTH) { |
| 724 HandleAuth(&response); | 724 HandleAuth(&response); |
| 725 } else if (state_ == SS_CONNECT) { | 725 } else if (state_ == SS_CONNECT) { |
| 726 HandleConnect(&response); | 726 HandleConnect(&response); |
| 727 } | 727 } |
| 728 | 728 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 void LoggingSocketAdapter::OnCloseEvent(AsyncSocket * socket, int err) { | 904 void LoggingSocketAdapter::OnCloseEvent(AsyncSocket * socket, int err) { |
| 905 LogMultiline(level_, label_.c_str(), false, NULL, 0, hex_mode_, &lms_); | 905 LogMultiline(level_, label_.c_str(), false, NULL, 0, hex_mode_, &lms_); |
| 906 LogMultiline(level_, label_.c_str(), true, NULL, 0, hex_mode_, &lms_); | 906 LogMultiline(level_, label_.c_str(), true, NULL, 0, hex_mode_, &lms_); |
| 907 LOG_V(level_) << label_ << " Closed with error: " << err; | 907 LOG_V(level_) << label_ << " Closed with error: " << err; |
| 908 AsyncSocketAdapter::OnCloseEvent(socket, err); | 908 AsyncSocketAdapter::OnCloseEvent(socket, err); |
| 909 } | 909 } |
| 910 | 910 |
| 911 /////////////////////////////////////////////////////////////////////////////// | 911 /////////////////////////////////////////////////////////////////////////////// |
| 912 | 912 |
| 913 } // namespace rtc | 913 } // namespace rtc |
| OLD | NEW |