Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 1 | // Copyright 2019 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 PLATFORM_API_TLS_CONNECTION_H_ |
| 6 | #define PLATFORM_API_TLS_CONNECTION_H_ |
| 7 | |
| 8 | #include <cstdint> |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 11 | #include "platform/base/error.h" |
| 12 | #include "platform/base/ip_address.h" |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 13 | |
| 14 | namespace openscreen { |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 15 | |
| 16 | class TlsConnection { |
| 17 | public: |
Yuri Wiitala | fb75b09 | 2019-11-14 14:13:18 -0800 | [diff] [blame] | 18 | // Client callbacks are run via the TaskRunner used by TlsConnectionFactory. |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 19 | class Client { |
| 20 | public: |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 21 | // Called when |connection| experiences an error, such as a read error. |
Jordan Bayles | f46c0a6 | 2019-09-20 11:37:42 -0700 | [diff] [blame] | 22 | virtual void OnError(TlsConnection* connection, Error error) = 0; |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 23 | |
Jordan Bayles | f46c0a6 | 2019-09-20 11:37:42 -0700 | [diff] [blame] | 24 | // Called when a |block| arrives on |connection|. |
| 25 | virtual void OnRead(TlsConnection* connection, |
| 26 | std::vector<uint8_t> block) = 0; |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 27 | |
| 28 | protected: |
Abraham Corea Diaz | bffb5c2 | 2021-07-09 23:35:39 +0000 | [diff] [blame^] | 29 | virtual ~Client(); |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
Yuri Wiitala | fb75b09 | 2019-11-14 14:13:18 -0800 | [diff] [blame] | 32 | virtual ~TlsConnection(); |
| 33 | |
| 34 | // Sets the Client associated with this instance. This should be called as |
| 35 | // soon as the factory provides a new TlsConnection instance via |
| 36 | // TlsConnectionFactory::OnAccepted() or OnConnected(). Pass nullptr to unset |
| 37 | // the Client. |
| 38 | virtual void SetClient(Client* client) = 0; |
| 39 | |
Yuri Wiitala | 910cb7f | 2020-01-14 13:37:32 -0800 | [diff] [blame] | 40 | // Sends a message. Returns true iff the message will be sent. |
Yuri Wiitala | 3866579 | 2020-01-17 15:40:16 -0800 | [diff] [blame] | 41 | [[nodiscard]] virtual bool Send(const void* data, size_t len) = 0; |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 42 | |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 43 | // Get the connected remote address. |
Yuri Wiitala | fb75b09 | 2019-11-14 14:13:18 -0800 | [diff] [blame] | 44 | virtual IPEndpoint GetRemoteEndpoint() const = 0; |
Ryan Keane | fdebe6c | 2019-09-06 14:12:51 -0700 | [diff] [blame] | 45 | |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 46 | protected: |
Yuri Wiitala | fb75b09 | 2019-11-14 14:13:18 -0800 | [diff] [blame] | 47 | TlsConnection(); |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Jordan Bayles | 1c785bd | 2019-08-15 10:32:33 -0700 | [diff] [blame] | 50 | } // namespace openscreen |
| 51 | |
| 52 | #endif // PLATFORM_API_TLS_CONNECTION_H_ |