diff options
author | btolsch <btolsch@chromium.org> | 2020-04-22 10:27:17 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-04-22 19:03:29 +0000 |
commit | 9a95cc089fbb642906eafad7d9cb028a9a74465e (patch) | |
tree | c54463d629c2c8b29a49943b69e7582873fd914c /cast/sender/public | |
parent | 7df4fa3cdf2a80c3bc4bc44c418d1854d03eceee (diff) | |
download | openscreen-9a95cc089fbb642906eafad7d9cb028a9a74465e.tar.gz |
Move CastSocket components to public/ dirs
This change moves CastSocket and both factories to their respective
public directories to make embedder DEPS whitelisting clearer.
Bug: b/154090565
Change-Id: Ieee5ed5bf794e26683dd0ea58c97c6299c1579af
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/2161147
Reviewed-by: Ryan Keane <rwkeane@google.com>
Commit-Queue: Brandon Tolsch <btolsch@chromium.org>
Diffstat (limited to 'cast/sender/public')
-rw-r--r-- | cast/sender/public/sender_socket_factory.h | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/cast/sender/public/sender_socket_factory.h b/cast/sender/public/sender_socket_factory.h new file mode 100644 index 00000000..67d8c901 --- /dev/null +++ b/cast/sender/public/sender_socket_factory.h @@ -0,0 +1,110 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CAST_SENDER_PUBLIC_SENDER_SOCKET_FACTORY_H_ +#define CAST_SENDER_PUBLIC_SENDER_SOCKET_FACTORY_H_ + +#include <openssl/x509.h> + +#include <set> +#include <utility> +#include <vector> + +#include "cast/common/public/cast_socket.h" +#include "platform/api/task_runner.h" +#include "platform/api/tls_connection_factory.h" +#include "platform/base/ip_address.h" +#include "util/serial_delete_ptr.h" + +namespace openscreen { +namespace cast { + +class AuthContext; + +class SenderSocketFactory final : public TlsConnectionFactory::Client, + public CastSocket::Client { + public: + class Client { + public: + virtual void OnConnected(SenderSocketFactory* factory, + const IPEndpoint& endpoint, + std::unique_ptr<CastSocket> socket) = 0; + virtual void OnError(SenderSocketFactory* factory, + const IPEndpoint& endpoint, + Error error) = 0; + }; + + enum class DeviceMediaPolicy { + kNone = 0, + kAudioOnly, + kIncludesVideo, + }; + + // |client| and |task_runner| must outlive |this|. + SenderSocketFactory(Client* client, TaskRunner* task_runner); + ~SenderSocketFactory(); + + // |factory| cannot be nullptr and must outlive |this|. + void set_factory(TlsConnectionFactory* factory); + + // Begins connecting to a Cast device at |endpoint|. If a successful + // connection is made, including device authentication, the new CastSocket + // will be passed to |client_|'s OnConnected method. The new CastSocket will + // have its client set to |client|. If any part of the connection process + // fails, |client_|'s OnError method is called instead. This includes if the + // device's media policy, as determined by authentication, is audio-only and + // |media_policy| is kIncludesVideo. + void Connect(const IPEndpoint& endpoint, + DeviceMediaPolicy media_policy, + CastSocket::Client* client); + + // TlsConnectionFactory::Client overrides. + void OnAccepted(TlsConnectionFactory* factory, + std::vector<uint8_t> der_x509_peer_cert, + std::unique_ptr<TlsConnection> connection) override; + void OnConnected(TlsConnectionFactory* factory, + std::vector<uint8_t> der_x509_peer_cert, + std::unique_ptr<TlsConnection> connection) override; + void OnConnectionFailed(TlsConnectionFactory* factory, + const IPEndpoint& remote_address) override; + void OnError(TlsConnectionFactory* factory, Error error) override; + + private: + struct PendingConnection { + IPEndpoint endpoint; + DeviceMediaPolicy media_policy; + CastSocket::Client* client; + }; + + struct PendingAuth { + IPEndpoint endpoint; + DeviceMediaPolicy media_policy; + SerialDeletePtr<CastSocket> socket; + CastSocket::Client* client; + std::unique_ptr<AuthContext> auth_context; + bssl::UniquePtr<X509> peer_cert; + }; + + friend bool operator<(const std::unique_ptr<PendingAuth>& a, int b); + friend bool operator<(int a, const std::unique_ptr<PendingAuth>& b); + + std::vector<PendingConnection>::iterator FindPendingConnection( + const IPEndpoint& endpoint); + + // CastSocket::Client overrides. + void OnError(CastSocket* socket, Error error) override; + void OnMessage(CastSocket* socket, + ::cast::channel::CastMessage message) override; + + Client* const client_; + TaskRunner* const task_runner_; + TlsConnectionFactory* factory_ = nullptr; + std::vector<PendingConnection> pending_connections_; + std::vector<std::unique_ptr<PendingAuth>> pending_auth_; +}; + +} // namespace cast +} // namespace openscreen + +#endif // CAST_SENDER_PUBLIC_SENDER_SOCKET_FACTORY_H_ |