server_socket_adapters.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef RTC_BASE_SERVER_SOCKET_ADAPTERS_H_
  11. #define RTC_BASE_SERVER_SOCKET_ADAPTERS_H_
  12. #include "rtc_base/socket_adapters.h"
  13. namespace rtc {
  14. // Interface for implementing proxy server sockets.
  15. class AsyncProxyServerSocket : public BufferedReadAdapter {
  16. public:
  17. AsyncProxyServerSocket(AsyncSocket* socket, size_t buffer_size);
  18. ~AsyncProxyServerSocket() override;
  19. sigslot::signal2<AsyncProxyServerSocket*, const SocketAddress&>
  20. SignalConnectRequest;
  21. virtual void SendConnectResult(int err, const SocketAddress& addr) = 0;
  22. };
  23. // Implements a socket adapter that performs the server side of a
  24. // fake SSL handshake. Used when implementing a relay server that does "ssltcp".
  25. class AsyncSSLServerSocket : public BufferedReadAdapter {
  26. public:
  27. explicit AsyncSSLServerSocket(AsyncSocket* socket);
  28. protected:
  29. void ProcessInput(char* data, size_t* len) override;
  30. RTC_DISALLOW_COPY_AND_ASSIGN(AsyncSSLServerSocket);
  31. };
  32. // Implements a proxy server socket for the SOCKS protocol.
  33. class AsyncSocksProxyServerSocket : public AsyncProxyServerSocket {
  34. public:
  35. explicit AsyncSocksProxyServerSocket(AsyncSocket* socket);
  36. private:
  37. void ProcessInput(char* data, size_t* len) override;
  38. void DirectSend(const ByteBufferWriter& buf);
  39. void HandleHello(ByteBufferReader* request);
  40. void SendHelloReply(uint8_t method);
  41. void HandleAuth(ByteBufferReader* request);
  42. void SendAuthReply(uint8_t result);
  43. void HandleConnect(ByteBufferReader* request);
  44. void SendConnectResult(int result, const SocketAddress& addr) override;
  45. void Error(int error);
  46. static const int kBufferSize = 1024;
  47. enum State {
  48. SS_HELLO,
  49. SS_AUTH,
  50. SS_CONNECT,
  51. SS_CONNECT_PENDING,
  52. SS_TUNNEL,
  53. SS_ERROR
  54. };
  55. State state_;
  56. RTC_DISALLOW_COPY_AND_ASSIGN(AsyncSocksProxyServerSocket);
  57. };
  58. } // namespace rtc
  59. #endif // RTC_BASE_SERVER_SOCKET_ADAPTERS_H_