提交 fa6a1a00 编写于 作者: W wujing

websocket server listening port configurable

Signed-off-by: Nwujing <wujing50@huawei.com>
上级 8a722d35
...@@ -156,6 +156,7 @@ int service_arguments_init(struct service_arguments *args) ...@@ -156,6 +156,7 @@ int service_arguments_init(struct service_arguments *args)
args->default_ulimit = NULL; args->default_ulimit = NULL;
args->default_ulimit_len = 0; args->default_ulimit_len = 0;
args->json_confs->websocket_server_listening_port = DEFAULT_WEBSOCKET_SERVER_LISTENING_PORT;
ret = 0; ret = 0;
......
...@@ -57,6 +57,7 @@ struct service_arguments { ...@@ -57,6 +57,7 @@ struct service_arguments {
/* default configs */ /* default configs */
host_config_ulimits_element **default_ulimit; host_config_ulimits_element **default_ulimit;
size_t default_ulimit_len; size_t default_ulimit_len;
unsigned int websocket_server_listening_port;
// remaining arguments // remaining arguments
char * const *argv; char * const *argv;
......
...@@ -228,6 +228,27 @@ out: ...@@ -228,6 +228,27 @@ out:
return ret; return ret;
} }
static int check_websocket_server_listening_port(const struct service_arguments *args)
{
#define MIN_REGISTER_PORT 1024
#define MAX_REGISTER_PORT 49151
int ret = 0;
if (args->json_confs->websocket_server_listening_port < MIN_REGISTER_PORT ||
args->json_confs->websocket_server_listening_port > MAX_REGISTER_PORT) {
COMMAND_ERROR("Invalid websocket server listening port: '%d' (range: %d-%d)",
args->json_confs->websocket_server_listening_port,
MIN_REGISTER_PORT, MAX_REGISTER_PORT);
ERROR("Invalid websocket server listening port: '%d' (range: %d-%d)",
args->json_confs->websocket_server_listening_port,
MIN_REGISTER_PORT, MAX_REGISTER_PORT);
ret = -1;
goto out;
}
out:
return ret;
}
int check_args(struct service_arguments *args) int check_args(struct service_arguments *args)
{ {
int ret = 0; int ret = 0;
...@@ -291,6 +312,11 @@ int check_args(struct service_arguments *args) ...@@ -291,6 +312,11 @@ int check_args(struct service_arguments *args)
goto out; goto out;
} }
if (check_websocket_server_listening_port(args) != 0) {
ret = -1;
goto out;
}
out: out:
return ret; return ret;
} }
......
...@@ -99,7 +99,10 @@ int update_default_ulimit(struct service_arguments *args); ...@@ -99,7 +99,10 @@ int update_default_ulimit(struct service_arguments *args);
{ CMD_OPT_TYPE_STRING_DUP, false, "tlskey", 0, &(cmdargs)->json_confs->tls_config->key_file, \ { CMD_OPT_TYPE_STRING_DUP, false, "tlskey", 0, &(cmdargs)->json_confs->tls_config->key_file, \
"Path to TLS key file (default \"/root/.iSulad/key.pem\")", NULL }, \ "Path to TLS key file (default \"/root/.iSulad/key.pem\")", NULL }, \
{ CMD_OPT_TYPE_CALLBACK, false, "default-ulimit", 0, &(cmdargs)->default_ulimit, \ { CMD_OPT_TYPE_CALLBACK, false, "default-ulimit", 0, &(cmdargs)->default_ulimit, \
"Default ulimits for containers (default [])", command_default_ulimit_append } "Default ulimits for containers (default [])", command_default_ulimit_append }, \
{ CMD_OPT_TYPE_CALLBACK, false, "websocket-server-listening-port", 0, \
&(cmdargs)->json_confs->websocket_server_listening_port, \
"CRI websocket streaming service listening port (default 10350)", command_convert_uint }
#endif /* __COMMAND_H */ #endif /* __COMMAND_H */
...@@ -1256,6 +1256,28 @@ out: ...@@ -1256,6 +1256,28 @@ out:
return plugins; return plugins;
} }
/* conf get websocket server listening port */
int32_t conf_get_websocket_server_listening_port()
{
int32_t port = 0;
struct service_arguments *conf = NULL;
if (isulad_server_conf_rdlock() != 0) {
return port;
}
conf = conf_get_server_conf();
if (conf == NULL) {
goto out;
}
port = conf->json_confs->websocket_server_listening_port;
out:
(void)isulad_server_conf_unlock();
return port;
}
/* save args to conf */ /* save args to conf */
int save_args_to_conf(struct service_arguments *args) int save_args_to_conf(struct service_arguments *args)
{ {
...@@ -1794,6 +1816,10 @@ int merge_json_confs_into_global(struct service_arguments *args) ...@@ -1794,6 +1816,10 @@ int merge_json_confs_into_global(struct service_arguments *args)
args->json_confs->image_layer_check = tmp_json_confs->image_layer_check; args->json_confs->image_layer_check = tmp_json_confs->image_layer_check;
} }
if (tmp_json_confs->websocket_server_listening_port) {
args->json_confs->websocket_server_listening_port = tmp_json_confs->websocket_server_listening_port;
}
override_bool_pointer_value(&args->json_confs->use_decrypted_key, &tmp_json_confs->use_decrypted_key); override_bool_pointer_value(&args->json_confs->use_decrypted_key, &tmp_json_confs->use_decrypted_key);
if (tmp_json_confs->insecure_skip_verify_enforce) { if (tmp_json_confs->insecure_skip_verify_enforce) {
......
...@@ -47,6 +47,7 @@ char *conf_get_isulad_log_gather_fifo_path(); ...@@ -47,6 +47,7 @@ char *conf_get_isulad_log_gather_fifo_path();
char *conf_get_isulad_log_file(); char *conf_get_isulad_log_file();
char *conf_get_engine_log_file(); char *conf_get_engine_log_file();
char *conf_get_enable_plugins(); char *conf_get_enable_plugins();
int32_t conf_get_websocket_server_listening_port();
int save_args_to_conf(struct service_arguments *args); int save_args_to_conf(struct service_arguments *args);
......
...@@ -59,5 +59,7 @@ ...@@ -59,5 +59,7 @@
#define MAX_MSG_BUFFER_SIZE (32 * 1024) #define MAX_MSG_BUFFER_SIZE (32 * 1024)
#define DEFAULT_WEBSOCKET_SERVER_LISTENING_PORT 10350
#endif #endif
...@@ -118,6 +118,9 @@ ...@@ -118,6 +118,9 @@
"cgroup-parent": { "cgroup-parent": {
"type": "string" "type": "string"
}, },
"websocket-server-listening-port": {
"type": "int32"
},
"default-ulimits": { "default-ulimits": {
"type": "object", "type": "object",
"patternProperties": { "patternProperties": {
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "utils.h" #include "utils.h"
#include "request_cache.h" #include "request_cache.h"
#include "constants.h" #include "constants.h"
#include "isulad_config.h"
struct lws_context *WebsocketServer::m_context = nullptr; struct lws_context *WebsocketServer::m_context = nullptr;
std::atomic<WebsocketServer *> WebsocketServer::m_instance; std::atomic<WebsocketServer *> WebsocketServer::m_instance;
...@@ -385,6 +386,12 @@ void WebsocketServer::ServiceWorkThread(int threadid) ...@@ -385,6 +386,12 @@ void WebsocketServer::ServiceWorkThread(int threadid)
void WebsocketServer::Start(Errors &err) void WebsocketServer::Start(Errors &err)
{ {
m_listenPort = conf_get_websocket_server_listening_port();
if (m_listenPort == 0) {
err.SetError("Failed to get websocket server listening port from daemon config");
return;
}
if (CreateContext() < 0) { if (CreateContext() < 0) {
err.SetError("Websocket server start failed!, please check your network status" err.SetError("Websocket server start failed!, please check your network status"
"(eg: port " + std::to_string(m_listenPort) + "is occupied)"); "(eg: port " + std::to_string(m_listenPort) + "is occupied)");
......
...@@ -116,7 +116,7 @@ private: ...@@ -116,7 +116,7 @@ private:
RouteCallbackRegister m_handler; RouteCallbackRegister m_handler;
static std::map<struct lws *, session_data> m_wsis; static std::map<struct lws *, session_data> m_wsis;
url::URLDatum m_url; url::URLDatum m_url;
int m_listenPort = 10251; int m_listenPort;
}; };
ssize_t WsWriteToClient(void *context, const void *data, size_t len); ssize_t WsWriteToClient(void *context, const void *data, size_t len);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册