Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

fix: remove some deprecated stuff #242

Open
wants to merge 1 commit into
base: mistress
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -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

################################################################
Expand All @@ -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,
Expand Down Expand Up @@ -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 ###
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

# For development, we disable any cache and enable
# debugging and code reloading.
Expand Down
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Mix.Config
import Config

config :singyeong, SingyeongWeb.Endpoint,
http: [port: 4001],
Expand Down
14 changes: 7 additions & 7 deletions lib/singyeong/gateway/dispatch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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, []}

Expand All @@ -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, []}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/singyeong/gateway/handler/conn_state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
Expand Down
15 changes: 4 additions & 11 deletions lib/singyeong/message_dispatcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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