Repository: envoyproxy/envoy
File: source/common/tcp_proxy/tcp_proxy.cc (C++)

Code before:
  if (config.has_on_demand() && config.on_demand().has_odcds_config()) {
    on_demand_config_ =
        std::make_unique<OnDemandConfig>(config.on_demand(), context, *stats_scope_);
  }

  if (config.has_backoff_options()) {
    const uint64_t base_interval_ms =
        PROTOBUF_GET_MS_REQUIRED(config.backoff_options(), base_interval);
    const uint64_t max_interval_ms =
        PROTOBUF_GET_MS_OR_DEFAULT(config.backoff_options(), max_interval, base_interval_ms * 10);

    if (max_interval_ms < base_interval_ms) {
      throw EnvoyException(
          "max_backoff_interval must be greater or equal to base_backoff_interval");
    }

    backoff_strategy_ = std::make_unique<JitteredExponentialBackOffStrategy>(
        base_interval_ms, max_interval_ms, context.serverFactoryContext().api().randomGenerator());
  }

  if (!config.proxy_protocol_tlvs().empty()) {
    proxy_protocol_tlvs_ =
        parseTLVs(config.proxy_protocol_tlvs(), context, dynamic_tlv_formatters_);
  }

  downstream_tlv_merge_policy_ = config.downstream_tlv_merge_policy();
}

Config::Config(const envoy::extensions::filters::network::tcp_proxy::v3::TcpProxy& config,
               Server::Configuration::FactoryContext& context)
    : max_connect_attempts_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, max_connect_attempts, 1)),
      upstream_drain_manager_slot_(context.serverFactoryContext().threadLocal().allocateSlot()),
      shared_config_(std::make_shared<SharedConfig>(config, context)),
      random_generator_(context.serverFactoryContext().api().randomGenerator()),
      regex_engine_(context.serverFactoryContext().regexEngine()) {
  upstream_drain_manager_slot_->set([](Event::Dispatcher&) {
    ThreadLocal::ThreadLocalObjectSharedPtr drain_manager =
        std::make_shared<UpstreamDrainManager>();
    return drain_manager;
  });

  if (!config.cluster().empty()) {
    default_route_ = std::make_shared<const SimpleRouteImpl>(*this, config.cluster());
  }

  if (config.has_metadata_match()) {
    const auto& filter_metadata = config.metadata_match().filter_metadata();

    const auto filter_it = filter_metadata.find(Envoy::Config::MetadataFilters::get().ENVOY_LB);

    if (filter_it != filter_metadata.end()) {

Review comment (suggestion):
This should be set in the initializer list at the top of the constructor, because it has no validation or complicated conversion logic.

Code after:
  }

  if (config.has_on_demand() && config.on_demand().has_odcds_config()) {
    on_demand_config_ =
        std::make_unique<OnDemandConfig>(config.on_demand(), context, *stats_scope_);
  }

  if (config.has_backoff_options()) {
    const uint64_t base_interval_ms =
        PROTOBUF_GET_MS_REQUIRED(config.backoff_options(), base_interval);
    const uint64_t max_interval_ms =
        PROTOBUF_GET_MS_OR_DEFAULT(config.backoff_options(), max_interval, base_interval_ms * 10);

    if (max_interval_ms < base_interval_ms) {
      throw EnvoyException(
          "max_backoff_interval must be greater or equal to base_backoff_interval");
    }

    backoff_strategy_ = std::make_unique<JitteredExponentialBackOffStrategy>(
        base_interval_ms, max_interval_ms, context.serverFactoryContext().api().randomGenerator());
  }

  if (!config.proxy_protocol_tlvs().empty()) {
    proxy_protocol_tlvs_ =
        parseTLVs(config.proxy_protocol_tlvs(), context, dynamic_tlv_formatters_);
  }
}

Config::Config(const envoy::extensions::filters::network::tcp_proxy::v3::TcpProxy& config,
               Server::Configuration::FactoryContext& context)
    : max_connect_attempts_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(config, max_connect_attempts, 1)),
      upstream_drain_manager_slot_(context.serverFactoryContext().threadLocal().allocateSlot()),
      shared_config_(std::make_shared<SharedConfig>(config, context)),
      random_generator_(context.serverFactoryContext().api().randomGenerator()),
      regex_engine_(context.serverFactoryContext().regexEngine()) {
  upstream_drain_manager_slot_->set([](Event::Dispatcher&) {
    ThreadLocal::ThreadLocalObjectSharedPtr drain_manager =
        std::make_shared<UpstreamDrainManager>();
    return drain_manager;
  });

  if (!config.cluster().empty()) {
    default_route_ = std::make_shared<const SimpleRouteImpl>(*this, config.cluster());
  }

  if (config.has_metadata_match()) {
    const auto& filter_metadata = config.metadata_match().filter_metadata();

    const auto filter_it = filter_metadata.find(Envoy::Config::MetadataFilters::get().ENVOY_LB);

    if (filter_it != filter_metadata.end()) {