aboutsummaryrefslogtreecommitdiff
path: root/cast/receiver/channel/receiver_socket_factory.cc
blob: f4276e4d0f2f7d3aa7ebb6977c981f297b6fa0c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// 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.

#include "cast/receiver/channel/receiver_socket_factory.h"

#include "util/logging.h"

namespace openscreen {
namespace cast {

ReceiverSocketFactory::ReceiverSocketFactory(Client* client,
                                             CastSocket::Client* socket_client)
    : client_(client), socket_client_(socket_client) {
  OSP_DCHECK(client);
  OSP_DCHECK(socket_client);
}

ReceiverSocketFactory::~ReceiverSocketFactory() = default;

void ReceiverSocketFactory::OnAccepted(
    TlsConnectionFactory* factory,
    std::vector<uint8_t> der_x509_peer_cert,
    std::unique_ptr<TlsConnection> connection) {
  IPEndpoint endpoint = connection->GetRemoteEndpoint();
  auto socket = std::make_unique<CastSocket>(std::move(connection),
                                             socket_client_, GetNextSocketId());
  client_->OnConnected(this, endpoint, std::move(socket));
}

void ReceiverSocketFactory::OnConnected(
    TlsConnectionFactory* factory,
    std::vector<uint8_t> der_x509_peer_cert,
    std::unique_ptr<TlsConnection> connection) {
  OSP_NOTREACHED() << "This factory is accept-only.";
}

void ReceiverSocketFactory::OnConnectionFailed(
    TlsConnectionFactory* factory,
    const IPEndpoint& remote_address) {
  OSP_DVLOG << "Receiving connection from endpoint failed: " << remote_address;
}

void ReceiverSocketFactory::OnError(TlsConnectionFactory* factory,
                                    Error error) {
  client_->OnError(this, error);
}

}  // namespace cast
}  // namespace openscreen