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 {
bind: "0.0.0.0:1883"
max_connections: 1024000
bind = "0.0.0.0:1883"
max_connections = 1024000
}
listeners.ssl.default {
bind: "0.0.0.0:8883"
max_connections: 512000
ssl {
keyfile: "{{ platform_etc_dir }}/certs/key.pem"
certfile: "{{ platform_etc_dir }}/certs/cert.pem"
cacertfile: "{{ platform_etc_dir }}/certs/cacert.pem"
bind = "0.0.0.0:8883"
max_connections = 512000
ssl_options {
keyfile = "{{ platform_etc_dir }}/certs/key.pem"
certfile = "{{ platform_etc_dir }}/certs/cert.pem"
cacertfile = "{{ platform_etc_dir }}/certs/cacert.pem"
}
}
listeners.ws.default {
bind: "0.0.0.0:8083"
max_connections: 1024000
websocket.mqtt_path: "/mqtt"
bind = "0.0.0.0:8083"
max_connections = 1024000
websocket.mqtt_path = "/mqtt"
}
listeners.wss.default {
bind: "0.0.0.0:8084"
max_connections: 512000
websocket.mqtt_path: "/mqtt"
ssl {
keyfile: "{{ platform_etc_dir }}/certs/key.pem"
certfile: "{{ platform_etc_dir }}/certs/cert.pem"
cacertfile: "{{ platform_etc_dir }}/certs/cacert.pem"
bind = "0.0.0.0:8084"
max_connections = 512000
websocket.mqtt_path = "/mqtt"
ssl_options {
keyfile = "{{ platform_etc_dir }}/certs/key.pem"
certfile = "{{ platform_etc_dir }}/certs/cert.pem"
cacertfile = "{{ platform_etc_dir }}/certs/cacert.pem"
}
}
# listeners.quic.default {
# enabled: false
# bind: "0.0.0.0:14567"
# max_connections: 1024000
# keyfile: "{{ platform_etc_dir }}/certs/key.pem"
# certfile: "{{ platform_etc_dir }}/certs/cert.pem"
# enabled = false
# bind = "0.0.0.0:14567"
# max_connections = 1024000
# keyfile = "{{ platform_etc_dir }}/certs/key.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(Type, Listener) -> emqx_config:get_listener_conf(Type, Listener, [tcp, active_n]).
get_active_n(quic, _Listener) ->
?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) ->
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),
listener => {Type, ListenerName},
limiter => limiter(Opts)
@ -497,7 +497,7 @@ limiter(Opts) ->
ssl_opts(Opts) ->
maps:to_list(
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:without(
[active_n],
maps:get(tcp, Opts, #{})
maps:get(tcp_options, Opts, #{})
)
).

View File

@ -787,29 +787,32 @@ fields("listeners") ->
)}
];
fields("mqtt_tcp_listener") ->
mqtt_listener(1883) ++
[
{"tcp",
{"tcp_options",
sc(
ref("tcp_opts"),
#{}
)}
] ++ mqtt_listener(1883);
];
fields("mqtt_ssl_listener") ->
mqtt_listener(8883) ++
[
{"tcp",
{"tcp_options",
sc(
ref("tcp_opts"),
#{}
)},
{"ssl",
{"ssl_options",
sc(
ref("listener_ssl_opts"),
#{}
)}
] ++ mqtt_listener(8883);
];
fields("mqtt_ws_listener") ->
mqtt_listener(8083) ++
[
{"tcp",
{"tcp_options",
sc(
ref("tcp_opts"),
#{}
@ -819,15 +822,16 @@ fields("mqtt_ws_listener") ->
ref("ws_opts"),
#{}
)}
] ++ mqtt_listener(8083);
];
fields("mqtt_wss_listener") ->
mqtt_listener(8084) ++
[
{"tcp",
{"tcp_options",
sc(
ref("tcp_opts"),
#{}
)},
{"ssl",
{"ssl_options",
sc(
ref("listener_wss_opts"),
#{}
@ -837,7 +841,7 @@ fields("mqtt_wss_listener") ->
ref("ws_opts"),
#{}
)}
] ++ mqtt_listener(8084);
];
fields("mqtt_quic_listener") ->
[
{"enabled",

View File

@ -1046,4 +1046,4 @@ get_ws_opts(Type, Listener, Key) ->
emqx_config:get_listener_conf(Type, Listener, [websocket, Key]).
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_timeout => <<"3s">>,
running => true,
tcp => #{
tcp_options => #{
active_n => 100,
backlog => 1024,
buffer => <<"4KB">>,