OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_HOST_GNUBBY_AUTH_HANDLER_H_ |
| 6 #define REMOTING_HOST_GNUBBY_AUTH_HANDLER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 14 #include "net/socket/stream_socket.h" |
| 15 #include "net/socket/tcp_server_socket.h" |
| 16 |
| 17 namespace base { |
| 18 class SingleThreadTaskRunner; |
| 19 } // namespace base |
| 20 |
| 21 namespace remoting { |
| 22 namespace protocol { |
| 23 class ClientStub; |
| 24 } // namespace protocol |
| 25 |
| 26 class GnubbyConnection; |
| 27 class GnubbyConnectionFactory; |
| 28 |
| 29 // Class responsible for proxying authentication data between a local gnubbyd |
| 30 // and the client. |
| 31 |
| 32 class GnubbyAuthHandler { |
| 33 public: |
| 34 GnubbyAuthHandler( |
| 35 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, |
| 36 GnubbyConnectionFactory* gnubby_connection_factory, |
| 37 protocol::ClientStub* client_stub); |
| 38 virtual ~GnubbyAuthHandler(); |
| 39 |
| 40 // A message was received from the client. |
| 41 virtual void DeliverClientMessage(const std::string message); |
| 42 |
| 43 // The local gnubbyd closed the connection. |
| 44 virtual void ConnectionClosed(int connection_id); |
| 45 |
| 46 // A error occurred with the connection to the local gnubbyd. |
| 47 virtual void ConnectionError(int connection_id, int result); |
| 48 |
| 49 // Send control message to client. |
| 50 virtual void DeliverHostControlMessage(const std::string control_type, |
| 51 const std::string data) const; |
| 52 |
| 53 // Send data to client. |
| 54 virtual void DeliverHostDataMessage(int connection_id, |
| 55 const std::string data) const; |
| 56 |
| 57 // Set the server socket. Takes ownership of |gnubbyd_socket|. |
| 58 void SetGnubbydSocketForTesting(net::TCPServerSocket* gnubbyd_socket); |
| 59 |
| 60 // Add a new connection for unit testing. Takes ownership of |pending_socket| |
| 61 // and returns the connection id. |
| 62 int AddGnubbyConnectionForTesting(net::StreamSocket* pending_socket); |
| 63 |
| 64 // Returns true if there is a connection with the given id. |
| 65 bool HasGnubbyConnectionForTesting(int connection_id) const; |
| 66 |
| 67 private: |
| 68 // Create socket for local gnubbyd. |
| 69 void CreateGnubbydSocket(); |
| 70 |
| 71 // Listen for gnubbyd connections. |
| 72 void AcceptGnubbydConnections(); |
| 73 |
| 74 // Called when gnubbyd makes a connection. |
| 75 void OnAccept(int result); |
| 76 |
| 77 // Task runner used by this class. |
| 78 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 79 |
| 80 // Factory to create GnubbyConnection objects. |
| 81 GnubbyConnectionFactory* gnubby_connection_factory_; |
| 82 |
| 83 // Interfaces through which communication with the client occurs. |
| 84 protocol::ClientStub* client_stub_; |
| 85 |
| 86 // Socket used to listen for local gnubbyd connections. |
| 87 scoped_ptr<net::TCPServerSocket> gnubbyd_socket_; |
| 88 |
| 89 // Socket that gnubbyd will connect to. |
| 90 scoped_ptr<net::StreamSocket> pending_socket_; |
| 91 |
| 92 // The current gnubby connection id. |
| 93 int current_connection_id_; |
| 94 |
| 95 // Active connections by connection id. |
| 96 typedef std::map<int, GnubbyConnection*> ConnectionMap; |
| 97 ConnectionMap active_connections_; |
| 98 |
| 99 // The port number that gnubbyd will establish connections with. |
| 100 int gnubbyd_listener_port_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(GnubbyAuthHandler); |
| 103 }; |
| 104 |
| 105 } // namespace remoting |
| 106 |
| 107 #endif // REMOTING_HOST_GNUBBY_AUTH_HANDLER_H_ |
OLD | NEW |