Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

udp_listener: refactor ActiveUdpListener creation #7884

Merged
merged 28 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/envoy/network/connection_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ class ActiveUdpListenerFactory {
* Creates an ActiveUdpListener object and a corresponding UdpListener
* according to given config.
* @param parent is the owner of the created ActiveListener objects.
* @param dispatcher is used to create actual UDP listener.
* @param logger might not need to be passed in.
* TODO(danzh): investigate if possible to use statically defined logger in ActiveUdpListener
* implementation instead.
* @param config provides information needed to create ActiveUdpListener and
* UdpListener objects.
* @return the ActiveUdpListener created.
Expand Down
7 changes: 7 additions & 0 deletions source/server/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ envoy_cc_library(
":filter_chain_manager_lib",
":lds_api_lib",
":transport_socket_config_lib",
":well_known_names_lib",
"//include/envoy/server:active_udp_listener_config_interface",
"//include/envoy/server:filter_config_interface",
"//include/envoy/server:listener_manager_interface",
Expand Down Expand Up @@ -443,12 +444,18 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "well_known_names_lib",
hdrs = ["well_known_names.h"],
)

envoy_cc_library(
name = "active_raw_udp_listener_config",
srcs = ["active_raw_udp_listener_config.cc"],
hdrs = ["active_raw_udp_listener_config.h"],
deps = [
":connection_handler_lib",
":well_known_names_lib",
"//include/envoy/registry",
"//include/envoy/server:active_udp_listener_config_interface",
],
Expand Down
3 changes: 2 additions & 1 deletion source/server/active_raw_udp_listener_config.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "server/active_raw_udp_listener_config.h"

#include "server/connection_handler_impl.h"
#include "server/well_known_names.h"

namespace Envoy {
namespace Server {
Expand All @@ -17,7 +18,7 @@ ActiveRawUdpListenerConfigFactory::createActiveUdpListenerFactory(
return std::make_unique<Server::ActiveRawUdpListenerFactory>();
}

std::string ActiveRawUdpListenerConfigFactory::name() { return "raw_udp_listener"; }
std::string ActiveRawUdpListenerConfigFactory::name() { return UdpListenerNames::get().RawUdp; }

REGISTER_FACTORY(ActiveRawUdpListenerConfigFactory, Server::ActiveUdpListenerConfigFactory);

Expand Down
3 changes: 2 additions & 1 deletion source/server/listener_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "server/drain_manager_impl.h"
#include "server/filter_chain_manager_impl.h"
#include "server/transport_socket_config_impl.h"
#include "server/well_known_names.h"

#include "extensions/filters/listener/well_known_names.h"
#include "extensions/transport_sockets/well_known_names.h"
Expand Down Expand Up @@ -230,7 +231,7 @@ ListenerImpl::ListenerImpl(const envoy::api::v2::Listener& config, const std::st
std::string listener_name =
config.has_udp_listener_config() ? config.udp_listener_config().udp_listener_name() : "";
if (listener_name.empty()) {
listener_name = "raw_udp_listener";
listener_name = UdpListenerNames::get().RawUdp;
}
udp_listener_factory_ =
Config::Utility::getAndCheckFactory<ActiveUdpListenerConfigFactory>(listener_name)
Expand Down
22 changes: 22 additions & 0 deletions source/server/well_known_names.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <string>

#include "common/singleton/const_singleton.h"

namespace Envoy {
namespace Server {

/**
* Well-known active UDP listener names.
*/
class UdpListenerNameValues {
public:
const std::string RawUdp = "raw_udp_listener";
const std::string Quic = "quic_listener";
mattklein123 marked this conversation as resolved.
Show resolved Hide resolved
};

using UdpListenerNames = ConstSingleton<UdpListenerNameValues>;

} // namespace Server
} // namespace Envoy