From 880076599c0501e168f2cf599571a9cae8f7e25d Mon Sep 17 00:00:00 2001 From: Cynthia Date: Tue, 20 Dec 2022 03:39:22 +0100 Subject: [PATCH] fix: remove some deprecated stuff also remove some unused args and hopefully make build working --- config/config.exs | 10 +++++----- config/dev.exs | 2 +- config/prod.exs | 2 +- config/test.exs | 2 +- lib/singyeong/gateway/dispatch.ex | 14 +++++++------- lib/singyeong/gateway/handler/conn_state.ex | 2 +- lib/singyeong/message_dispatcher.ex | 15 ++++----------- 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/config/config.exs b/config/config.exs index cb0e027..b5d8908 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,9 +1,9 @@ # This file is responsible for configuring your application -# and its dependencies with the aid of the Mix.Config module. +# and its dependencies with the aid of the Config module. # # This configuration file is loaded before any dependency and # is restricted to this project. -use Mix.Config +import Config require Logger ################################################################ @@ -20,7 +20,7 @@ config :singyeong, SingyeongWeb.Endpoint, # Configures Elixir's Logger config :logger, :console, - format: "[$time] $metadata[$level]$levelpad $message\n", + format: "[$time] $metadata[$level] $message\n", metadata: [:file, :line] config :phoenix, :format_encoders, @@ -52,7 +52,7 @@ gossip_topology = # Erlang distribution cookie cookie = - if Mix.env() == :prod do + if config_env() == :prod do System.get_env("COOKIE") || raise """ \n ### ERROR ### @@ -134,7 +134,7 @@ config :singyeong_plugin, # from whatever data is available. payload_module: Singyeong.Gateway.Payload -import_config "#{Mix.env}.exs" +import_config "#{config_env()}.exs" # Import custom configs. This should override EVERYTHING else, and so it must # stay at the very bottom. diff --git a/config/dev.exs b/config/dev.exs index 62c95f2..d590225 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config # For development, we disable any cache and enable # debugging and code reloading. diff --git a/config/prod.exs b/config/prod.exs index 491da3a..83f044a 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config # For production, we often load configuration from external # sources, such as your system environment. For this reason, diff --git a/config/test.exs b/config/test.exs index 9f2f7d2..ff4d4e1 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config config :singyeong, SingyeongWeb.Endpoint, http: [port: 4001], diff --git a/lib/singyeong/gateway/dispatch.ex b/lib/singyeong/gateway/dispatch.ex index 5a5030e..a8e575e 100644 --- a/lib/singyeong/gateway/dispatch.ex +++ b/lib/singyeong/gateway/dispatch.ex @@ -108,8 +108,8 @@ defmodule Singyeong.Gateway.Dispatch do {:ok, []} end - def handle_dispatch(socket, %Payload{t: "SEND", d: data} = payload) do - case send_to_clients(socket, data, false) do + def handle_dispatch(_, %Payload{t: "SEND", d: data} = payload) do + case send_to_clients(data, false) do {:ok, _} -> {:ok, []} @@ -118,8 +118,8 @@ defmodule Singyeong.Gateway.Dispatch do end end - def handle_dispatch(socket, %Payload{t: "BROADCAST", d: data} = payload) do - case send_to_clients(socket, data, true) do + def handle_dispatch(_, %Payload{t: "BROADCAST", d: data} = payload) do + case send_to_clients(data, true) do {:ok, _} -> {:ok, []} @@ -169,14 +169,14 @@ defmodule Singyeong.Gateway.Dispatch do {Map.to_list(clients), client_count} end - def send_to_clients(socket, %Payload.Dispatch{} = data, broadcast?, type \\ nil) do + def send_to_clients(%Payload.Dispatch{} = data, broadcast?, type \\ nil) do # TODO: Relocate this type of code to MessageDispatcher? {possible_clients, client_count} = data.target |> Cluster.query |> get_possible_clients - MessageDispatcher.send_message socket, possible_clients, client_count, data, broadcast?, type + MessageDispatcher.send_message possible_clients, client_count, data, broadcast?, type end defp attempt_queue_dispatch(queue_name) do @@ -247,7 +247,7 @@ defmodule Singyeong.Gateway.Dispatch do :ok = Queue.remove_client queue_name, {next_client.app_id, next_client.client_id} # Queues can only send to a single client, so client_count=1 - MessageDispatcher.send_message nil, [{node, [next_client]}], 1, %Payload.Dispatch{ + MessageDispatcher.send_message [{node, [next_client]}], 1, %Payload.Dispatch{ target: target, nonce: nonce, payload: outgoing_payload diff --git a/lib/singyeong/gateway/handler/conn_state.ex b/lib/singyeong/gateway/handler/conn_state.ex index e5585ed..11b47c6 100644 --- a/lib/singyeong/gateway/handler/conn_state.ex +++ b/lib/singyeong/gateway/handler/conn_state.ex @@ -3,7 +3,7 @@ defmodule Singyeong.Gateway.Handler.ConnState do alias Singyeong.Metadata.Query def send_update(app, mode) do - Dispatch.send_to_clients nil, %Payload.Dispatch{ + Dispatch.send_to_clients %Payload.Dispatch{ target: %Query{ ops: [ {:boolean, :op_eq, "/receive_client_updates", {:value, true}}, diff --git a/lib/singyeong/message_dispatcher.ex b/lib/singyeong/message_dispatcher.ex index be435e4..eaacd89 100644 --- a/lib/singyeong/message_dispatcher.ex +++ b/lib/singyeong/message_dispatcher.ex @@ -11,7 +11,6 @@ defmodule Singyeong.MessageDispatcher do require Logger @spec send_message( - Plug.Socket.t() | nil, # Intiating socket [{node(), [Client.t()]}], # List of clients non_neg_integer(), # Number of clients Payload.Dispatch.t(), # Payload to send @@ -21,20 +20,14 @@ defmodule Singyeong.MessageDispatcher do :: {:ok, :dropped} | {:ok, :sent} | {:error, :no_route} + def send_message(clients, client_count, dispatch, broadcast?, event_type \\ nil) - def send_message(socket, clients, client_count, dispatch, broadcast?, event_type \\ nil) - - def send_message(_, _, 0, %Payload.Dispatch{target: %Query{droppable: true}}, _, nil) do + def send_message(_, 0, %Payload.Dispatch{target: %Query{droppable: true}}, _, nil) do # No matches and droppable, silently drop {:ok, :dropped} end - def send_message(socket, _, 0, %Payload.Dispatch{target: %Query{droppable: false} = target, nonce: nonce}, _, nil) do - # No matches and not droppable, drop with an error - {:error, :no_route} - end - - def send_message(_socket, [_ | _] = clients, client_count, %Payload.Dispatch{ + def send_message([_ | _] = clients, client_count, %Payload.Dispatch{ nonce: nonce, payload: payload, }, broadcast?, type) when client_count > 0 do @@ -64,7 +57,7 @@ defmodule Singyeong.MessageDispatcher do {:ok, :sent} end - def send_message(_, _, 0, _, _, _) do + def send_message(_, 0, _, _, _) do {:error, :no_route} end end