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

feat(server): disable UDP service by config #1132

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 18 additions & 13 deletions src/runtime/nativerun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
*/

#include "runtime/nativerun.h"
#include "utils/flags.h"

namespace dsn {
namespace tools {

DSN_DECLARE_bool(enable_udp);

void nativerun::install(service_spec &spec)
{
if (spec.env_factory_name == "")
Expand All @@ -59,19 +62,21 @@ void nativerun::install(service_spec &spec)
cs2.message_buffer_block_size = 1024 * 64;
spec.network_default_server_cfs[cs2] = cs2;
}
{
network_client_config cs;
cs.factory_name = "dsn::tools::asio_udp_provider";
cs.message_buffer_block_size = 1024 * 64;
spec.network_default_client_cfs[RPC_CHANNEL_UDP] = cs;
}
{
network_server_config cs2;
cs2.port = 0;
cs2.channel = RPC_CHANNEL_UDP;
cs2.factory_name = "dsn::tools::asio_udp_provider";
cs2.message_buffer_block_size = 1024 * 64;
spec.network_default_server_cfs[cs2] = cs2;
if (FLAGS_enable_udp) {
{
network_client_config client_conf;
client_conf.factory_name = "dsn::tools::asio_udp_provider";
client_conf.message_buffer_block_size = 1024 * 64;
spec.network_default_client_cfs[RPC_CHANNEL_UDP] = client_conf;
}
{
network_server_config server_conf;
server_conf.port = 0;
server_conf.channel = RPC_CHANNEL_UDP;
server_conf.factory_name = "dsn::tools::asio_udp_provider";
server_conf.message_buffer_block_size = 1024 * 64;
spec.network_default_server_cfs[server_conf] = server_conf;
}
}

if (spec.logging_factory_name == "")
Expand Down
7 changes: 6 additions & 1 deletion src/runtime/providers.common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "runtime/task/simple_task_queue.h"
#include "runtime/task/hpc_task_queue.h"
#include "runtime/rpc/network.sim.h"
#include "utils/flags.h"
#include "utils/simple_logger.h"
#include "runtime/rpc/dsn_message_parser.h"
#include "runtime/rpc/thrift_message_parser.h"
Expand All @@ -47,6 +48,8 @@
namespace dsn {
namespace tools {

DSN_DEFINE_bool("network", enable_udp, true, "whether to enable udp rpc engine");

void register_std_lock_providers()
{
lock_provider::register_component<std_lock_provider>("dsn::tools::std_lock_provider");
Expand All @@ -64,8 +67,10 @@ void register_common_providers()

register_std_lock_providers();

if (FLAGS_enable_udp) {
register_component_provider<asio_udp_provider>("dsn::tools::asio_udp_provider");
}
register_component_provider<asio_network_provider>("dsn::tools::asio_network_provider");
register_component_provider<asio_udp_provider>("dsn::tools::asio_udp_provider");
register_component_provider<sim_network_provider>("dsn::tools::sim_network_provider");
register_component_provider<simple_task_queue>("dsn::tools::simple_task_queue");
register_component_provider<hpc_concurrent_task_queue>("dsn::tools::hpc_concurrent_task_queue");
Expand Down
10 changes: 10 additions & 0 deletions src/runtime/task/task_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@
#include <array>

#include "runtime/rpc/rpc_message.h"
#include "utils/flags.h"
#include "utils/fmt_logging.h"
#include "utils/command_manager.h"
#include "utils/threadpool_spec.h"
#include "utils/smart_pointers.h"

namespace dsn {
namespace tools {
DSN_DECLARE_bool(enable_udp);
}

constexpr int TASK_SPEC_STORE_CAPACITY = 512;

Expand Down Expand Up @@ -224,6 +228,12 @@ bool task_spec::init()
return false;
}
}

if (spec->rpc_call_channel == RPC_CHANNEL_UDP && !dsn::tools::FLAGS_enable_udp) {
LOG_ERROR("task rpc_call_channel RPC_CHANNEL_UCP need udp service, make sure "
"[network].enable_udp");
return false;
}
}

return true;
Expand Down