diff --git a/apps/emqx/etc/emqx.conf b/apps/emqx/etc/emqx.conf index e86512a0f..554ab05fd 100644 --- a/apps/emqx/etc/emqx.conf +++ b/apps/emqx/etc/emqx.conf @@ -211,82 +211,6 @@ listeners.ssl.default { tcp.buffer = 4KB } -## MQTT/QUIC - QUIC Listeners for MQTT Protocol -## syntax: listeners.quic. -## example: listeners.quic.my_quic_listener -listeners.quic.default { - ## The IP address and port that the listener will bind. - ## - ## @doc listeners.quic..bind - ## ValueType: IPAddress | Port | IPAddrPort - ## Required: true - ## Examples: 14567, 127.0.0.1:14567, ::1:14567 - bind = "0.0.0.0:14567" - - ## The configuration zone this listener is using. - ## If not set, the global configs are used for this listener. - ## - ## See `zones.` for more details. - ## NOTE: This is a cluster-wide configuration. - ## It requires all nodes to be stopped before changing it. - ## - ## @doc listeners.quic..zone - ## ValueType: String - ## Required: false - #zone = default - - ## The size of the acceptor pool for this listener. - ## - ## @doc listeners.quic..acceptors - ## ValueType: Number - ## Default: 16 - acceptors = 16 - - ## Maximum number of concurrent connections. - ## - ## @doc listeners.quic..max_connections - ## ValueType: Number | infinity - ## Default: infinity - max_connections = 1024000 - - ## Path to the file containing the user's private PEM-encoded key. - ## - ## @doc listeners.quic..keyfile - ## ValueType: String - ## Default: "{{ platform_etc_dir }}/certs/key.pem" - keyfile = "{{ platform_etc_dir }}/certs/key.pem" - - ## Path to a file containing the user certificate. - ## - ## @doc listeners.quic..certfile - ## ValueType: String - ## Default: "{{ platform_etc_dir }}/certs/cert.pem" - certfile = "{{ platform_etc_dir }}/certs/cert.pem" - - ## When publishing or subscribing, prefix all topics with a mountpoint string. - ## The prefixed string will be removed from the topic name when the message - ## is delivered to the subscriber. The mountpoint is a way that users can use - ## to implement isolation of message routing between different listeners. - ## - ## For example if a clientA subscribes to "t" with `listeners.quic..mountpoint` - ## set to "some_tenant", then the client accually subscribes to the topic - ## "some_tenant/t". Similarly if another clientB (connected to the same listener - ## with the clientA) send a message to topic "t", the message is accually route - ## to all the clients subscribed "some_tenant/t", so clientA will receive the - ## message, with topic name "t". - ## - ## Set to "" to disable the feature. - ## - ## Variables in mountpoint string: - ## - ${clientid}: clientid - ## - ${username}: username - ## - ## @doc listeners.quic..mountpoint - ## ValueType: String - ## Default: "" - mountpoint = "" -} - ## MQTT/WS - Websocket Listeners for MQTT Protocol ## syntax: listeners.ws. ## example: listeners.ws.my_ws_listener diff --git a/apps/emqx/test/emqx_broker_SUITE.erl b/apps/emqx/test/emqx_broker_SUITE.erl index f6e122059..158a5a420 100644 --- a/apps/emqx/test/emqx_broker_SUITE.erl +++ b/apps/emqx/test/emqx_broker_SUITE.erl @@ -75,9 +75,11 @@ init_per_group(ws, Config) -> init_per_group(quic, Config) -> emqx_common_test_helpers:boot_modules(all), emqx_common_test_helpers:start_apps([]), + UdpPort = 14567, + ok = emqx_common_test_helpers:ensure_quic_listener(?MODULE, UdpPort), [ {conn_fun, quic_connect}, - {port, 14567} + {port, UdpPort} | Config ]; init_per_group(_Group, Config) -> diff --git a/apps/emqx/test/emqx_common_test_helpers.erl b/apps/emqx/test/emqx_common_test_helpers.erl index aced2d95a..4e5a0ffbc 100644 --- a/apps/emqx/test/emqx_common_test_helpers.erl +++ b/apps/emqx/test/emqx_common_test_helpers.erl @@ -55,6 +55,8 @@ is_tcp_server_available/3 ]). +-export([ensure_quic_listener/2]). + -define(CERTS_PATH(CertName), filename:join(["etc", "certs", CertName])). -define(MQTT_SSL_TWOWAY, [ @@ -503,3 +505,30 @@ ensure_dashboard_listeners_started(emqx_dashboard) -> ok; ensure_dashboard_listeners_started(_App) -> ok. + +-spec ensure_quic_listener(Name :: atom(), UdpPort :: inet:port_number()) -> ok. +ensure_quic_listener(Name, UdpPort) -> + application:ensure_all_started(quicer), + emqx_config:put([listeners, quic, Name, mountpoint], <<>>), + Conf = #{ + acceptors => 16, + bind => {{0, 0, 0, 0}, UdpPort}, + certfile => filename:join(code:lib_dir(emqx), "etc/certs/cert.pem"), + ciphers => + [ + "TLS_AES_256_GCM_SHA384", + "TLS_AES_128_GCM_SHA256", + "TLS_CHACHA20_POLY1305_SHA256" + ], + enabled => true, + idle_timeout => 15000, + keyfile => filename:join(code:lib_dir(emqx), "etc/certs/key.pem"), + limiter => #{}, + max_connections => 1024000, + mountpoint => <<>>, + zone => default + }, + case emqx_listeners:start_listener(quic, Name, Conf) of + ok -> ok; + {error, {already_started, _Pid}} -> ok + end. diff --git a/apps/emqx/test/emqx_mqtt_protocol_v5_SUITE.erl b/apps/emqx/test/emqx_mqtt_protocol_v5_SUITE.erl index e2fe474f8..887cf2a3e 100644 --- a/apps/emqx/test/emqx_mqtt_protocol_v5_SUITE.erl +++ b/apps/emqx/test/emqx_mqtt_protocol_v5_SUITE.erl @@ -62,8 +62,10 @@ init_per_group(tcp, Config) -> emqx_common_test_helpers:start_apps([]), [{port, 1883}, {conn_fun, connect} | Config]; init_per_group(quic, Config) -> + UdpPort = 1884, emqx_common_test_helpers:start_apps([]), - [{port, 14567}, {conn_fun, quic_connect} | Config]; + emqx_common_test_helpers:ensure_quic_listener(?MODULE, UdpPort), + [{port, UdpPort}, {conn_fun, quic_connect} | Config]; init_per_group(_, Config) -> emqx_common_test_helpers:stop_apps([]), Config. diff --git a/apps/emqx/test/emqx_persistent_session_SUITE.erl b/apps/emqx/test/emqx_persistent_session_SUITE.erl index b8830dc0d..c53e4c58b 100644 --- a/apps/emqx/test/emqx_persistent_session_SUITE.erl +++ b/apps/emqx/test/emqx_persistent_session_SUITE.erl @@ -131,7 +131,9 @@ init_per_group(Group, Config) when Group == ws; Group == ws_snabbkaffe -> init_per_group(Group, Config) when Group == tcp; Group == tcp_snabbkaffe -> [{port, 1883}, {conn_fun, connect} | Config]; init_per_group(Group, Config) when Group == quic; Group == quic_snabbkaffe -> - [{port, 14567}, {conn_fun, quic_connect} | Config]; + UdpPort = 1883, + emqx_common_test_helpers:ensure_quic_listener(?MODULE, UdpPort), + [{port, UdpPort}, {conn_fun, quic_connect} | Config]; init_per_group(no_kill_connection_process, Config) -> [{kill_connection_process, false} | Config]; init_per_group(kill_connection_process, Config) -> diff --git a/apps/emqx/test/emqx_shared_sub_SUITE.erl b/apps/emqx/test/emqx_shared_sub_SUITE.erl index 21ffd385e..39ef34cf6 100644 --- a/apps/emqx/test/emqx_shared_sub_SUITE.erl +++ b/apps/emqx/test/emqx_shared_sub_SUITE.erl @@ -561,7 +561,6 @@ setup_node(Node, Port) -> ok = emqx_config:put([listeners, tcp, default, bind], {{127, 0, 0, 1}, Port}), ok = emqx_config:put([listeners, ssl, default, bind], {{127, 0, 0, 1}, Port + 1}), - ok = emqx_config:put([listeners, quic, default, bind], {{127, 0, 0, 1}, Port + 2}), ok = emqx_config:put([listeners, ws, default, bind], {{127, 0, 0, 1}, Port + 3}), ok = emqx_config:put([listeners, wss, default, bind], {{127, 0, 0, 1}, Port + 4}), ok