• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef RTC_BASE_SERVER_SOCKET_ADAPTERS_H_
12 #define RTC_BASE_SERVER_SOCKET_ADAPTERS_H_
13 
14 #include "rtc_base/socket_adapters.h"
15 
16 namespace rtc {
17 
18 // Interface for implementing proxy server sockets.
19 class AsyncProxyServerSocket : public BufferedReadAdapter {
20  public:
21   AsyncProxyServerSocket(Socket* socket, size_t buffer_size);
22   ~AsyncProxyServerSocket() override;
23   sigslot::signal2<AsyncProxyServerSocket*, const SocketAddress&>
24       SignalConnectRequest;
25   virtual void SendConnectResult(int err, const SocketAddress& addr) = 0;
26 };
27 
28 // Implements a socket adapter that performs the server side of a
29 // fake SSL handshake. Used when implementing a relay server that does "ssltcp".
30 class AsyncSSLServerSocket : public BufferedReadAdapter {
31  public:
32   explicit AsyncSSLServerSocket(Socket* socket);
33 
34   AsyncSSLServerSocket(const AsyncSSLServerSocket&) = delete;
35   AsyncSSLServerSocket& operator=(const AsyncSSLServerSocket&) = delete;
36 
37  protected:
38   void ProcessInput(char* data, size_t* len) override;
39 };
40 
41 // Implements a proxy server socket for the SOCKS protocol.
42 class AsyncSocksProxyServerSocket : public AsyncProxyServerSocket {
43  public:
44   explicit AsyncSocksProxyServerSocket(Socket* socket);
45 
46   AsyncSocksProxyServerSocket(const AsyncSocksProxyServerSocket&) = delete;
47   AsyncSocksProxyServerSocket& operator=(const AsyncSocksProxyServerSocket&) =
48       delete;
49 
50  private:
51   void ProcessInput(char* data, size_t* len) override;
52   void DirectSend(const ByteBufferWriter& buf);
53 
54   void HandleHello(ByteBufferReader* request);
55   void SendHelloReply(uint8_t method);
56   void HandleAuth(ByteBufferReader* request);
57   void SendAuthReply(uint8_t result);
58   void HandleConnect(ByteBufferReader* request);
59   void SendConnectResult(int result, const SocketAddress& addr) override;
60 
61   void Error(int error);
62 
63   static const int kBufferSize = 1024;
64   enum State {
65     SS_HELLO,
66     SS_AUTH,
67     SS_CONNECT,
68     SS_CONNECT_PENDING,
69     SS_TUNNEL,
70     SS_ERROR
71   };
72   State state_;
73 };
74 
75 }  // namespace rtc
76 
77 #endif  // RTC_BASE_SERVER_SOCKET_ADAPTERS_H_
78