feat: make tcp/ssl options more straightforward

This commit is contained in:
Zhongwen Deng 2022-06-07 16:21:04 +08:00
parent e035ff573d
commit dd873147b3
6 changed files with 84 additions and 78 deletions

View File

@ -1,39 +1,39 @@
listeners.tcp.default { listeners.tcp.default {
bind: "0.0.0.0:1883" bind = "0.0.0.0:1883"
max_connections: 1024000 max_connections = 1024000
} }
listeners.ssl.default { listeners.ssl.default {
bind: "0.0.0.0:8883" bind = "0.0.0.0:8883"
max_connections: 512000 max_connections = 512000
ssl { ssl_options {
keyfile: "{{ platform_etc_dir }}/certs/key.pem" keyfile = "{{ platform_etc_dir }}/certs/key.pem"
certfile: "{{ platform_etc_dir }}/certs/cert.pem" certfile = "{{ platform_etc_dir }}/certs/cert.pem"
cacertfile: "{{ platform_etc_dir }}/certs/cacert.pem" cacertfile = "{{ platform_etc_dir }}/certs/cacert.pem"
} }
} }
listeners.ws.default { listeners.ws.default {
bind: "0.0.0.0:8083" bind = "0.0.0.0:8083"
max_connections: 1024000 max_connections = 1024000
websocket.mqtt_path: "/mqtt" websocket.mqtt_path = "/mqtt"
} }
listeners.wss.default { listeners.wss.default {
bind: "0.0.0.0:8084" bind = "0.0.0.0:8084"
max_connections: 512000 max_connections = 512000
websocket.mqtt_path: "/mqtt" websocket.mqtt_path = "/mqtt"
ssl { ssl_options {
keyfile: "{{ platform_etc_dir }}/certs/key.pem" keyfile = "{{ platform_etc_dir }}/certs/key.pem"
certfile: "{{ platform_etc_dir }}/certs/cert.pem" certfile = "{{ platform_etc_dir }}/certs/cert.pem"
cacertfile: "{{ platform_etc_dir }}/certs/cacert.pem" cacertfile = "{{ platform_etc_dir }}/certs/cacert.pem"
} }
} }
# listeners.quic.default { # listeners.quic.default {
# enabled: false # enabled = false
# bind: "0.0.0.0:14567" # bind = "0.0.0.0:14567"
# max_connections: 1024000 # max_connections = 1024000
# keyfile: "{{ platform_etc_dir }}/certs/key.pem" # keyfile = "{{ platform_etc_dir }}/certs/key.pem"
# certfile: "{{ platform_etc_dir }}/certs/cert.pem" # certfile = "{{ platform_etc_dir }}/certs/cert.pem"
#} #}

View File

@ -1176,5 +1176,7 @@ get_state(Pid) ->
) )
). ).
get_active_n(quic, _Listener) -> ?ACTIVE_N; get_active_n(quic, _Listener) ->
get_active_n(Type, Listener) -> emqx_config:get_listener_conf(Type, Listener, [tcp, active_n]). ?ACTIVE_N;
get_active_n(Type, Listener) ->
emqx_config:get_listener_conf(Type, Listener, [tcp_options, active_n]).

View File

@ -406,7 +406,7 @@ esockd_opts(Type, Opts0) ->
ws_opts(Type, ListenerName, Opts) -> ws_opts(Type, ListenerName, Opts) ->
WsPaths = [ WsPaths = [
{maps:get(mqtt_path, Opts, "/mqtt"), emqx_ws_connection, #{ {emqx_map_lib:deep_get([websocket, mqtt_path], Opts, "/mqtt"), emqx_ws_connection, #{
zone => zone(Opts), zone => zone(Opts),
listener => {Type, ListenerName}, listener => {Type, ListenerName},
limiter => limiter(Opts) limiter => limiter(Opts)
@ -497,7 +497,7 @@ limiter(Opts) ->
ssl_opts(Opts) -> ssl_opts(Opts) ->
maps:to_list( maps:to_list(
emqx_tls_lib:drop_tls13_for_old_otp( emqx_tls_lib:drop_tls13_for_old_otp(
maps:get(ssl, Opts, #{}) maps:get(ssl_options, Opts, #{})
) )
). ).
@ -505,7 +505,7 @@ tcp_opts(Opts) ->
maps:to_list( maps:to_list(
maps:without( maps:without(
[active_n], [active_n],
maps:get(tcp, Opts, #{}) maps:get(tcp_options, Opts, #{})
) )
). ).

View File

@ -787,57 +787,61 @@ fields("listeners") ->
)} )}
]; ];
fields("mqtt_tcp_listener") -> fields("mqtt_tcp_listener") ->
[ mqtt_listener(1883) ++
{"tcp", [
sc( {"tcp_options",
ref("tcp_opts"), sc(
#{} ref("tcp_opts"),
)} #{}
] ++ mqtt_listener(1883); )}
];
fields("mqtt_ssl_listener") -> fields("mqtt_ssl_listener") ->
[ mqtt_listener(8883) ++
{"tcp", [
sc( {"tcp_options",
ref("tcp_opts"), sc(
#{} ref("tcp_opts"),
)}, #{}
{"ssl", )},
sc( {"ssl_options",
ref("listener_ssl_opts"), sc(
#{} ref("listener_ssl_opts"),
)} #{}
] ++ mqtt_listener(8883); )}
];
fields("mqtt_ws_listener") -> fields("mqtt_ws_listener") ->
[ mqtt_listener(8083) ++
{"tcp", [
sc( {"tcp_options",
ref("tcp_opts"), sc(
#{} ref("tcp_opts"),
)}, #{}
{"websocket", )},
sc( {"websocket",
ref("ws_opts"), sc(
#{} ref("ws_opts"),
)} #{}
] ++ mqtt_listener(8083); )}
];
fields("mqtt_wss_listener") -> fields("mqtt_wss_listener") ->
[ mqtt_listener(8084) ++
{"tcp", [
sc( {"tcp_options",
ref("tcp_opts"), sc(
#{} ref("tcp_opts"),
)}, #{}
{"ssl", )},
sc( {"ssl_options",
ref("listener_wss_opts"), sc(
#{} ref("listener_wss_opts"),
)}, #{}
{"websocket", )},
sc( {"websocket",
ref("ws_opts"), sc(
#{} ref("ws_opts"),
)} #{}
] ++ mqtt_listener(8084); )}
];
fields("mqtt_quic_listener") -> fields("mqtt_quic_listener") ->
[ [
{"enabled", {"enabled",

View File

@ -1046,4 +1046,4 @@ get_ws_opts(Type, Listener, Key) ->
emqx_config:get_listener_conf(Type, Listener, [websocket, Key]). emqx_config:get_listener_conf(Type, Listener, [websocket, Key]).
get_active_n(Type, Listener) -> get_active_n(Type, Listener) ->
emqx_config:get_listener_conf(Type, Listener, [tcp, active_n]). emqx_config:get_listener_conf(Type, Listener, [tcp_options, active_n]).

View File

@ -685,7 +685,7 @@ tcp_schema_example() ->
proxy_protocol => false, proxy_protocol => false,
proxy_protocol_timeout => <<"3s">>, proxy_protocol_timeout => <<"3s">>,
running => true, running => true,
tcp => #{ tcp_options => #{
active_n => 100, active_n => 100,
backlog => 1024, backlog => 1024,
buffer => <<"4KB">>, buffer => <<"4KB">>,