blob: a534eeaf6479d69f1d17c2d382d994f6379fed61 [file] [log] [blame]
Niels Möller44153152018-12-17 14:04:05 +01001/*
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
Steve Anton10542f22019-01-11 09:11:00 -080014#include "rtc_base/socket_adapters.h"
Niels Möller44153152018-12-17 14:04:05 +010015
16namespace rtc {
17
18// Interface for implementing proxy server sockets.
19class AsyncProxyServerSocket : public BufferedReadAdapter {
20 public:
21 AsyncProxyServerSocket(AsyncSocket* 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".
30class AsyncSSLServerSocket : public BufferedReadAdapter {
31 public:
32 explicit AsyncSSLServerSocket(AsyncSocket* socket);
33
34 protected:
35 void ProcessInput(char* data, size_t* len) override;
36 RTC_DISALLOW_COPY_AND_ASSIGN(AsyncSSLServerSocket);
37};
38
39// Implements a proxy server socket for the SOCKS protocol.
40class AsyncSocksProxyServerSocket : public AsyncProxyServerSocket {
41 public:
42 explicit AsyncSocksProxyServerSocket(AsyncSocket* socket);
43
44 private:
45 void ProcessInput(char* data, size_t* len) override;
46 void DirectSend(const ByteBufferWriter& buf);
47
48 void HandleHello(ByteBufferReader* request);
49 void SendHelloReply(uint8_t method);
50 void HandleAuth(ByteBufferReader* request);
51 void SendAuthReply(uint8_t result);
52 void HandleConnect(ByteBufferReader* request);
53 void SendConnectResult(int result, const SocketAddress& addr) override;
54
55 void Error(int error);
56
57 static const int kBufferSize = 1024;
58 enum State {
59 SS_HELLO,
60 SS_AUTH,
61 SS_CONNECT,
62 SS_CONNECT_PENDING,
63 SS_TUNNEL,
64 SS_ERROR
65 };
66 State state_;
67 RTC_DISALLOW_COPY_AND_ASSIGN(AsyncSocksProxyServerSocket);
68};
69
70} // namespace rtc
71
72#endif // RTC_BASE_SERVER_SOCKET_ADAPTERS_H_