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 #include "cast/receiver/public/receiver_socket_factory.h"
6
7 #include "util/osp_logging.h"
8
9 namespace openscreen {
10 namespace cast {
11
12 ReceiverSocketFactory::Client::~Client() = default;
13
ReceiverSocketFactory(Client * client,CastSocket::Client * socket_client)14 ReceiverSocketFactory::ReceiverSocketFactory(Client* client,
15 CastSocket::Client* socket_client)
16 : client_(client), socket_client_(socket_client) {
17 OSP_DCHECK(client);
18 OSP_DCHECK(socket_client);
19 }
20
21 ReceiverSocketFactory::~ReceiverSocketFactory() = default;
22
OnAccepted(TlsConnectionFactory * factory,std::vector<uint8_t> der_x509_peer_cert,std::unique_ptr<TlsConnection> connection)23 void ReceiverSocketFactory::OnAccepted(
24 TlsConnectionFactory* factory,
25 std::vector<uint8_t> der_x509_peer_cert,
26 std::unique_ptr<TlsConnection> connection) {
27 IPEndpoint endpoint = connection->GetRemoteEndpoint();
28 auto socket =
29 std::make_unique<CastSocket>(std::move(connection), socket_client_);
30 client_->OnConnected(this, endpoint, std::move(socket));
31 }
32
OnConnected(TlsConnectionFactory * factory,std::vector<uint8_t> der_x509_peer_cert,std::unique_ptr<TlsConnection> connection)33 void ReceiverSocketFactory::OnConnected(
34 TlsConnectionFactory* factory,
35 std::vector<uint8_t> der_x509_peer_cert,
36 std::unique_ptr<TlsConnection> connection) {
37 OSP_LOG_FATAL << "This factory is accept-only";
38 }
39
OnConnectionFailed(TlsConnectionFactory * factory,const IPEndpoint & remote_address)40 void ReceiverSocketFactory::OnConnectionFailed(
41 TlsConnectionFactory* factory,
42 const IPEndpoint& remote_address) {
43 client_->OnError(this, Error(Error::Code::kConnectionFailed,
44 "Accepting connection failed."));
45 }
46
OnError(TlsConnectionFactory * factory,Error error)47 void ReceiverSocketFactory::OnError(TlsConnectionFactory* factory,
48 Error error) {
49 client_->OnError(this, error);
50 }
51
52 } // namespace cast
53 } // namespace openscreen
54