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> | 14 #include <list> |
| 15 #include <memory> |
15 #include "webrtc/base/asyncsocket.h" | 16 #include "webrtc/base/asyncsocket.h" |
16 #include "webrtc/base/socketadapters.h" | 17 #include "webrtc/base/socketadapters.h" |
17 #include "webrtc/base/socketaddress.h" | 18 #include "webrtc/base/socketaddress.h" |
18 #include "webrtc/base/stream.h" | 19 #include "webrtc/base/stream.h" |
19 | 20 |
20 namespace rtc { | 21 namespace rtc { |
21 | 22 |
22 class SocketFactory; | 23 class SocketFactory; |
23 | 24 |
24 // ProxyServer is a base class that allows for easy construction of proxy | 25 // ProxyServer is a base class that allows for easy construction of proxy |
(...skipping 18 matching lines...) Expand all Loading... |
43 void OnExternalConnect(AsyncSocket* socket); | 44 void OnExternalConnect(AsyncSocket* socket); |
44 void OnExternalRead(AsyncSocket* socket); | 45 void OnExternalRead(AsyncSocket* socket); |
45 void OnExternalWrite(AsyncSocket* socket); | 46 void OnExternalWrite(AsyncSocket* socket); |
46 void OnExternalClose(AsyncSocket* socket, int err); | 47 void OnExternalClose(AsyncSocket* socket, int err); |
47 | 48 |
48 static void Read(AsyncSocket* socket, FifoBuffer* buffer); | 49 static void Read(AsyncSocket* socket, FifoBuffer* buffer); |
49 static void Write(AsyncSocket* socket, FifoBuffer* buffer); | 50 static void Write(AsyncSocket* socket, FifoBuffer* buffer); |
50 void Destroy(); | 51 void Destroy(); |
51 | 52 |
52 static const int kBufferSize = 4096; | 53 static const int kBufferSize = 4096; |
53 scoped_ptr<AsyncProxyServerSocket> int_socket_; | 54 std::unique_ptr<AsyncProxyServerSocket> int_socket_; |
54 scoped_ptr<AsyncSocket> ext_socket_; | 55 std::unique_ptr<AsyncSocket> ext_socket_; |
55 bool connected_; | 56 bool connected_; |
56 FifoBuffer out_buffer_; | 57 FifoBuffer out_buffer_; |
57 FifoBuffer in_buffer_; | 58 FifoBuffer in_buffer_; |
58 RTC_DISALLOW_COPY_AND_ASSIGN(ProxyBinding); | 59 RTC_DISALLOW_COPY_AND_ASSIGN(ProxyBinding); |
59 }; | 60 }; |
60 | 61 |
61 class ProxyServer : public sigslot::has_slots<> { | 62 class ProxyServer : public sigslot::has_slots<> { |
62 public: | 63 public: |
63 ProxyServer(SocketFactory* int_factory, const SocketAddress& int_addr, | 64 ProxyServer(SocketFactory* int_factory, const SocketAddress& int_addr, |
64 SocketFactory* ext_factory, const SocketAddress& ext_ip); | 65 SocketFactory* ext_factory, const SocketAddress& ext_ip); |
65 ~ProxyServer() override; | 66 ~ProxyServer() override; |
66 | 67 |
67 // Returns the address to which the proxy server is bound | 68 // Returns the address to which the proxy server is bound |
68 SocketAddress GetServerAddress(); | 69 SocketAddress GetServerAddress(); |
69 | 70 |
70 protected: | 71 protected: |
71 void OnAcceptEvent(AsyncSocket* socket); | 72 void OnAcceptEvent(AsyncSocket* socket); |
72 virtual AsyncProxyServerSocket* WrapSocket(AsyncSocket* socket) = 0; | 73 virtual AsyncProxyServerSocket* WrapSocket(AsyncSocket* socket) = 0; |
73 void OnBindingDestroyed(ProxyBinding* binding); | 74 void OnBindingDestroyed(ProxyBinding* binding); |
74 | 75 |
75 private: | 76 private: |
76 typedef std::list<ProxyBinding*> BindingList; | 77 typedef std::list<ProxyBinding*> BindingList; |
77 SocketFactory* ext_factory_; | 78 SocketFactory* ext_factory_; |
78 SocketAddress ext_ip_; | 79 SocketAddress ext_ip_; |
79 scoped_ptr<AsyncSocket> server_socket_; | 80 std::unique_ptr<AsyncSocket> server_socket_; |
80 BindingList bindings_; | 81 BindingList bindings_; |
81 RTC_DISALLOW_COPY_AND_ASSIGN(ProxyServer); | 82 RTC_DISALLOW_COPY_AND_ASSIGN(ProxyServer); |
82 }; | 83 }; |
83 | 84 |
84 // SocksProxyServer is a simple extension of ProxyServer to implement SOCKS. | 85 // SocksProxyServer is a simple extension of ProxyServer to implement SOCKS. |
85 class SocksProxyServer : public ProxyServer { | 86 class SocksProxyServer : public ProxyServer { |
86 public: | 87 public: |
87 SocksProxyServer(SocketFactory* int_factory, const SocketAddress& int_addr, | 88 SocksProxyServer(SocketFactory* int_factory, const SocketAddress& int_addr, |
88 SocketFactory* ext_factory, const SocketAddress& ext_ip) | 89 SocketFactory* ext_factory, const SocketAddress& ext_ip) |
89 : ProxyServer(int_factory, int_addr, ext_factory, ext_ip) { | 90 : ProxyServer(int_factory, int_addr, ext_factory, ext_ip) { |
90 } | 91 } |
91 protected: | 92 protected: |
92 AsyncProxyServerSocket* WrapSocket(AsyncSocket* socket) override; | 93 AsyncProxyServerSocket* WrapSocket(AsyncSocket* socket) override; |
93 RTC_DISALLOW_COPY_AND_ASSIGN(SocksProxyServer); | 94 RTC_DISALLOW_COPY_AND_ASSIGN(SocksProxyServer); |
94 }; | 95 }; |
95 | 96 |
96 } // namespace rtc | 97 } // namespace rtc |
97 | 98 |
98 #endif // WEBRTC_BASE_PROXYSERVER_H_ | 99 #endif // WEBRTC_BASE_PROXYSERVER_H_ |
OLD | NEW |