diff --git a/include/quicer_types.hrl b/include/quicer_types.hrl index 51033269..bcdfba76 100644 --- a/include/quicer_types.hrl +++ b/include/quicer_types.hrl @@ -86,9 +86,9 @@ , key := file:filename() , keyfile := file:filename() , verify => none | peer | verify_peer | verify_none - , cacertfile => filelib:filename() + , cacertfile => file:filename() , password => string() - , sslkeylogfile => filelib:filename() + , sslkeylogfile => file:filename() , allow_insecure => boolean() , quic_registration => reg_handle() , conn_acceptors => non_neg_integer() @@ -141,16 +141,16 @@ -type conn_opts() :: quic_settings() | #{ alpn := [string()] , conn_callback => module() - , cert => filelib:filename() - , certfile => filelib:filename() - , key => filelib:filename() - , keyfile => filelib:filename() + , cert => file:filename() + , certfile => file:filename() + , key => file:filename() + , keyfile => file:filename() , password => string() , verify => none | peer , handle => connection_handle() %% get NST from last connection, for reconnect. , nst => binary() - , cacertfile => filelib:filename() - , sslkeylogfile => filelib:filename() + , cacertfile => file:filename() + , sslkeylogfile => file:filename() , peer_bidi_stream_count => uint16() , peer_unidi_stream_count => uint16() , handshake_idle_timeout_ms => non_neg_integer() diff --git a/src/quicer.erl b/src/quicer.erl index 454fd40c..f93a4ef4 100644 --- a/src/quicer.erl +++ b/src/quicer.erl @@ -129,8 +129,19 @@ %% versions -export([abi_version/0]). --type connection_opts() :: proplists:proplist() | quicer_connection:opts(). --type listener_opts() :: proplists:proplist() | quicer_listener:listener_opts(). + +%% export types +-export_type([listener_handle/0, + listener_opts/0, + listen_on/0, + connection_handle/0, + conn_opts/0, + stream_handle/0, + stream_opts/0 + ]). + +-type connection_opts() :: proplists:proplist() | conn_opts(). +-type listener_opts() :: proplists:proplist() | listen_opts(). %% @doc Return ABI version of the library. -spec abi_version() -> quicer_nif:abi_version(). @@ -161,32 +172,32 @@ close_lib() -> %% @doc Create a new registration. --spec new_registration(Name, Profile) -> - quicer_nif:new_registration(Name, Profile). +-spec new_registration(string(), registration_profile()) -> + quicer_nif:new_registration(). new_registration(Name, Profile) -> quicer_nif:new_registration(Name, Profile). %% @doc Shutdown a registration. --spec shutdown_registration(Handle) -> - quicer_nif:shutdown_registration(Handle). +-spec shutdown_registration(reg_handle()) -> + quicer_nif:shutdown_registration(). shutdown_registration(Handle) -> quicer_nif:shutdown_registration(Handle). %% @doc Shutdown a registration with error code and silent flag. --spec shutdown_registration(Handle, IsSilent, ErrCode) -> - quicer_nif:shutdown_registration(Handle, IsSilent, ErrCode). +-spec shutdown_registration(reg_handle(), boolean(), uint64()) -> + quicer_nif:shutdown_registration(). shutdown_registration(Handle, IsSilent, ErrCode) -> quicer_nif:shutdown_registration(Handle, IsSilent, ErrCode). %% @doc close a registration. --spec close_registration(Handle) -> - quicer_nif:close_registration(Handle). +-spec close_registration(reg_handle()) -> + quicer_nif:close_registration(). close_registration(Handle) -> quicer_nif:close_registration(Handle). %% @doc get registration name --spec get_registration_name(Handle) -> - quicer_nif:get_registration_name(Handle). +-spec get_registration_name(reg_handle()) -> + quicer_nif:get_registration_name(). get_registration_name(Handle) -> quicer_nif:get_registration_name(Handle). @@ -288,7 +299,7 @@ listen(ListenOn, Opts) when is_map(Opts) -> close_listener(Listener) -> close_listener(Listener, 5000). --spec close_listener(listener_handle(), timer:time()) -> +-spec close_listener(listener_handle(), timeout()) -> ok | {error, badarg | closed | timeout}. close_listener(Listener, Timeout) -> case quicer_nif:close_listener(Listener) of @@ -946,7 +957,7 @@ peername(Handle) -> %% @doc Peer Cert in DER-encoded binary %% mimic {@link ssl:peername/1} -spec peercert(connection_handle() | stream_handle()) -> - {ok, Cert:: public_key:der_encoded()} | {error, any()}. + {ok, CertDerEncoded :: binary()} | {error, any()}. peercert(Handle) -> quicer_nif:peercert(Handle). @@ -971,7 +982,7 @@ open_connection() -> %% @doc list all listeners -spec listeners() -> [{{ quicer_listener:listener_name() - , quicer_listener:listen_on()}, + , quicer:listen_on()}, pid()}]. listeners() -> quicer_listener_sup:listeners(). @@ -979,7 +990,7 @@ listeners() -> %% @doc List listener with app name -spec listener(quicer_listener:listener_name() | {quicer_listener:listener_name(), - quicer_listener:listen_on()}) -> {ok, pid()} | {error, not_found}. + quicer:listen_on()}) -> {ok, pid()} | {error, not_found}. listener(Name) -> quicer_listener_sup:listener(Name). @@ -989,7 +1000,7 @@ get_listeners() -> quicer_nif:get_listeners(). %% @doc Get a list of listeners under registration handle --spec get_listeners(Reg | global) -> quicer_nif:get_listeners(Reg). +-spec get_listeners(reg_handle() | global) -> quicer_nif:get_listeners(). get_listeners(global) -> quicer_nif:get_listeners(); get_listeners(Reg) -> @@ -1002,21 +1013,21 @@ get_connections() -> quicer_nif:get_connections(). %% @doc Get a list of connections under registration handle --spec get_connections(Reg | global) -> quicer_nif:get_connections(Reg). +-spec get_connections(reg_handle() | global) -> quicer_nif:get_connections(). get_connections(global) -> quicer_nif:get_connections(); get_connections(Reg) -> quicer_nif:get_connections(Reg). --spec get_conn_owner(C) -> quicer_nif:get_conn_owner(C). +-spec get_conn_owner(connection_handle()) -> quicer_nif:get_owner(). get_conn_owner(Conn) -> quicer_nif:get_conn_owner(Conn). --spec get_stream_owner(S) -> quicer_nif:get_stream_owner(S). +-spec get_stream_owner(stream_handle()) -> quicer_nif:get_owner(). get_stream_owner(Stream) -> quicer_nif:get_stream_owner(Stream). --spec get_listener_owner(L) -> quicer_nif:get_listener_owner(L). +-spec get_listener_owner(listener_handle()) -> quicer_nif:get_owner(). get_listener_owner(Listener) -> quicer_nif:get_listener_owner(Listener). @@ -1071,7 +1082,7 @@ handoff_stream(Stream, NewOwner, HandoffData) -> ActiveN =/= false andalso quicer:setopt(Stream, active, false), Res = case forward_stream_msgs(Stream, NewOwner) of ok -> - quicer:controlling_process(Stream, NewOwner), + _ = quicer:controlling_process(Stream, NewOwner), NewOwner ! {handoff_done, Stream, HandoffData}, ok; {error, _} = Other -> diff --git a/src/quicer_app.erl b/src/quicer_app.erl index 0b88baf4..56484f97 100644 --- a/src/quicer_app.erl +++ b/src/quicer_app.erl @@ -21,7 +21,7 @@ ]). start(_StartType, _StartArgs) -> - quicer:open_lib(), + _ = quicer:open_lib(), _ = quicer:reg_open(application:get_env(quicer, profile, quic_execution_profile_low_latency)), quicer_sup:start_link(). diff --git a/src/quicer_connection.erl b/src/quicer_connection.erl index b8b33c73..edd683c6 100644 --- a/src/quicer_connection.erl +++ b/src/quicer_connection.erl @@ -157,7 +157,7 @@ start_link(CallbackModule, {_Host, _Port} = Peer, {_COpts, _SOpts} = Opts) when %% Get `CallbackModule` from conn_opts, key:`conn_callback` if `CallbackModule` is undefined, %% this is the entry for supervised acceptor. -spec start_link(CallbackModule :: undefined | module(), - Listener ::quicer:listener_handle(), + Listener :: quicer:listener_handle(), ConnOpts :: term(), Sup :: pid()) -> {ok, Pid :: pid()} | {error, Error :: {already_started, pid()}} | diff --git a/src/quicer_lib.erl b/src/quicer_lib.erl index 3fe6f71c..c517e643 100644 --- a/src/quicer_lib.erl +++ b/src/quicer_lib.erl @@ -17,6 +17,7 @@ -include("quicer_types.hrl"). -export_type([ cb_ret/0 + , cb_state/0 ]). -type cb_ret() :: cb_ret_noreply() | cb_ret_reply(). -type cb_state() :: term(). diff --git a/src/quicer_listener.erl b/src/quicer_listener.erl index e495439c..085e0745 100644 --- a/src/quicer_listener.erl +++ b/src/quicer_listener.erl @@ -33,9 +33,9 @@ , alpn :: [string()] }). +-export_type([listener_name/0]). + -type listener_name() :: atom(). --type listen_on() :: inet:port_number() | string(). %% "127.0.0.1:8080" --type listener_opts() :: map(). %%%=================================================================== %%% API @@ -47,11 +47,11 @@ %% @end %%-------------------------------------------------------------------- -spec start_link(Name :: listener_name(), - ListenOn :: listen_on(), + ListenOn :: quicer:listen_on(), Options :: - { listener_opts() - , quicer_connection:opts() - , quicer_stream:stream_opts() + { quicer:listener_opts() + , quicer:conn_opts() + , quicer:stream_opts() } ) -> {ok, Pid :: pid()} | {error, Error :: {already_started, pid()}} | @@ -89,7 +89,7 @@ init([Name, ListenOn, { #{conn_acceptors := N, alpn := Alpn} = LOpts, process_flag(trap_exit, true), {ok, L} = quicer:listen(ListenOn, maps:without([conn_acceptors], LOpts)), {ok, ConnSup} = supervisor:start_link(quicer_conn_acceptor_sup, [L, Opts]), - [{ok, _} = supervisor:start_child(ConnSup, [ConnSup]) || _ <- lists:seq(1, N)], + _ = [{ok, _} = supervisor:start_child(ConnSup, [ConnSup]) || _ <- lists:seq(1, N)], {ok, #state{ name = Name , listener = L , conn_sup = ConnSup @@ -156,5 +156,5 @@ handle_info(_Info, State) -> State :: term()) -> any(). terminate(_Reason, #state{listener = L}) -> %% nif listener has no owner process so we need to close it explicitly. - quicer:close_listener(L), + _ = quicer:close_listener(L), ok. diff --git a/src/quicer_listener_sup.erl b/src/quicer_listener_sup.erl index 0e184b06..254c52b9 100644 --- a/src/quicer_listener_sup.erl +++ b/src/quicer_listener_sup.erl @@ -51,7 +51,7 @@ start_listener(AppName, Port, Options) -> supervisor:start_child(?MODULE, chid_spec(AppName, Port, Options)). stop_listener(AppName) -> - supervisor:terminate_child(?MODULE, ?CHILD_ID(AppName)), + _ = supervisor:terminate_child(?MODULE, ?CHILD_ID(AppName)), supervisor:delete_child(?MODULE, ?CHILD_ID(AppName)). -spec listeners() -> [{{atom(), integer()|string()}, pid()}]. diff --git a/src/quicer_nif.erl b/src/quicer_nif.erl index 4652e01a..d50f89b7 100644 --- a/src/quicer_nif.erl +++ b/src/quicer_nif.erl @@ -67,6 +67,28 @@ %% for test -export([init/1]). + +-export_type([ abi_version/0, + new_registration/0, + shutdown_registration/0, + close_registration/0, + get_registration_name/0, + get_listeners/0, + get_connections/0, + get_owner/0 + ]). + +%% NIF fuction return types +-type abi_version() :: integer(). +-type new_registration() :: {ok, reg_handle()} | {error, atom_reason()}. +-type shutdown_registration() :: ok | {error, badarg}. +-type close_registration() :: ok | {error, badarg}. +-type get_registration_name() :: {ok, string()} | {error, badarg}. +-type get_listeners() :: [listener_handle()]. +-type get_connections() :: [connection_handle()]. +-type get_owner() :: {ok, pid()} | {error, undefined | badarg}. + + %% @NOTE: In embedded mode, first all modules are loaded. Then all on_load functions are called. -on_load(init/0). @@ -75,7 +97,7 @@ -include("quicer_types.hrl"). -include("quicer_vsn.hrl"). --spec abi_version() -> integer(). +-spec abi_version() -> abi_version(). abi_version() -> ?QUICER_ABI_VERSION. @@ -144,25 +166,24 @@ reg_close() -> erlang:nif_error(nif_library_not_loaded). --spec new_registration(Name::string(), registration_profile()) -> - {ok, reg_handle()} | {error, atom_reason()}. +-spec new_registration(Name::string(), Profile :: registration_profile()) -> new_registration(). new_registration(_Name, _Profile) -> erlang:nif_error(nif_library_not_loaded). --spec shutdown_registration(reg_handle()) -> ok | {error | badarg}. +-spec shutdown_registration(reg_handle()) -> shutdown_registration(). shutdown_registration(_Handle) -> erlang:nif_error(nif_library_not_loaded). -spec shutdown_registration(reg_handle(), IsSilent::boolean(), ErrorCode::uint64()) - -> ok | {error | badarg}. + -> shutdown_registration(). shutdown_registration(_Handle, _IsSilent, _ErrorCode) -> erlang:nif_error(nif_library_not_loaded). --spec close_registration(reg_handle()) -> ok | {error | badarg}. +-spec close_registration(reg_handle()) -> close_registration(). close_registration(_Handle) -> erlang:nif_error(nif_library_not_loaded). --spec get_registration_name(reg_handle()) -> {ok, string()} | {error, badarg}. +-spec get_registration_name(reg_handle()) -> get_registration_name(). get_registration_name(_Handle) -> erlang:nif_error(nif_library_not_loaded). @@ -306,27 +327,27 @@ controlling_process(_H, _P) -> erlang:nif_error(nif_library_not_loaded). -spec peercert(connection_handle() | stream_handle()) -> - {ok, Cert:: public_key:der_encoded()} | {error, any()}. + {ok, CertDerEncoded :: binary()} | {error, any()}. peercert(_Handle) -> erlang:nif_error(nif_library_not_loaded). --spec get_conn_owner(connection_handle()) -> {ok, pid()} | {error, undefined | badarg}. +-spec get_conn_owner(connection_handle()) -> get_owner(). get_conn_owner(_) -> erlang:nif_error(nif_library_not_loaded). --spec get_stream_owner(connection_handle()) -> {ok, pid()} | {error, undefined | badarg}. +-spec get_stream_owner(connection_handle()) -> get_owner(). get_stream_owner(_) -> erlang:nif_error(nif_library_not_loaded). --spec get_listener_owner(listener_handle()) -> {ok, pid()} | {error, undefined | badarg}. +-spec get_listener_owner(listener_handle()) -> get_owner(). get_listener_owner(_) -> erlang:nif_error(nif_library_not_loaded). --spec get_listeners() -> [listener_handle()]. +-spec get_listeners() -> get_listeners(). get_listeners() -> erlang:nif_error(nif_library_not_loaded). --spec get_listeners(reg_handle()) -> [listener_handle()] | {error, badarg}. +-spec get_listeners(reg_handle()) -> get_listeners(). get_listeners(_) -> erlang:nif_error(nif_library_not_loaded). diff --git a/src/quicer_server_conn_callback.erl b/src/quicer_server_conn_callback.erl index 62d0abfd..3de88412 100644 --- a/src/quicer_server_conn_callback.erl +++ b/src/quicer_server_conn_callback.erl @@ -111,7 +111,7 @@ peer_needs_streams(_C, _UnidiOrBidi, S) -> connected(Conn, _Flags, #{ slow_start := false, stream_opts := SOpts , stream_callback := Callback} = S) -> %% @TODO configurable behavior of spawing stream acceptor - quicer_stream:start_link(Callback, Conn, SOpts), + _ = quicer_stream:start_link(Callback, Conn, SOpts), {ok, S#{conn => Conn}}; connected(_Connecion, _Flags, S) -> {ok, S}. diff --git a/src/quicer_stream.erl b/src/quicer_stream.erl index a54e4ca9..5a5cc29e 100644 --- a/src/quicer_stream.erl +++ b/src/quicer_stream.erl @@ -136,7 +136,7 @@ start_link(Callback, Conn, StreamOpts) when is_atom(Callback) -> %% then handoff ownership to this process %%-------------------------------------------------------------------- -spec start_link(Callback :: module(), - Stream :: quicer:connection_handle(), + Stream :: quicer:stream_handle(), Conn :: quicer:connection_handle(), StreamOpts :: map(), Props :: new_stream_props()