1 // Copyright 2018 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 OSP_IMPL_QUIC_QUIC_CONNECTION_FACTORY_H_ 6 #define OSP_IMPL_QUIC_QUIC_CONNECTION_FACTORY_H_ 7 8 #include <memory> 9 #include <vector> 10 11 #include "absl/types/optional.h" 12 #include "osp/impl/quic/quic_connection.h" 13 #include "platform/api/time.h" 14 #include "platform/base/ip_address.h" 15 16 namespace openscreen { 17 namespace osp { 18 19 // This interface provides a way to make new QUIC connections to endpoints. It 20 // also provides a way to receive incoming QUIC connections (as a server). 21 class QuicConnectionFactory : public UdpSocket::Client { 22 public: 23 class ServerDelegate { 24 public: 25 virtual ~ServerDelegate() = default; 26 27 virtual QuicConnection::Delegate* NextConnectionDelegate( 28 const IPEndpoint& source) = 0; 29 virtual void OnIncomingConnection( 30 std::unique_ptr<QuicConnection> connection) = 0; 31 }; 32 33 virtual ~QuicConnectionFactory() = default; 34 35 // Initializes a server socket listening on |port| where new connection 36 // callbacks are sent to |delegate|. 37 virtual void SetServerDelegate(ServerDelegate* delegate, 38 const std::vector<IPEndpoint>& endpoints) = 0; 39 40 virtual std::unique_ptr<QuicConnection> Connect( 41 const IPEndpoint& endpoint, 42 QuicConnection::Delegate* connection_delegate) = 0; 43 }; 44 45 } // namespace osp 46 } // namespace openscreen 47 48 #endif // OSP_IMPL_QUIC_QUIC_CONNECTION_FACTORY_H_ 49