| 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 |
| 11 #ifndef WEBRTC_BASE_PROXYSERVER_H_ | 11 #ifndef WEBRTC_BASE_PROXYSERVER_H_ |
| 12 #define WEBRTC_BASE_PROXYSERVER_H_ | 12 #define WEBRTC_BASE_PROXYSERVER_H_ |
| 13 | 13 |
| 14 #include <list> | |
| 15 #include <memory> | |
| 16 #include "webrtc/base/asyncsocket.h" | |
| 17 #include "webrtc/base/constructormagic.h" | |
| 18 #include "webrtc/base/socketadapters.h" | |
| 19 #include "webrtc/base/socketaddress.h" | |
| 20 #include "webrtc/base/stream.h" | |
| 21 | 14 |
| 22 namespace rtc { | 15 // This header is deprecated and is just left here temporarily during |
| 23 | 16 // refactoring. See https://bugs.webrtc.org/7634 for more details. |
| 24 class SocketFactory; | 17 #include "webrtc/rtc_base/proxyserver.h" |
| 25 | |
| 26 // ProxyServer is a base class that allows for easy construction of proxy | |
| 27 // servers. With its helper class ProxyBinding, it contains all the necessary | |
| 28 // logic for receiving and bridging connections. The specific client-server | |
| 29 // proxy protocol is implemented by an instance of the AsyncProxyServerSocket | |
| 30 // class; children of ProxyServer implement WrapSocket appropriately to return | |
| 31 // the correct protocol handler. | |
| 32 | |
| 33 class ProxyBinding : public sigslot::has_slots<> { | |
| 34 public: | |
| 35 ProxyBinding(AsyncProxyServerSocket* in_socket, AsyncSocket* out_socket); | |
| 36 ~ProxyBinding() override; | |
| 37 sigslot::signal1<ProxyBinding*> SignalDestroyed; | |
| 38 | |
| 39 private: | |
| 40 void OnConnectRequest(AsyncProxyServerSocket* socket, | |
| 41 const SocketAddress& addr); | |
| 42 void OnInternalRead(AsyncSocket* socket); | |
| 43 void OnInternalWrite(AsyncSocket* socket); | |
| 44 void OnInternalClose(AsyncSocket* socket, int err); | |
| 45 void OnExternalConnect(AsyncSocket* socket); | |
| 46 void OnExternalRead(AsyncSocket* socket); | |
| 47 void OnExternalWrite(AsyncSocket* socket); | |
| 48 void OnExternalClose(AsyncSocket* socket, int err); | |
| 49 | |
| 50 static void Read(AsyncSocket* socket, FifoBuffer* buffer); | |
| 51 static void Write(AsyncSocket* socket, FifoBuffer* buffer); | |
| 52 void Destroy(); | |
| 53 | |
| 54 static const int kBufferSize = 4096; | |
| 55 std::unique_ptr<AsyncProxyServerSocket> int_socket_; | |
| 56 std::unique_ptr<AsyncSocket> ext_socket_; | |
| 57 bool connected_; | |
| 58 FifoBuffer out_buffer_; | |
| 59 FifoBuffer in_buffer_; | |
| 60 RTC_DISALLOW_COPY_AND_ASSIGN(ProxyBinding); | |
| 61 }; | |
| 62 | |
| 63 class ProxyServer : public sigslot::has_slots<> { | |
| 64 public: | |
| 65 ProxyServer(SocketFactory* int_factory, const SocketAddress& int_addr, | |
| 66 SocketFactory* ext_factory, const SocketAddress& ext_ip); | |
| 67 ~ProxyServer() override; | |
| 68 | |
| 69 // Returns the address to which the proxy server is bound | |
| 70 SocketAddress GetServerAddress(); | |
| 71 | |
| 72 protected: | |
| 73 void OnAcceptEvent(AsyncSocket* socket); | |
| 74 virtual AsyncProxyServerSocket* WrapSocket(AsyncSocket* socket) = 0; | |
| 75 void OnBindingDestroyed(ProxyBinding* binding); | |
| 76 | |
| 77 private: | |
| 78 typedef std::list<ProxyBinding*> BindingList; | |
| 79 SocketFactory* ext_factory_; | |
| 80 SocketAddress ext_ip_; | |
| 81 std::unique_ptr<AsyncSocket> server_socket_; | |
| 82 BindingList bindings_; | |
| 83 RTC_DISALLOW_COPY_AND_ASSIGN(ProxyServer); | |
| 84 }; | |
| 85 | |
| 86 // SocksProxyServer is a simple extension of ProxyServer to implement SOCKS. | |
| 87 class SocksProxyServer : public ProxyServer { | |
| 88 public: | |
| 89 SocksProxyServer(SocketFactory* int_factory, const SocketAddress& int_addr, | |
| 90 SocketFactory* ext_factory, const SocketAddress& ext_ip) | |
| 91 : ProxyServer(int_factory, int_addr, ext_factory, ext_ip) { | |
| 92 } | |
| 93 protected: | |
| 94 AsyncProxyServerSocket* WrapSocket(AsyncSocket* socket) override; | |
| 95 RTC_DISALLOW_COPY_AND_ASSIGN(SocksProxyServer); | |
| 96 }; | |
| 97 | |
| 98 } // namespace rtc | |
| 99 | 18 |
| 100 #endif // WEBRTC_BASE_PROXYSERVER_H_ | 19 #endif // WEBRTC_BASE_PROXYSERVER_H_ |
| OLD | NEW |