diff --git a/lib/riverside/connection.ex b/lib/riverside/connection.ex index 020c3a6..7823b0c 100644 --- a/lib/riverside/connection.ex +++ b/lib/riverside/connection.ex @@ -53,46 +53,46 @@ defmodule Riverside.Connection do handler = Keyword.fetch!(opts, :handler) - if handler.__config__.show_debug_logs do + if handler.__config__().show_debug_logs do Logger.debug(" incoming new request: #{peer}") end if Stats.number_of_current_connections() >= - handler.__config__.max_connections do - Logger.warn( + handler.__config__().max_connections do + Logger.warning( " connection number reached the limit." ) # :cow_http.status/1 doesn't support 508, so use 503 instead - {:ok, CowboyUtil.response(req, 503, %{}), {:unset, handler.__config__.show_debug_logs}} + {:ok, CowboyUtil.response(req, 503, %{}), {:unset, handler.__config__().show_debug_logs}} else auth_req = AuthRequest.new(req, peer) case handler.__handle_authentication__(auth_req) do {:ok, user_id, handler_state} -> - timeout = handler.__config__.idle_timeout + timeout = handler.__config__().idle_timeout session_id = Random.hex(20) state = new(handler, user_id, session_id, peer, handler_state) {:cowboy_websocket, req, state, %{idle_timeout: timeout}} {:ok, user_id, session_id, handler_state} -> - timeout = handler.__config__.idle_timeout + timeout = handler.__config__().idle_timeout state = new(handler, user_id, session_id, peer, handler_state) {:cowboy_websocket, req, state, %{idle_timeout: timeout}} {:error, %AuthError{code: code, headers: headers}} -> {:ok, CowboyUtil.response(req, code, headers), - {:unset, handler.__config__.show_debug_logs}} + {:unset, handler.__config__().show_debug_logs}} other -> - if handler.__config__.show_debug_logs do + if handler.__config__().show_debug_logs do Logger.debug( " failed to authenticate by reason: #{inspect(other)}, shutdown" ) end {:ok, CowboyUtil.response(req, 500, %{}), - {:unset, handler.__config__.show_debug_logs}} + {:unset, handler.__config__().show_debug_logs}} end end end @@ -104,13 +104,13 @@ defmodule Riverside.Connection do "(#{state.session}) websocket_init", fn -> {:stop, state} end, fn -> - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug("(#{state.session}) @init") end if Stats.number_of_current_connections() >= - state.handler.__config__.max_connections do - Logger.warn(" connection number is over limit") + state.handler.__config__().max_connections do + Logger.warning(" connection number is over limit") {:stop, state} else @@ -133,14 +133,14 @@ defmodule Riverside.Connection do "(#{state.session}) websocket_info", fn -> {:stop, state} end, fn -> - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug("(#{state.session}) @post_init") end case state.handler.init(state.session, state.handler_state) do {:ok, session2, handler_state2} -> - if state.handler.__config__.connection_max_age != :infinity do - Process.send_after(self(), :over_age, state.handler.__config__.connection_max_age) + if state.handler.__config__().connection_max_age != :infinity do + Process.send_after(self(), :over_age, state.handler.__config__().connection_max_age) end state2 = %{state | session: session2, handler_state: handler_state2} @@ -158,7 +158,7 @@ defmodule Riverside.Connection do end def websocket_info(:over_age, state) do - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug("(#{state.session}) @over_age") end @@ -166,7 +166,7 @@ defmodule Riverside.Connection do end def websocket_info(:stop, state) do - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug("(#{state.session}) @stop") end @@ -174,7 +174,7 @@ defmodule Riverside.Connection do end def websocket_info({:deliver, type, msg}, state) do - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug("(#{state.session}) @deliver") end @@ -188,7 +188,7 @@ defmodule Riverside.Connection do "(#{session}) websocket_info", fn -> {:stop, state} end, fn -> - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug( "(#{session}) @exit: #{inspect(pid)} -> #{inspect(self())}" ) @@ -212,7 +212,7 @@ defmodule Riverside.Connection do "(#{state.session}) websocket_info", fn -> {:stop, state} end, fn -> - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug( "(#{state.session}) @info: #{inspect(event)}" ) @@ -243,7 +243,7 @@ defmodule Riverside.Connection do " websocket_handle", fn -> {:stop, state} end, fn -> - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug("(#{state.session}) @ping") end @@ -257,7 +257,7 @@ defmodule Riverside.Connection do " websocket_handle", fn -> {:stop, state} end, fn -> - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug("(#{state.session}) @binary") end @@ -271,7 +271,7 @@ defmodule Riverside.Connection do "(#{state.session}) websocket_handle", fn -> {:stop, state} end, fn -> - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug("(#{state.session}) @text") end @@ -281,7 +281,7 @@ defmodule Riverside.Connection do end def websocket_handle(event, state) do - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug( "(#{state.session}) handle: unsupported event #{inspect(event)}" ) @@ -303,7 +303,7 @@ defmodule Riverside.Connection do "(#{state.session}) terminate", fn -> :ok end, fn -> - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug( "(#{state.session}) @terminate: #{inspect(reason)}" ) @@ -323,7 +323,7 @@ defmodule Riverside.Connection do "(#{state.session}) terminate", fn -> :ok end, fn -> - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug( "(#{state.session}) @terminate: #{inspect(reason)}" ) @@ -341,7 +341,7 @@ defmodule Riverside.Connection do defp handle_frame(type, data, %{handler: handler, session: session} = state) do Stats.countup_incoming_messages() - case Session.countup_messages(session, handler.__config__.transmission_limit) do + case Session.countup_messages(session, handler.__config__().transmission_limit) do {:ok, session2} -> state2 = %{state | session: session2} @@ -354,7 +354,7 @@ defmodule Riverside.Connection do {:stop, %{state2 | shutdown_reason: reason, handler_state: handler_state3}} {:error, reason} -> - if state.handler.__config__.show_debug_logs do + if state.handler.__config__().show_debug_logs do Logger.debug( "(#{session2}) failed to handle frame_type #{inspect(type)}: #{inspect(reason)}" ) diff --git a/lib/riverside/endpoint_supervisor.ex b/lib/riverside/endpoint_supervisor.ex index f80e4bf..1f10653 100644 --- a/lib/riverside/endpoint_supervisor.ex +++ b/lib/riverside/endpoint_supervisor.ex @@ -17,7 +17,7 @@ defmodule Riverside.EndpointSupervisor do router = Keyword.get(opts, :router, Riverside.Router) scheme = - if Config.get_tls(handler.__config__.tls) do + if Config.get_tls(handler.__config__().tls) do :https else :http @@ -38,10 +38,10 @@ defmodule Riverside.EndpointSupervisor do defp cowboy_opts(router, module) do Config.ensure_module_loaded(module) - port = Config.get_port(module.__config__.port) - extra_opts = Config.get_cowboy_opts(module.__config__.cowboy_opts) - path = module.__config__.path - idle_timeout = module.__config__.idle_timeout + port = Config.get_port(module.__config__().port) + extra_opts = Config.get_cowboy_opts(module.__config__().cowboy_opts) + path = module.__config__().path + idle_timeout = module.__config__().idle_timeout cowboy_opts = [ @@ -51,18 +51,18 @@ defmodule Riverside.EndpointSupervisor do ] ++ extra_opts cowboy_opts = - if module.__config__.reuse_port do + if module.__config__().reuse_port do cowboy_opts ++ [{:raw, 1, 15, <<1, 0, 0, 0>>}] else cowboy_opts end - if Config.get_tls(module.__config__.tls) do + if Config.get_tls(module.__config__().tls) do cowboy_opts ++ [ - otp_app: module.__config__.otp_app, - certfile: Config.get_tls_certfile(module.__config__.tls_certfile), - keyfile: Config.get_tls_keyfile(module.__config__.tls_keyfile) + otp_app: module.__config__().otp_app, + certfile: Config.get_tls_certfile(module.__config__().tls_certfile), + keyfile: Config.get_tls_keyfile(module.__config__().tls_keyfile) ] else cowboy_opts diff --git a/lib/riverside/exception_guard.ex b/lib/riverside/exception_guard.ex index c7df9b5..926faab 100644 --- a/lib/riverside/exception_guard.ex +++ b/lib/riverside/exception_guard.ex @@ -6,12 +6,12 @@ defmodule Riverside.ExceptionGuard do func.() rescue err -> - stacktrace = System.stacktrace() |> Exception.format_stacktrace() + stacktrace = __STACKTRACE__ |> Exception.format_stacktrace() Logger.error("#{log_header} rescued error - #{inspect(err)}, stacktrace - #{stacktrace}") error_resp.() catch error_type, value when error_type in [:throw, :exit] -> - stacktrace = System.stacktrace() |> Exception.format_stacktrace() + stacktrace = __STACKTRACE__ |> Exception.format_stacktrace() Logger.error("#{log_header} caught error - #{inspect(value)}, stacktrace - #{stacktrace}") error_resp.() end diff --git a/lib/riverside/io/random.ex b/lib/riverside/io/random.ex index 9b781e0..342c73c 100644 --- a/lib/riverside/io/random.ex +++ b/lib/riverside/io/random.ex @@ -1,5 +1,5 @@ defmodule Riverside.IO.Random do - @impl_mod Application.get_env(:riverside, :random_module, Riverside.IO.Random.Real) + @impl_mod Application.compile_env(:riverside, :random_module, Riverside.IO.Random.Real) defmodule Behaviour do @callback hex(non_neg_integer) :: String.t() diff --git a/lib/riverside/io/timestamp.ex b/lib/riverside/io/timestamp.ex index 0aca659..5f19226 100644 --- a/lib/riverside/io/timestamp.ex +++ b/lib/riverside/io/timestamp.ex @@ -4,7 +4,7 @@ defmodule Riverside.IO.Timestamp do @callback milli_seconds() :: non_neg_integer end - @impl_mod Application.get_env(:riverside, :timestamp_module, Riverside.IO.Timestamp.Real) + @impl_mod Application.compile_env(:riverside, :timestamp_module, Riverside.IO.Timestamp.Real) @behaviour Behaviour diff --git a/lib/riverside/test/test_client.ex b/lib/riverside/test/test_client.ex index 66d30a6..2f110b6 100644 --- a/lib/riverside/test/test_client.ex +++ b/lib/riverside/test/test_client.ex @@ -93,7 +93,7 @@ defmodule Riverside.Test.TestClient do {:ok, value} {:error, reason} -> - Logger.warn(" failed to decode received message: #{reason}") + Logger.warning(" failed to decode received message: #{reason}") {:error, :bad_format} end else @@ -153,7 +153,7 @@ defmodule Riverside.Test.TestClient do {:noreply, state} {:error, reason} -> - Logger.warn(" failed to format message: #{reason}") + Logger.warning(" failed to format message: #{reason}") {:noreply, state} end end