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> 9 #include <vector> 10 11 #include "platform/base/error.h" 12 #include "platform/base/ip_address.h" 13 14 namespace openscreen { 15 16 class TlsConnection { 17 public: 18 // Client callbacks are run via the TaskRunner used by TlsConnectionFactory. 19 class Client { 20 public: 21 // Called when |connection| experiences an error, such as a read error. 22 virtual void OnError(TlsConnection* connection, Error error) = 0; 23 24 // Called when a |block| arrives on |connection|. 25 virtual void OnRead(TlsConnection* connection, 26 std::vector<uint8_t> block) = 0; 27 28 protected: 29 virtual ~Client() = default; 30 }; 31 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 40 // Sends a message. Returns true iff the message will be sent. 41 [[nodiscard]] virtual bool Send(const void* data, size_t len) = 0; 42 43 // Get the local address. 44 virtual IPEndpoint GetLocalEndpoint() const = 0; 45 46 // Get the connected remote address. 47 virtual IPEndpoint GetRemoteEndpoint() const = 0; 48 49 protected: 50 TlsConnection(); 51 }; 52 53 } // namespace openscreen 54 55 #endif // PLATFORM_API_TLS_CONNECTION_H_ 56