/** * Copyright Quadrivium LLC * All Rights Reserved * SPDX-License-Identifier: Apache-2.0 */ #pragma once #include // implementations #include #include #include #include #include #include #include #include #include namespace libp2p::injector { template std::shared_ptr get_kademlia( const Injector &injector) { static auto initialized = boost::optional>( boost::none); if (initialized) { return initialized.value(); } [[maybe_unused]] auto config = injector.template create(); [[maybe_unused]] auto host = injector.template create>(); [[maybe_unused]] auto storage = injector .template create>(); [[maybe_unused]] auto table = injector.template create< std::shared_ptr>(); [[maybe_unused]] auto content_routing_table = injector.template create< std::shared_ptr>(); [[maybe_unused]] auto validator = injector .template create>(); [[maybe_unused]] auto scheduler = injector.template create>(); [[maybe_unused]] auto random_generator = injector.template create< std::shared_ptr>(); [[maybe_unused]] auto bus = injector.template create>(); initialized = std::make_shared( config, std::move(host), std::move(storage), std::move(content_routing_table), std::move(table), std::move(validator), std::move(scheduler), std::move(bus), std::move(random_generator)); return initialized.value(); } template < typename T, typename C = std::decay_t, typename = std::enable_if>> inline auto useKademliaConfig(T &&c) { return boost::di::bind().to( [c = std::forward(c)](const auto &injector) mutable -> const C & { static C instance = std::move(c); return instance; })[boost::di::override]; } // clang-format off template auto makeKademliaInjector(Ts &&... args) { namespace di = boost::di; return di::make_injector( // clang-format off di::bind.to(), di::bind.to(), di::bind.to(), di::bind.to(), di::bind.to(), di::bind.to(), di::bind.to(), di::bind.to(), // user-defined overrides... std::forward(args)... // clang-format on ); } } // namespace libp2p::injector