Rename repository

This commit is contained in:
Pim Kunis 2021-09-01 14:43:55 +02:00
parent 4aeb2d2cd8
commit 232df26b85
71 changed files with 348 additions and 345 deletions

2
.gitignore vendored
View file

@ -20,7 +20,7 @@ erl_crash.dump
*.ez *.ez
# Ignore package tarball (built via "mix hex.build"). # Ignore package tarball (built via "mix hex.build").
matrix_server-*.tar architex-*.tar
# Since we are building assets from assets/, # Since we are building assets from assets/,
# we ignore priv/static. You may want to comment # we ignore priv/static. You may want to comment

View file

@ -7,15 +7,15 @@
# General application configuration # General application configuration
use Mix.Config use Mix.Config
config :matrix_server, config :architex,
ecto_repos: [MatrixServer.Repo] ecto_repos: [Architex.Repo]
# Configures the endpoint # Configures the endpoint
config :matrix_server, MatrixServerWeb.Endpoint, config :architex, ArchitexWeb.Endpoint,
url: [host: "localhost"], url: [host: "localhost"],
secret_key_base: "npI0xfNYxf5FoTIdAoc7er0ZvdCJgQFZQ9LcpUFL6dsPXyQllMv45zaQQoO4ZLu1", secret_key_base: "npI0xfNYxf5FoTIdAoc7er0ZvdCJgQFZQ9LcpUFL6dsPXyQllMv45zaQQoO4ZLu1",
render_errors: [view: MatrixServerWeb.ErrorView, accepts: ~w(json), layout: false], render_errors: [view: ArchitexWeb.ErrorView, accepts: ~w(json), layout: false],
pubsub_server: MatrixServer.PubSub, pubsub_server: Architex.PubSub,
live_view: [signing_salt: "6ymoi3Gx"] live_view: [signing_salt: "6ymoi3Gx"]
# Configures Elixir's Logger # Configures Elixir's Logger
@ -26,7 +26,7 @@ config :logger, :console,
# Use Jason for JSON parsing in Phoenix # Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason config :phoenix, :json_library, Jason
config :matrix_server, MatrixServer.Repo, migration_timestamps: [type: :utc_datetime] config :architex, Architex.Repo, migration_timestamps: [type: :utc_datetime]
config :cors_plug, config :cors_plug,
origin: ["*"], origin: ["*"],

View file

@ -4,10 +4,10 @@ hostname = "localhost"
port = System.get_env("PORT") || 4000 port = System.get_env("PORT") || 4000
# Configure your database # Configure your database
config :matrix_server, MatrixServer.Repo, config :architex, Architex.Repo,
username: "matrix_server", username: "architex",
password: "matrix_server", password: "architex",
database: "matrix_server_dev", database: "architex_dev",
hostname: hostname, hostname: hostname,
show_sensitive_data_on_connection_error: true, show_sensitive_data_on_connection_error: true,
pool_size: 10 pool_size: 10
@ -18,7 +18,7 @@ config :matrix_server, MatrixServer.Repo,
# The watchers configuration can be used to run external # The watchers configuration can be used to run external
# watchers to your application. For example, we use it # watchers to your application. For example, we use it
# with webpack to recompile .js and .css sources. # with webpack to recompile .js and .css sources.
config :matrix_server, MatrixServerWeb.Endpoint, config :architex, ArchitexWeb.Endpoint,
http: [port: port], http: [port: port],
debug_errors: true, debug_errors: true,
code_reloader: true, code_reloader: true,
@ -59,5 +59,5 @@ config :phoenix, :stacktrace_depth, 20
# Initialize plugs at runtime for faster development compilation # Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime config :phoenix, :plug_init_mode, :runtime
config :matrix_server, server_name: "#{hostname}:#{port}" config :architex, server_name: "#{hostname}:#{port}"
config :matrix_server, private_key_file: "keys/id_ed25519" config :architex, private_key_file: "keys/id_ed25519"

View file

@ -9,7 +9,7 @@ use Mix.Config
# manifest is generated by the `mix phx.digest` task, # manifest is generated by the `mix phx.digest` task,
# which you should run after static files are built and # which you should run after static files are built and
# before starting your production server. # before starting your production server.
config :matrix_server, MatrixServerWeb.Endpoint, config :architex, ArchitexWeb.Endpoint,
url: [host: "example.com", port: 80], url: [host: "example.com", port: 80],
cache_static_manifest: "priv/static/cache_manifest.json" cache_static_manifest: "priv/static/cache_manifest.json"
@ -21,7 +21,7 @@ config :logger, level: :info
# To get SSL working, you will need to add the `https` key # To get SSL working, you will need to add the `https` key
# to the previous section and set your `:url` port to 443: # to the previous section and set your `:url` port to 443:
# #
# config :matrix_server, MatrixServerWeb.Endpoint, # config :architex, ArchitexWeb.Endpoint,
# ... # ...
# url: [host: "example.com", port: 443], # url: [host: "example.com", port: 443],
# https: [ # https: [
@ -45,7 +45,7 @@ config :logger, level: :info
# We also recommend setting `force_ssl` in your endpoint, ensuring # We also recommend setting `force_ssl` in your endpoint, ensuring
# no data is ever sent via http, always redirecting to https: # no data is ever sent via http, always redirecting to https:
# #
# config :matrix_server, MatrixServerWeb.Endpoint, # config :architex, ArchitexWeb.Endpoint,
# force_ssl: [hsts: true] # force_ssl: [hsts: true]
# #
# Check `Plug.SSL` for all available options in `force_ssl`. # Check `Plug.SSL` for all available options in `force_ssl`.

View file

@ -11,7 +11,7 @@ database_url =
For example: ecto://USER:PASS@HOST/DATABASE For example: ecto://USER:PASS@HOST/DATABASE
""" """
config :matrix_server, MatrixServer.Repo, config :architex, Architex.Repo,
# ssl: true, # ssl: true,
url: database_url, url: database_url,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10") pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
@ -23,7 +23,7 @@ secret_key_base =
You can generate one by calling: mix phx.gen.secret You can generate one by calling: mix phx.gen.secret
""" """
config :matrix_server, MatrixServerWeb.Endpoint, config :architex, ArchitexWeb.Endpoint,
http: [ http: [
port: String.to_integer(System.get_env("PORT") || "4000"), port: String.to_integer(System.get_env("PORT") || "4000"),
transport_options: [socket_opts: [:inet6]] transport_options: [socket_opts: [:inet6]]
@ -35,7 +35,7 @@ config :matrix_server, MatrixServerWeb.Endpoint,
# If you are doing OTP releases, you need to instruct Phoenix # If you are doing OTP releases, you need to instruct Phoenix
# to start each relevant endpoint: # to start each relevant endpoint:
# #
# config :matrix_server, MatrixServerWeb.Endpoint, server: true # config :architex, ArchitexWeb.Endpoint, server: true
# #
# Then you can assemble a release by calling `mix release`. # Then you can assemble a release by calling `mix release`.
# See `mix help release` for more information. # See `mix help release` for more information.

View file

@ -8,21 +8,21 @@ port = System.get_env("PORT") || 4000
# The MIX_TEST_PARTITION environment variable can be used # The MIX_TEST_PARTITION environment variable can be used
# to provide built-in test partitioning in CI environment. # to provide built-in test partitioning in CI environment.
# Run `mix help test` for more information. # Run `mix help test` for more information.
config :matrix_server, MatrixServer.Repo, config :architex, Architex.Repo,
username: "matrix_server", username: "architex",
password: "matrix_server", password: "architex",
database: "matrix_server_test#{System.get_env("MIX_TEST_PARTITION")}", database: "architex_test#{System.get_env("MIX_TEST_PARTITION")}",
hostname: hostname, hostname: hostname,
pool: Ecto.Adapters.SQL.Sandbox pool: Ecto.Adapters.SQL.Sandbox
# We don't run a server during test. If one is required, # We don't run a server during test. If one is required,
# you can enable the server option below. # you can enable the server option below.
config :matrix_server, MatrixServerWeb.Endpoint, config :architex, ArchitexWeb.Endpoint,
http: [port: port], http: [port: port],
server: false server: false
# Print only warnings and errors during test # Print only warnings and errors during test
config :logger, level: :warn config :logger, level: :warn
config :matrix_server, server_name: "#{hostname}:#{port}" config :architex, server_name: "#{hostname}:#{port}"
config :matrix_server, private_key_file: "keys/id_ed25519" config :architex, private_key_file: "keys/id_ed25519"

3
element.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/bash
docker run --rm -d -p ${1-80}:80 vectorim/element-web

View file

@ -1,9 +1,9 @@
defmodule MatrixServer do defmodule Architex do
@moduledoc """ @moduledoc """
Utility functions used throughout the project. Utility functions used throughout the project.
""" """
alias MatrixServer.EncodableMap alias Architex.EncodableMap
@random_string_alphabet Enum.into(?a..?z, []) ++ Enum.into(?A..?Z, []) @random_string_alphabet Enum.into(?a..?z, []) ++ Enum.into(?A..?Z, [])
@ipv6_regex ~r/^\[(?<ip>[^\]]+)\](?<port>:\d{1,5})?$/ @ipv6_regex ~r/^\[(?<ip>[^\]]+)\](?<port>:\d{1,5})?$/
@ -24,7 +24,7 @@ defmodule MatrixServer do
""" """
@spec server_name() :: String.t() @spec server_name() :: String.t()
def server_name do def server_name do
Application.get_env(:matrix_server, :server_name) Application.get_env(:architex, :server_name)
end end
@doc """ @doc """
@ -171,12 +171,12 @@ defmodule MatrixServer do
""" """
@spec add_signature(map(), String.t(), String.t()) :: map() @spec add_signature(map(), String.t(), String.t()) :: map()
def add_signature(object, key_id, sig) when not is_map_key(object, :signatures) do def add_signature(object, key_id, sig) when not is_map_key(object, :signatures) do
Map.put(object, :signatures, %{MatrixServer.server_name() => %{key_id => sig}}) Map.put(object, :signatures, %{Architex.server_name() => %{key_id => sig}})
end end
def add_signature(%{signatures: sigs} = object, key_id, sig) do def add_signature(%{signatures: sigs} = object, key_id, sig) do
new_sigs = new_sigs =
Map.update(sigs, MatrixServer.server_name(), %{key_id => sig}, &Map.put(&1, key_id, sig)) Map.update(sigs, Architex.server_name(), %{key_id => sig}, &Map.put(&1, key_id, sig))
%{object | signatures: new_sigs} %{object | signatures: new_sigs}
end end

View file

@ -0,0 +1,29 @@
defmodule Architex.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
children = [
Architex.Repo,
ArchitexWeb.Telemetry,
{Phoenix.PubSub, name: Architex.PubSub},
ArchitexWeb.Endpoint,
{Registry, keys: :unique, name: Architex.RoomServer.Registry},
{DynamicSupervisor, name: Architex.RoomServer.Supervisor, strategy: :one_for_one},
Architex.KeyServer,
{Finch, name: ArchitexWeb.HTTPClient}
]
Supervisor.start_link(children, name: Architex.Supervisor, strategy: :one_for_one)
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
def config_change(changed, _new, removed) do
ArchitexWeb.Endpoint.config_change(changed, removed)
:ok
end
end

View file

@ -1,7 +1,7 @@
defmodule MatrixServer.Check do defmodule Architex.Check do
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, Account, Room} alias Architex.{Repo, Account, Room}
alias MatrixServerWeb.Client.Request.CreateRoom alias ArchitexWeb.Client.Request.CreateRoom
def create_room do def create_room do
account = Repo.one!(from a in Account, limit: 1) account = Repo.one!(from a in Account, limit: 1)

View file

@ -1,7 +1,7 @@
# https://github.com/michalmuskala/jason/issues/69 # https://github.com/michalmuskala/jason/issues/69
defmodule MatrixServer.EncodableMap do defmodule Architex.EncodableMap do
alias MatrixServer.EncodableMap alias Architex.EncodableMap
alias MatrixServer.Types.{UserId, RoomId, EventId, GroupId, AliasId} alias Architex.Types.{UserId, RoomId, EventId, GroupId, AliasId}
defstruct pairs: [] defstruct pairs: []

View file

@ -1,4 +1,4 @@
defmodule MatrixServer.KeyServer do defmodule Architex.KeyServer do
@moduledoc """ @moduledoc """
A GenServer holding the homeserver's keys, and responsible for signing objects. A GenServer holding the homeserver's keys, and responsible for signing objects.
@ -54,7 +54,7 @@ defmodule MatrixServer.KeyServer do
end end
def handle_call(:get_own_signing_keys, _from, %{public_key: public_key} = state) do def handle_call(:get_own_signing_keys, _from, %{public_key: public_key} = state) do
encoded_key = MatrixServer.encode_unpadded_base64(public_key) encoded_key = Architex.encode_unpadded_base64(public_key)
{:reply, [{@signing_key_id, encoded_key}], state} {:reply, [{@signing_key_id, encoded_key}], state}
end end
@ -64,11 +64,11 @@ defmodule MatrixServer.KeyServer do
defp sign_object(object, private_key) do defp sign_object(object, private_key) do
object = Map.drop(object, [:signatures, :unsigned]) object = Map.drop(object, [:signatures, :unsigned])
with {:ok, json} <- MatrixServer.encode_canonical_json(object) do with {:ok, json} <- Architex.encode_canonical_json(object) do
signature = signature =
json json
|> :enacl.sign_detached(private_key) |> :enacl.sign_detached(private_key)
|> MatrixServer.encode_unpadded_base64() |> Architex.encode_unpadded_base64()
{:ok, signature} {:ok, signature}
end end
@ -78,7 +78,7 @@ defmodule MatrixServer.KeyServer do
@spec read_keys() :: {binary(), binary()} @spec read_keys() :: {binary(), binary()}
defp read_keys do defp read_keys do
raw_priv_key = raw_priv_key =
Application.get_env(:matrix_server, :private_key_file) Application.get_env(:architex, :private_key_file)
|> File.read!() |> File.read!()
"-----BEGIN OPENSSH PRIVATE KEY-----\n" <> rest = raw_priv_key "-----BEGIN OPENSSH PRIVATE KEY-----\n" <> rest = raw_priv_key

5
lib/architex/repo.ex Normal file
View file

@ -0,0 +1,5 @@
defmodule Architex.Repo do
use Ecto.Repo,
otp_app: :architex,
adapter: Ecto.Adapters.Postgres
end

View file

@ -1,4 +1,4 @@
defmodule MatrixServer.RoomServer do defmodule Architex.RoomServer do
@moduledoc """ @moduledoc """
A GenServer to hold and manipulate the state of a Matrix room. A GenServer to hold and manipulate the state of a Matrix room.
@ -13,7 +13,7 @@ defmodule MatrixServer.RoomServer do
import Ecto.Query import Ecto.Query
import Ecto.Changeset import Ecto.Changeset
alias MatrixServer.{ alias Architex.{
Repo, Repo,
Room, Room,
Event, Event,
@ -24,11 +24,11 @@ defmodule MatrixServer.RoomServer do
DeviceTransaction DeviceTransaction
} }
alias MatrixServer.StateResolution.Authorization alias Architex.StateResolution.Authorization
alias MatrixServerWeb.Client.Request.{CreateRoom, Kick, Ban} alias ArchitexWeb.Client.Request.{CreateRoom, Kick, Ban}
@registry MatrixServer.RoomServer.Registry @registry Architex.RoomServer.Registry
@supervisor MatrixServer.RoomServer.Supervisor @supervisor Architex.RoomServer.Supervisor
### Interface ### Interface
@ -215,7 +215,7 @@ defmodule MatrixServer.RoomServer do
result = result =
Enum.any?(state_set, fn Enum.any?(state_set, fn
{{"m.room.member", user_id}, %Event{content: %{"membership" => "join"}}} -> {{"m.room.member", user_id}, %Event{content: %{"membership" => "join"}}} ->
MatrixServer.get_domain(user_id) == domain Architex.get_domain(user_id) == domain
_ -> _ ->
false false
@ -607,19 +607,19 @@ defmodule MatrixServer.RoomServer do
# Update local accounts' room membership if applicable. # Update local accounts' room membership if applicable.
@spec update_joined_rooms(Room.t(), t()) :: JoinedRoom.t() | nil @spec update_joined_rooms(Room.t(), t()) :: JoinedRoom.t() | nil
defp update_joined_rooms(%Room{id: room_id}, state_set) do defp update_joined_rooms(%Room{id: room_id}, state_set) do
server_name = MatrixServer.server_name() server_name = Architex.server_name()
{joined, not_joined} = {joined, not_joined} =
state_set state_set
|> Enum.filter(fn {{type, state_key}, _} -> |> Enum.filter(fn {{type, state_key}, _} ->
type == "m.room.member" and MatrixServer.get_domain(state_key) == server_name type == "m.room.member" and Architex.get_domain(state_key) == server_name
end) end)
|> Enum.split_with(fn {_, %Event{content: %{"membership" => membership}}} -> |> Enum.split_with(fn {_, %Event{content: %{"membership" => membership}}} ->
membership == "join" membership == "join"
end) end)
map_localparts = map_localparts =
&Enum.map(&1, fn {{_, state_key}, _} -> MatrixServer.get_localpart(state_key) end) &Enum.map(&1, fn {{_, state_key}, _} -> Architex.get_localpart(state_key) end)
joined_localparts = map_localparts.(joined) joined_localparts = map_localparts.(joined)
not_joined_localparts = map_localparts.(not_joined) not_joined_localparts = map_localparts.(not_joined)

View file

@ -1,10 +1,10 @@
defmodule MatrixServer.Account do defmodule Architex.Account do
use Ecto.Schema use Ecto.Schema
import Ecto.{Changeset, Query} import Ecto.{Changeset, Query}
alias MatrixServer.{Repo, Account, Device, Room, JoinedRoom} alias Architex.{Repo, Account, Device, Room, JoinedRoom}
alias MatrixServerWeb.Client.Request.{Register, Login} alias ArchitexWeb.Client.Request.{Register, Login}
alias Ecto.{Multi, Changeset} alias Ecto.{Multi, Changeset}
@type t :: %__MODULE__{ @type t :: %__MODULE__{
@ -30,7 +30,7 @@ defmodule MatrixServer.Account do
""" """
@spec available?(String.t()) :: :ok | {:error, :user_in_use | :invalid_username} @spec available?(String.t()) :: :ok | {:error, :user_in_use | :invalid_username}
def available?(localpart) when is_binary(localpart) do def available?(localpart) when is_binary(localpart) do
if Regex.match?(MatrixServer.localpart_regex(), localpart) and if Regex.match?(Architex.localpart_regex(), localpart) and
String.length(localpart) <= localpart_length() do String.length(localpart) <= localpart_length() do
if Repo.one!( if Repo.one!(
Account Account
@ -56,7 +56,7 @@ defmodule MatrixServer.Account do
initial_device_display_name: initial_device_display_name, initial_device_display_name: initial_device_display_name,
password: password password: password
}) do }) do
localpart = username || MatrixServer.random_string(10, ?a..?z) localpart = username || Architex.random_string(10, ?a..?z)
account_params = %{ account_params = %{
localpart: localpart, localpart: localpart,
@ -126,7 +126,7 @@ defmodule MatrixServer.Account do
|> cast(params, [:localpart, :password_hash]) |> cast(params, [:localpart, :password_hash])
|> validate_required([:localpart, :password_hash]) |> validate_required([:localpart, :password_hash])
|> validate_length(:password_hash, max: 60) |> validate_length(:password_hash, max: 60)
|> validate_format(:localpart, MatrixServer.localpart_regex()) |> validate_format(:localpart, Architex.localpart_regex())
|> validate_length(:localpart, max: localpart_length()) |> validate_length(:localpart, max: localpart_length())
|> unique_constraint(:localpart, name: :accounts_localpart_index) |> unique_constraint(:localpart, name: :accounts_localpart_index)
end end
@ -134,7 +134,7 @@ defmodule MatrixServer.Account do
@spec localpart_length :: integer() @spec localpart_length :: integer()
defp localpart_length do defp localpart_length do
# Subtract the "@" and ":" in the MXID. # Subtract the "@" and ":" in the MXID.
@max_mxid_length - 2 - String.length(MatrixServer.server_name()) @max_mxid_length - 2 - String.length(Architex.server_name())
end end
@spec try_get_localpart(String.t()) :: String.t() @spec try_get_localpart(String.t()) :: String.t()
@ -152,6 +152,6 @@ defmodule MatrixServer.Account do
""" """
@spec get_mxid(Account.t()) :: String.t() @spec get_mxid(Account.t()) :: String.t()
def get_mxid(%Account{localpart: localpart}) do def get_mxid(%Account{localpart: localpart}) do
"@" <> localpart <> ":" <> MatrixServer.server_name() "@" <> localpart <> ":" <> Architex.server_name()
end end
end end

View file

@ -1,9 +1,9 @@
defmodule MatrixServer.Alias do defmodule Architex.Alias do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
alias MatrixServer.{Repo, Alias, Room} alias Architex.{Repo, Alias, Room}
alias Ecto.Changeset alias Ecto.Changeset
@primary_key {:alias, :string, []} @primary_key {:alias, :string, []}

View file

@ -1,10 +1,10 @@
defmodule MatrixServer.Device do defmodule Architex.Device do
use Ecto.Schema use Ecto.Schema
import Ecto.{Changeset, Query} import Ecto.{Changeset, Query}
alias MatrixServer.{Account, Device, Repo, DeviceTransaction} alias Architex.{Account, Device, Repo, DeviceTransaction}
alias MatrixServerWeb.Client.Request.Login alias ArchitexWeb.Client.Request.Login
@type t :: %__MODULE__{ @type t :: %__MODULE__{
device_id: String.t(), device_id: String.t(),
@ -30,7 +30,7 @@ defmodule MatrixServer.Device do
end end
def generate_access_token(localpart, device_id) do def generate_access_token(localpart, device_id) do
Phoenix.Token.encrypt(MatrixServerWeb.Endpoint, "access_token", {localpart, device_id}) Phoenix.Token.encrypt(ArchitexWeb.Endpoint, "access_token", {localpart, device_id})
end end
def generate_device_id(localpart) do def generate_device_id(localpart) do

View file

@ -1,7 +1,7 @@
defmodule MatrixServer.DeviceTransaction do defmodule Architex.DeviceTransaction do
use Ecto.Schema use Ecto.Schema
alias MatrixServer.Device alias Architex.Device
@type t :: %__MODULE__{ @type t :: %__MODULE__{
txn_id: String.t(), txn_id: String.t(),

View file

@ -1,10 +1,10 @@
defmodule MatrixServer.Event do defmodule Architex.Event do
use Ecto.Schema use Ecto.Schema
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, Room, Event, Account, EncodableMap, KeyServer} alias Architex.{Repo, Room, Event, Account, EncodableMap, KeyServer}
alias MatrixServer.Types.UserId alias Architex.Types.UserId
# TODO: Could refactor to also always set prev_events, but not necessary. # TODO: Could refactor to also always set prev_events, but not necessary.
@type t :: %__MODULE__{ @type t :: %__MODULE__{
@ -66,7 +66,7 @@ defmodule MatrixServer.Event do
def new(%Room{id: room_id}, %Account{localpart: localpart}) do def new(%Room{id: room_id}, %Account{localpart: localpart}) do
%Event{ %Event{
room_id: room_id, room_id: room_id,
sender: %UserId{localpart: localpart, domain: MatrixServer.server_name()}, sender: %UserId{localpart: localpart, domain: Architex.server_name()},
origin_server_ts: DateTime.utc_now() |> DateTime.to_unix(:millisecond), origin_server_ts: DateTime.utc_now() |> DateTime.to_unix(:millisecond),
prev_events: [], prev_events: [],
auth_events: [] auth_events: []
@ -119,7 +119,7 @@ defmodule MatrixServer.Event do
# Check rules: 1.1, 1.2 # Check rules: 1.1, 1.2
prev_events == [] and prev_events == [] and
auth_events == [] and auth_events == [] and
domain == MatrixServer.get_domain(room_id) domain == Architex.get_domain(room_id)
end end
def prevalidate(%Event{auth_events: auth_event_ids, prev_events: prev_event_ids} = event) do def prevalidate(%Event{auth_events: auth_event_ids, prev_events: prev_event_ids} = event) do
@ -138,7 +138,7 @@ defmodule MatrixServer.Event do
# Check rules: 2.1, 2.2, 3 # Check rules: 2.1, 2.2, 3
length(auth_events) == length(auth_event_ids) and length(auth_events) == length(auth_event_ids) and
length(prev_events) == length(prev_event_ids) and length(prev_events) == length(prev_event_ids) and
not MatrixServer.has_duplicates?(state_pairs) and not Architex.has_duplicates?(state_pairs) and
valid_auth_events?(event, auth_events) and valid_auth_events?(event, auth_events) and
Enum.find_value(state_pairs, false, &(&1 == {"m.room.create", ""})) and Enum.find_value(state_pairs, false, &(&1 == {"m.room.create", ""})) and
do_prevalidate(event, auth_events, prev_events) do_prevalidate(event, auth_events, prev_events)
@ -152,7 +152,7 @@ defmodule MatrixServer.Event do
_ _
) do ) do
# Check rule: 4.2 # Check rule: 4.2
domain == MatrixServer.get_domain(state_key) domain == Architex.get_domain(state_key)
end end
# Rule 5.1 is left to changeset validation. # Rule 5.1 is left to changeset validation.
@ -222,7 +222,7 @@ defmodule MatrixServer.Event do
defp calculate_content_hash(event) do defp calculate_content_hash(event) do
m = m =
event event
|> MatrixServer.to_serializable_map() |> Architex.to_serializable_map()
|> Map.drop([:unsigned, :signature, :hashes]) |> Map.drop([:unsigned, :signature, :hashes])
|> EncodableMap.from_map() |> EncodableMap.from_map()
@ -235,7 +235,7 @@ defmodule MatrixServer.Event do
defp redact(%Event{type: type, content: content} = event) do defp redact(%Event{type: type, content: content} = event) do
redacted_event = redacted_event =
event event
|> MatrixServer.to_serializable_map() |> Architex.to_serializable_map()
|> Map.take([ |> Map.take([
:event_id, :event_id,
:type, :type,
@ -285,11 +285,11 @@ defmodule MatrixServer.Event do
@spec post_process(t()) :: {:ok, t()} | :error @spec post_process(t()) :: {:ok, t()} | :error
def post_process(event) do def post_process(event) do
with {:ok, content_hash} <- calculate_content_hash(event) do with {:ok, content_hash} <- calculate_content_hash(event) do
encoded_hash = MatrixServer.encode_unpadded_base64(content_hash) encoded_hash = Architex.encode_unpadded_base64(content_hash)
event = %Event{event | hashes: %{"sha256" => encoded_hash}} event = %Event{event | hashes: %{"sha256" => encoded_hash}}
with {:ok, sig, key_id} <- KeyServer.sign_object(redact(event)) do with {:ok, sig, key_id} <- KeyServer.sign_object(redact(event)) do
event = %Event{event | signatures: %{MatrixServer.server_name() => %{key_id => sig}}} event = %Event{event | signatures: %{Architex.server_name() => %{key_id => sig}}}
with {:ok, event} <- set_event_id(event) do with {:ok, event} <- set_event_id(event) do
{:ok, event} {:ok, event}
@ -312,7 +312,7 @@ defmodule MatrixServer.Event do
@spec generate_event_id(t()) :: {:ok, String.t()} | {:error, Jason.EncodeError.t()} @spec generate_event_id(t()) :: {:ok, String.t()} | {:error, Jason.EncodeError.t()}
defp generate_event_id(event) do defp generate_event_id(event) do
with {:ok, hash} <- calculate_reference_hash(event) do with {:ok, hash} <- calculate_reference_hash(event) do
{:ok, "$" <> MatrixServer.encode_url_safe_base64(hash)} {:ok, "$" <> Architex.encode_url_safe_base64(hash)}
end end
end end
@ -323,7 +323,7 @@ defmodule MatrixServer.Event do
|> redact() |> redact()
|> Map.drop([:unsigned, :signature, :age_ts]) |> Map.drop([:unsigned, :signature, :age_ts])
with {:ok, json} <- MatrixServer.encode_canonical_json(redacted_event) do with {:ok, json} <- Architex.encode_canonical_json(redacted_event) do
{:ok, :crypto.hash(:sha256, json)} {:ok, :crypto.hash(:sha256, json)}
end end
end end

View file

@ -1,9 +1,9 @@
defmodule MatrixServer.Event.Join do defmodule Architex.Event.Join do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t()) :: Event.t() @spec new(Room.t(), Account.t()) :: Event.t()
def new(room, %Account{localpart: localpart} = sender) do def new(room, %Account{localpart: localpart} = sender) do
mxid = MatrixServer.get_mxid(localpart) mxid = Architex.get_mxid(localpart)
%Event{ %Event{
Event.new(room, sender) Event.new(room, sender)
@ -16,12 +16,12 @@ defmodule MatrixServer.Event.Join do
end end
end end
defmodule MatrixServer.Event.CreateRoom do defmodule Architex.Event.CreateRoom do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t()) :: Event.t() @spec new(Room.t(), Account.t(), String.t()) :: Event.t()
def new(room, %Account{localpart: localpart} = creator, room_version) do def new(room, %Account{localpart: localpart} = creator, room_version) do
mxid = MatrixServer.get_mxid(localpart) mxid = Architex.get_mxid(localpart)
%Event{ %Event{
Event.new(room, creator) Event.new(room, creator)
@ -29,18 +29,18 @@ defmodule MatrixServer.Event.CreateRoom do
state_key: "", state_key: "",
content: %{ content: %{
"creator" => mxid, "creator" => mxid,
"room_version" => room_version || MatrixServer.default_room_version() "room_version" => room_version || Architex.default_room_version()
} }
} }
end end
end end
defmodule MatrixServer.Event.PowerLevels do defmodule Architex.Event.PowerLevels do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t()) :: Event.t() @spec new(Room.t(), Account.t()) :: Event.t()
def new(room, %Account{localpart: localpart} = sender) do def new(room, %Account{localpart: localpart} = sender) do
mxid = MatrixServer.get_mxid(localpart) mxid = Architex.get_mxid(localpart)
%Event{ %Event{
Event.new(room, sender) Event.new(room, sender)
@ -66,8 +66,8 @@ defmodule MatrixServer.Event.PowerLevels do
end end
end end
defmodule MatrixServer.Event.Name do defmodule Architex.Event.Name do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t()) :: Event.t() @spec new(Room.t(), Account.t(), String.t()) :: Event.t()
def new(room, sender, name) do def new(room, sender, name) do
@ -82,8 +82,8 @@ defmodule MatrixServer.Event.Name do
end end
end end
defmodule MatrixServer.Event.Topic do defmodule Architex.Event.Topic do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t()) :: Event.t() @spec new(Room.t(), Account.t(), String.t()) :: Event.t()
def new(room, sender, topic) do def new(room, sender, topic) do
@ -98,8 +98,8 @@ defmodule MatrixServer.Event.Topic do
end end
end end
defmodule MatrixServer.Event.JoinRules do defmodule Architex.Event.JoinRules do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t()) :: Event.t() @spec new(Room.t(), Account.t(), String.t()) :: Event.t()
def new(room, sender, join_rule) do def new(room, sender, join_rule) do
@ -114,8 +114,8 @@ defmodule MatrixServer.Event.JoinRules do
end end
end end
defmodule MatrixServer.Event.HistoryVisibility do defmodule Architex.Event.HistoryVisibility do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t()) :: Event.t() @spec new(Room.t(), Account.t(), String.t()) :: Event.t()
def new(room, sender, history_visibility) do def new(room, sender, history_visibility) do
@ -130,8 +130,8 @@ defmodule MatrixServer.Event.HistoryVisibility do
end end
end end
defmodule MatrixServer.Event.GuestAccess do defmodule Architex.Event.GuestAccess do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t()) :: Event.t() @spec new(Room.t(), Account.t(), String.t()) :: Event.t()
def new(room, sender, guest_access) do def new(room, sender, guest_access) do
@ -146,8 +146,8 @@ defmodule MatrixServer.Event.GuestAccess do
end end
end end
defmodule MatrixServer.Event.Invite do defmodule Architex.Event.Invite do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t()) :: Event.t() @spec new(Room.t(), Account.t(), String.t()) :: Event.t()
def new(room, sender, user_id) do def new(room, sender, user_id) do
@ -162,8 +162,8 @@ defmodule MatrixServer.Event.Invite do
end end
end end
defmodule MatrixServer.Event.Leave do defmodule Architex.Event.Leave do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t()) :: Event.t() @spec new(Room.t(), Account.t()) :: Event.t()
def new(room, sender) do def new(room, sender) do
@ -178,8 +178,8 @@ defmodule MatrixServer.Event.Leave do
end end
end end
defmodule MatrixServer.Event.Kick do defmodule Architex.Event.Kick do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t(), String.t() | nil) :: Event.t() @spec new(Room.t(), Account.t(), String.t(), String.t() | nil) :: Event.t()
def new(room, sender, user_id, reason \\ nil) do def new(room, sender, user_id, reason \\ nil) do
@ -195,8 +195,8 @@ defmodule MatrixServer.Event.Kick do
end end
end end
defmodule MatrixServer.Event.Ban do defmodule Architex.Event.Ban do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t(), String.t() | nil) :: Event.t() @spec new(Room.t(), Account.t(), String.t(), String.t() | nil) :: Event.t()
def new(room, sender, user_id, reason \\ nil) do def new(room, sender, user_id, reason \\ nil) do
@ -212,8 +212,8 @@ defmodule MatrixServer.Event.Ban do
end end
end end
defmodule MatrixServer.Event.Unban do defmodule Architex.Event.Unban do
alias MatrixServer.{Event, Account, Room} alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t()) :: Event.t() @spec new(Room.t(), Account.t(), String.t()) :: Event.t()
def new(room, sender, user_id) do def new(room, sender, user_id) do
%Event{ %Event{

View file

@ -1,7 +1,7 @@
defmodule MatrixServer.JoinedRoom do defmodule Architex.JoinedRoom do
use Ecto.Schema use Ecto.Schema
alias MatrixServer.{Account, Room} alias Architex.{Account, Room}
@type t :: %__MODULE__{ @type t :: %__MODULE__{
account_id: integer(), account_id: integer(),

View file

@ -1,11 +1,11 @@
defmodule MatrixServer.Room do defmodule Architex.Room do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, Room, Event, Alias, RoomServer} alias Architex.{Repo, Room, Event, Alias, RoomServer}
alias MatrixServerWeb.Client.Request.CreateRoom alias ArchitexWeb.Client.Request.CreateRoom
@type t :: %__MODULE__{ @type t :: %__MODULE__{
visibility: :public | :private, visibility: :public | :private,
@ -34,7 +34,7 @@ defmodule MatrixServer.Room do
end end
def generate_room_id do def generate_room_id do
"!" <> MatrixServer.random_string(18) <> ":" <> MatrixServer.server_name() "!" <> Architex.random_string(18) <> ":" <> Architex.server_name()
end end
def update_forward_extremities( def update_forward_extremities(

View file

@ -1,11 +1,11 @@
defmodule MatrixServer.ServerKeyInfo do defmodule Architex.ServerKeyInfo do
use Ecto.Schema use Ecto.Schema
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, ServerKeyInfo, SigningKey} alias Architex.{Repo, ServerKeyInfo, SigningKey}
alias MatrixServerWeb.Federation.HTTPClient alias ArchitexWeb.Federation.HTTPClient
alias MatrixServerWeb.Federation.Request.GetSigningKeys alias ArchitexWeb.Federation.Request.GetSigningKeys
alias Ecto.Multi alias Ecto.Multi
@primary_key {:server_name, :string, []} @primary_key {:server_name, :string, []}
@ -53,7 +53,7 @@ defmodule MatrixServer.ServerKeyInfo do
ski = %ServerKeyInfo{ ski = %ServerKeyInfo{
server_name: server_name, server_name: server_name,
valid_until: valid_until:
MatrixServer.min_datetime(in_a_week, valid_until) |> DateTime.to_unix(:millisecond) Architex.min_datetime(in_a_week, valid_until) |> DateTime.to_unix(:millisecond)
} }
case upsert_multi(server_name, ski, signing_keys) |> Repo.transaction() do case upsert_multi(server_name, ski, signing_keys) |> Repo.transaction() do

View file

@ -1,10 +1,10 @@
defmodule MatrixServer.SigningKey do defmodule Architex.SigningKey do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, SigningKey, ServerKeyInfo} alias Architex.{Repo, SigningKey, ServerKeyInfo}
@primary_key false @primary_key false
schema "signing_keys" do schema "signing_keys" do

View file

@ -1,4 +1,4 @@
defmodule MatrixServer.StateResolution do defmodule Architex.StateResolution do
@moduledoc """ @moduledoc """
Functions for resolving the state of a Matrix room. Functions for resolving the state of a Matrix room.
@ -20,8 +20,8 @@ defmodule MatrixServer.StateResolution do
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, Event, Room} alias Architex.{Repo, Event, Room}
alias MatrixServer.StateResolution.Authorization alias Architex.StateResolution.Authorization
@type state_set :: map() @type state_set :: map()

View file

@ -1,17 +1,17 @@
defmodule MatrixServer.StateResolution.Authorization do defmodule Architex.StateResolution.Authorization do
@moduledoc """ @moduledoc """
Implementation of Matrix event authorization rules for state resolution. Implementation of Matrix event authorization rules for state resolution.
Note that some authorization rules are already checked in Note that some authorization rules are already checked in
`MatrixServer.Event.prevalidate/1` so they are skipped here. `Architex.Event.prevalidate/1` so they are skipped here.
""" """
import MatrixServer.StateResolution import Architex.StateResolution
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, Event} alias Architex.{Repo, Event}
alias MatrixServer.Types.UserId alias Architex.Types.UserId
alias MatrixServer.StateResolution, as: StateRes alias Architex.StateResolution, as: StateRes
@typep action :: :invite | :ban | :redact | :kick | {:event, Event.t()} @typep action :: :invite | :ban | :redact | :kick | {:event, Event.t()}

View file

@ -1,7 +1,7 @@
defmodule MatrixServer.Types.AliasId do defmodule Architex.Types.AliasId do
use Ecto.Type use Ecto.Type
alias MatrixServer.Types.AliasId alias Architex.Types.AliasId
defstruct [:localpart, :domain] defstruct [:localpart, :domain]
@ -17,7 +17,7 @@ defmodule MatrixServer.Types.AliasId do
with "#" <> rest <- s, with "#" <> rest <- s,
[localpart, domain] <- String.split(rest, ":", parts: 2) do [localpart, domain] <- String.split(rest, ":", parts: 2) do
if String.length(localpart) + String.length(domain) + 2 <= 255 and if String.length(localpart) + String.length(domain) + 2 <= 255 and
MatrixServer.valid_domain?(domain) do Architex.valid_domain?(domain) do
{:ok, %AliasId{localpart: localpart, domain: domain}} {:ok, %AliasId{localpart: localpart, domain: domain}}
else else
:error :error

View file

@ -1,7 +1,7 @@
defmodule MatrixServer.Types.EventId do defmodule Architex.Types.EventId do
use Ecto.Type use Ecto.Type
alias MatrixServer.Types.EventId alias Architex.Types.EventId
defstruct [:id] defstruct [:id]

View file

@ -1,7 +1,7 @@
defmodule MatrixServer.Types.GroupId do defmodule Architex.Types.GroupId do
use Ecto.Type use Ecto.Type
alias MatrixServer.Types.GroupId alias Architex.Types.GroupId
defstruct [:localpart, :domain] defstruct [:localpart, :domain]
@ -20,7 +20,7 @@ defmodule MatrixServer.Types.GroupId do
[localpart, domain] <- String.split(rest, ":", parts: 2) do [localpart, domain] <- String.split(rest, ":", parts: 2) do
if String.length(localpart) + String.length(domain) + 2 <= 255 and if String.length(localpart) + String.length(domain) + 2 <= 255 and
Regex.match?(@localpart_regex, localpart) and Regex.match?(@localpart_regex, localpart) and
MatrixServer.valid_domain?(domain) do Architex.valid_domain?(domain) do
{:ok, %GroupId{localpart: localpart, domain: domain}} {:ok, %GroupId{localpart: localpart, domain: domain}}
else else
:error :error

View file

@ -1,7 +1,7 @@
defmodule MatrixServer.Types.RoomId do defmodule Architex.Types.RoomId do
use Ecto.Type use Ecto.Type
alias MatrixServer.Types.RoomId alias Architex.Types.RoomId
defstruct [:localpart, :domain] defstruct [:localpart, :domain]
@ -16,7 +16,7 @@ defmodule MatrixServer.Types.RoomId do
def cast(s) when is_binary(s) do def cast(s) when is_binary(s) do
with "!" <> rest <- s, with "!" <> rest <- s,
[localpart, domain] <- String.split(rest, ":", parts: 2) do [localpart, domain] <- String.split(rest, ":", parts: 2) do
if MatrixServer.valid_domain?(domain) do if Architex.valid_domain?(domain) do
{:ok, %RoomId{localpart: localpart, domain: domain}} {:ok, %RoomId{localpart: localpart, domain: domain}}
else else
:error :error

View file

@ -1,7 +1,7 @@
defmodule MatrixServer.Types.UserId do defmodule Architex.Types.UserId do
use Ecto.Type use Ecto.Type
alias MatrixServer.Types.UserId alias Architex.Types.UserId
@type t :: %__MODULE__{ @type t :: %__MODULE__{
localpart: String.t(), localpart: String.t(),
@ -30,7 +30,7 @@ defmodule MatrixServer.Types.UserId do
with "@" <> rest <- s, with "@" <> rest <- s,
[localpart, domain] <- String.split(rest, ":", parts: 2) do [localpart, domain] <- String.split(rest, ":", parts: 2) do
if String.length(localpart) + String.length(domain) + 2 <= 255 and if String.length(localpart) + String.length(domain) + 2 <= 255 and
Regex.match?(@localpart_regex, localpart) and MatrixServer.valid_domain?(domain) do Regex.match?(@localpart_regex, localpart) and Architex.valid_domain?(domain) do
{:ok, %UserId{localpart: localpart, domain: domain}} {:ok, %UserId{localpart: localpart, domain: domain}}
else else
:error :error

View file

@ -1,12 +1,12 @@
defmodule MatrixServerWeb do defmodule ArchitexWeb do
@moduledoc """ @moduledoc """
The entrypoint for defining your web interface, such The entrypoint for defining your web interface, such
as controllers, views, channels and so on. as controllers, views, channels and so on.
This can be used in your application as: This can be used in your application as:
use MatrixServerWeb, :controller use ArchitexWeb, :controller
use MatrixServerWeb, :view use ArchitexWeb, :view
The definitions below will be executed for every view, The definitions below will be executed for every view,
controller, etc, so keep them short and clean, focused controller, etc, so keep them short and clean, focused
@ -19,18 +19,18 @@ defmodule MatrixServerWeb do
def controller do def controller do
quote do quote do
use Phoenix.Controller, namespace: MatrixServerWeb use Phoenix.Controller, namespace: ArchitexWeb
import Plug.Conn import Plug.Conn
alias MatrixServerWeb.Router.Helpers, as: Routes alias ArchitexWeb.Router.Helpers, as: Routes
end end
end end
def view do def view do
quote do quote do
use Phoenix.View, use Phoenix.View,
root: "lib/matrix_server_web/templates", root: "lib/architex_web/templates",
namespace: MatrixServerWeb namespace: ArchitexWeb
# Import convenience functions from controllers # Import convenience functions from controllers
import Phoenix.Controller, import Phoenix.Controller,
@ -61,8 +61,8 @@ defmodule MatrixServerWeb do
# Import basic rendering functionality (render, render_layout, etc) # Import basic rendering functionality (render, render_layout, etc)
import Phoenix.View import Phoenix.View
import MatrixServerWeb.ErrorHelpers import ArchitexWeb.ErrorHelpers
alias MatrixServerWeb.Router.Helpers, as: Routes alias ArchitexWeb.Router.Helpers, as: Routes
end end
end end

View file

@ -1,8 +1,8 @@
defmodule MatrixServerWeb.Client.Plug.AuthenticateClient do defmodule ArchitexWeb.Client.Plug.AuthenticateClient do
import MatrixServerWeb.Error import ArchitexWeb.Error
import Plug.Conn import Plug.Conn
alias MatrixServer.Account alias Architex.Account
alias Plug.Conn alias Plug.Conn
def init(opts), do: opts def init(opts), do: opts

View file

@ -1,10 +1,10 @@
defmodule MatrixServerWeb.Client.AccountController do defmodule ArchitexWeb.Client.AccountController do
use MatrixServerWeb, :controller use ArchitexWeb, :controller
import MatrixServer import Architex
import MatrixServerWeb.Error import ArchitexWeb.Error
alias MatrixServer.{Account, Repo} alias Architex.{Account, Repo}
alias Plug.Conn alias Plug.Conn
@doc """ @doc """

View file

@ -1,9 +1,9 @@
defmodule MatrixServerWeb.Client.AliasesController do defmodule ArchitexWeb.Client.AliasesController do
use MatrixServerWeb, :controller use ArchitexWeb, :controller
import MatrixServerWeb.Error import ArchitexWeb.Error
alias MatrixServer.Alias alias Architex.Alias
@doc """ @doc """
Create a new mapping from room alias to room ID. Create a new mapping from room alias to room ID.

View file

@ -1,7 +1,7 @@
defmodule MatrixServerWeb.Client.InfoController do defmodule ArchitexWeb.Client.InfoController do
use MatrixServerWeb, :controller use ArchitexWeb, :controller
import MatrixServerWeb.Error import ArchitexWeb.Error
@supported_versions ["r0.6.1"] @supported_versions ["r0.6.1"]

View file

@ -1,11 +1,11 @@
defmodule MatrixServerWeb.Client.LoginController do defmodule ArchitexWeb.Client.LoginController do
use MatrixServerWeb, :controller use ArchitexWeb, :controller
import MatrixServerWeb.Error import ArchitexWeb.Error
import Ecto.Changeset import Ecto.Changeset
alias MatrixServer.{Repo, Account, Device} alias Architex.{Repo, Account, Device}
alias MatrixServerWeb.Client.Request.Login alias ArchitexWeb.Client.Request.Login
alias Ecto.Changeset alias Ecto.Changeset
@login_type "m.login.password" @login_type "m.login.password"
@ -42,7 +42,7 @@ defmodule MatrixServerWeb.Client.LoginController do
{%Account{localpart: localpart}, {%Account{localpart: localpart},
%Device{access_token: access_token, device_id: device_id}}} -> %Device{access_token: access_token, device_id: device_id}}} ->
data = %{ data = %{
user_id: MatrixServer.get_mxid(localpart), user_id: Architex.get_mxid(localpart),
access_token: access_token, access_token: access_token,
device_id: device_id device_id: device_id
} }

View file

@ -1,11 +1,11 @@
defmodule MatrixServerWeb.Client.RegisterController do defmodule ArchitexWeb.Client.RegisterController do
use MatrixServerWeb, :controller use ArchitexWeb, :controller
import MatrixServerWeb.Error import ArchitexWeb.Error
import Ecto.Changeset import Ecto.Changeset
alias MatrixServer.{Repo, Account, Device} alias Architex.{Repo, Account, Device}
alias MatrixServerWeb.Client.Request.Register alias ArchitexWeb.Client.Request.Register
alias Ecto.Changeset alias Ecto.Changeset
@register_type "m.login.dummy" @register_type "m.login.dummy"
@ -26,7 +26,7 @@ defmodule MatrixServerWeb.Client.RegisterController do
account: %Account{localpart: localpart}, account: %Account{localpart: localpart},
device: %Device{device_id: device_id, access_token: access_token} device: %Device{device_id: device_id, access_token: access_token}
}} -> }} ->
data = %{user_id: MatrixServer.get_mxid(localpart)} data = %{user_id: Architex.get_mxid(localpart)}
data = data =
if not inhibit_login do if not inhibit_login do

View file

@ -1,12 +1,12 @@
defmodule MatrixServerWeb.Client.RoomController do defmodule ArchitexWeb.Client.RoomController do
use MatrixServerWeb, :controller use ArchitexWeb, :controller
import MatrixServerWeb.Error import ArchitexWeb.Error
import Ecto.{Changeset, Query} import Ecto.{Changeset, Query}
alias MatrixServer.{Repo, Room, RoomServer} alias Architex.{Repo, Room, RoomServer}
alias MatrixServer.Types.UserId alias Architex.Types.UserId
alias MatrixServerWeb.Client.Request.{CreateRoom, Kick, Ban} alias ArchitexWeb.Client.Request.{CreateRoom, Kick, Ban}
alias Ecto.Changeset alias Ecto.Changeset
alias Plug.Conn alias Plug.Conn

View file

@ -1,10 +1,10 @@
defmodule MatrixServerWeb.Client.RoomDirectoryController do defmodule ArchitexWeb.Client.RoomDirectoryController do
use MatrixServerWeb, :controller use ArchitexWeb, :controller
import MatrixServerWeb.Error import ArchitexWeb.Error
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, Room, RoomServer} alias Architex.{Repo, Room, RoomServer}
alias Plug.Conn alias Plug.Conn
@doc """ @doc """

View file

@ -1,5 +1,5 @@
defmodule MatrixServerWeb.Client.Request.Ban do defmodule ArchitexWeb.Client.Request.Ban do
use MatrixServerWeb.Request use ArchitexWeb.Request
@type t :: %__MODULE__{ @type t :: %__MODULE__{
user_id: String.t(), user_id: String.t(),

View file

@ -1,4 +1,4 @@
defmodule MatrixServerWeb.Client.Request.CreateRoom do defmodule ArchitexWeb.Client.Request.CreateRoom do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset

View file

@ -1,5 +1,5 @@
defmodule MatrixServerWeb.Client.Request.Kick do defmodule ArchitexWeb.Client.Request.Kick do
use MatrixServerWeb.Request use ArchitexWeb.Request
@type t :: %__MODULE__{ @type t :: %__MODULE__{
user_id: String.t(), user_id: String.t(),

View file

@ -1,4 +1,4 @@
defmodule MatrixServerWeb.Client.Request.Login do defmodule ArchitexWeb.Client.Request.Login do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset

View file

@ -1,4 +1,4 @@
defmodule MatrixServerWeb.Client.Request.Register do defmodule ArchitexWeb.Client.Request.Register do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset

View file

@ -1,12 +1,12 @@
defmodule MatrixServerWeb.Endpoint do defmodule ArchitexWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :matrix_server use Phoenix.Endpoint, otp_app: :architex
# The session will be stored in the cookie and signed, # The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with. # this means its contents can be read but not tampered with.
# Set :encryption_salt if you would also like to encrypt it. # Set :encryption_salt if you would also like to encrypt it.
@session_options [ @session_options [
store: :cookie, store: :cookie,
key: "_matrix_server_key", key: "_architex_key",
signing_salt: "IGPHtnAo" signing_salt: "IGPHtnAo"
] ]
@ -16,7 +16,7 @@ defmodule MatrixServerWeb.Endpoint do
# when deploying your static files in production. # when deploying your static files in production.
plug Plug.Static, plug Plug.Static,
at: "/", at: "/",
from: :matrix_server, from: :architex,
gzip: false, gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt) only: ~w(css fonts images js favicon.ico robots.txt)
@ -24,7 +24,7 @@ defmodule MatrixServerWeb.Endpoint do
# :code_reloader configuration of your endpoint. # :code_reloader configuration of your endpoint.
if code_reloading? do if code_reloading? do
plug Phoenix.CodeReloader plug Phoenix.CodeReloader
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :matrix_server plug Phoenix.Ecto.CheckRepoStatus, otp_app: :architex
end end
plug Plug.RequestId plug Plug.RequestId
@ -40,5 +40,5 @@ defmodule MatrixServerWeb.Endpoint do
plug Plug.Session, @session_options plug Plug.Session, @session_options
plug CORSPlug plug CORSPlug
plug MatrixServerWeb.Router plug ArchitexWeb.Router
end end

View file

@ -1,4 +1,4 @@
defmodule MatrixServerWeb.Error do defmodule ArchitexWeb.Error do
import Plug.Conn import Plug.Conn
import Phoenix.Controller, only: [json: 2] import Phoenix.Controller, only: [json: 2]

View file

@ -1,7 +1,7 @@
defmodule MatrixServerWeb.Federation.AuthenticateServer do defmodule ArchitexWeb.Federation.AuthenticateServer do
import MatrixServerWeb.Error import ArchitexWeb.Error
alias MatrixServer.{SigningKey, ServerKeyInfo} alias Architex.{SigningKey, ServerKeyInfo}
@auth_header_regex ~r/^X-Matrix origin=(?<origin>.*),key="(?<key>.*)",sig="(?<sig>.*)"$/ @auth_header_regex ~r/^X-Matrix origin=(?<origin>.*),key="(?<key>.*)",sig="(?<sig>.*)"$/
@ -25,7 +25,7 @@ defmodule MatrixServerWeb.Federation.AuthenticateServer do
object_to_sign = %{ object_to_sign = %{
uri: uri, uri: uri,
method: method, method: method,
destination: MatrixServer.server_name() destination: Architex.server_name()
} }
object_to_sign = object_to_sign =
@ -43,13 +43,13 @@ defmodule MatrixServerWeb.Federation.AuthenticateServer do
|> Enum.find(:error, fn {origin, _, sig} -> |> Enum.find(:error, fn {origin, _, sig} ->
object = object_fun.(origin) object = object_fun.(origin)
with {:ok, raw_sig} <- MatrixServer.decode_base64(sig), with {:ok, raw_sig} <- Architex.decode_base64(sig),
{:ok, encoded_object} <- MatrixServer.encode_canonical_json(object), {:ok, encoded_object} <- Architex.encode_canonical_json(object),
{:ok, %ServerKeyInfo{signing_keys: keys}} <- {:ok, %ServerKeyInfo{signing_keys: keys}} <-
ServerKeyInfo.with_fresh_signing_keys(origin) do ServerKeyInfo.with_fresh_signing_keys(origin) do
Enum.find_value(keys, false, fn %SigningKey{signing_key: signing_key} -> Enum.find_value(keys, false, fn %SigningKey{signing_key: signing_key} ->
with {:ok, decoded_key} <- MatrixServer.decode_base64(signing_key) do with {:ok, decoded_key} <- Architex.decode_base64(signing_key) do
MatrixServer.sign_verify(raw_sig, encoded_object, decoded_key) Architex.sign_verify(raw_sig, encoded_object, decoded_key)
else else
_ -> false _ -> false
end end
@ -81,7 +81,7 @@ defmodule MatrixServerWeb.Federation.AuthenticateServer do
action = action_name(conn) action = action_name(conn)
if action not in unquote(except) do if action not in unquote(except) do
case MatrixServerWeb.Federation.AuthenticateServer.authenticate(conn) do case ArchitexWeb.Federation.AuthenticateServer.authenticate(conn) do
{origin, _key, _sig} -> {origin, _key, _sig} ->
conn = Plug.Conn.assign(conn, :origin, origin) conn = Plug.Conn.assign(conn, :origin, origin)
apply(__MODULE__, action, [conn, conn.params]) apply(__MODULE__, action, [conn, conn.params])

View file

@ -1,12 +1,12 @@
defmodule MatrixServerWeb.Federation.EventController do defmodule ArchitexWeb.Federation.EventController do
use MatrixServerWeb, :controller use ArchitexWeb, :controller
use MatrixServerWeb.Federation.AuthenticateServer use ArchitexWeb.Federation.AuthenticateServer
import MatrixServerWeb.Error import ArchitexWeb.Error
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, Event, RoomServer} alias Architex.{Repo, Event, RoomServer}
alias MatrixServerWeb.Federation.Transaction alias ArchitexWeb.Federation.Transaction
@doc """ @doc """
Retrieves a single event. Retrieves a single event.

View file

@ -1,9 +1,9 @@
defmodule MatrixServerWeb.Federation.KeyController do defmodule ArchitexWeb.Federation.KeyController do
use MatrixServerWeb, :controller use ArchitexWeb, :controller
import MatrixServerWeb.Error import ArchitexWeb.Error
alias MatrixServer.KeyServer alias Architex.KeyServer
@doc """ @doc """
Gets the homeserver's published signing keys. Gets the homeserver's published signing keys.
@ -22,7 +22,7 @@ defmodule MatrixServerWeb.Federation.KeyController do
valid_until = DateTime.utc_now() |> DateTime.add(60 * 60 * 24 * 30, :second) valid_until = DateTime.utc_now() |> DateTime.add(60 * 60 * 24 * 30, :second)
data = %{ data = %{
server_name: MatrixServer.server_name(), server_name: Architex.server_name(),
verify_keys: keys, verify_keys: keys,
old_verify_keys: %{}, old_verify_keys: %{},
valid_until_ts: DateTime.to_unix(valid_until, :millisecond) valid_until_ts: DateTime.to_unix(valid_until, :millisecond)
@ -30,7 +30,7 @@ defmodule MatrixServerWeb.Federation.KeyController do
case KeyServer.sign_object(data) do case KeyServer.sign_object(data) do
{:ok, sig, key_id} -> {:ok, sig, key_id} ->
signed_data = MatrixServer.add_signature(data, key_id, sig) signed_data = Architex.add_signature(data, key_id, sig)
conn conn
|> put_status(200) |> put_status(200)

View file

@ -1,12 +1,12 @@
defmodule MatrixServerWeb.Federation.QueryController do defmodule ArchitexWeb.Federation.QueryController do
use MatrixServerWeb, :controller use ArchitexWeb, :controller
use MatrixServerWeb.Federation.AuthenticateServer use ArchitexWeb.Federation.AuthenticateServer
import MatrixServerWeb.Error import ArchitexWeb.Error
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, Account} alias Architex.{Repo, Account}
alias MatrixServer.Types.UserId alias Architex.Types.UserId
defmodule ProfileRequest do defmodule ProfileRequest do
use Ecto.Schema use Ecto.Schema
@ -40,7 +40,7 @@ defmodule MatrixServerWeb.Federation.QueryController do
def profile(conn, params) do def profile(conn, params) do
with {:ok, %ProfileRequest{user_id: %UserId{localpart: localpart, domain: domain}}} <- with {:ok, %ProfileRequest{user_id: %UserId{localpart: localpart, domain: domain}}} <-
ProfileRequest.validate(params) do ProfileRequest.validate(params) do
if domain == MatrixServer.server_name() do if domain == Architex.server_name() do
case Repo.one(from a in Account, where: a.localpart == ^localpart) do case Repo.one(from a in Account, where: a.localpart == ^localpart) do
%Account{} -> %Account{} ->
# TODO: Return displayname and avatar_url when we implement them. # TODO: Return displayname and avatar_url when we implement them.

View file

@ -1,15 +1,15 @@
defmodule MatrixServerWeb.Federation.HTTPClient do defmodule ArchitexWeb.Federation.HTTPClient do
use Tesla use Tesla
alias MatrixServerWeb.Endpoint alias ArchitexWeb.Endpoint
alias MatrixServerWeb.Federation.Request.GetSigningKeys alias ArchitexWeb.Federation.Request.GetSigningKeys
alias MatrixServerWeb.Federation.Middleware.SignRequest alias ArchitexWeb.Federation.Middleware.SignRequest
alias MatrixServerWeb.Router.Helpers, as: RouteHelpers alias ArchitexWeb.Router.Helpers, as: RouteHelpers
# TODO: Maybe create database-backed homeserver struct to pass to client function. # TODO: Maybe create database-backed homeserver struct to pass to client function.
# TODO: Fix error propagation. # TODO: Fix error propagation.
@adapter {Tesla.Adapter.Finch, name: MatrixServerWeb.HTTPClient} @adapter {Tesla.Adapter.Finch, name: ArchitexWeb.HTTPClient}
def client(server_name) do def client(server_name) do
Tesla.client( Tesla.client(
@ -29,17 +29,17 @@ defmodule MatrixServerWeb.Federation.HTTPClient do
with {:ok, with {:ok,
%GetSigningKeys{server_name: server_name, verify_keys: verify_keys, signatures: sigs} = %GetSigningKeys{server_name: server_name, verify_keys: verify_keys, signatures: sigs} =
response} <- tesla_request(:get, client, path, GetSigningKeys), response} <- tesla_request(:get, client, path, GetSigningKeys),
serializable_response <- MatrixServer.to_serializable_map(response), serializable_response <- Architex.to_serializable_map(response),
serializable_response <- Map.drop(serializable_response, [:signatures]), serializable_response <- Map.drop(serializable_response, [:signatures]),
{:ok, encoded_body} <- MatrixServer.encode_canonical_json(serializable_response), {:ok, encoded_body} <- Architex.encode_canonical_json(serializable_response),
server_sigs when not is_nil(server_sigs) <- sigs[server_name] do server_sigs when not is_nil(server_sigs) <- sigs[server_name] do
# For each verify key, check if there is a matching signature. # For each verify key, check if there is a matching signature.
# If not, invalidate the whole response. # If not, invalidate the whole response.
Enum.all?(verify_keys, fn {key_id, %{"key" => key}} -> Enum.all?(verify_keys, fn {key_id, %{"key" => key}} ->
with true <- Map.has_key?(server_sigs, key_id), with true <- Map.has_key?(server_sigs, key_id),
{:ok, decoded_key} <- MatrixServer.decode_base64(key), {:ok, decoded_key} <- Architex.decode_base64(key),
{:ok, decoded_sig} <- MatrixServer.decode_base64(server_sigs[key_id]) do {:ok, decoded_sig} <- Architex.decode_base64(server_sigs[key_id]) do
MatrixServer.sign_verify(decoded_sig, encoded_body, decoded_key) Architex.sign_verify(decoded_sig, encoded_body, decoded_key)
else else
_ -> false _ -> false
end end

View file

@ -1,4 +1,4 @@
defmodule MatrixServerWeb.Federation.Request.GetSigningKeys do defmodule ArchitexWeb.Federation.Request.GetSigningKeys do
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
@ -17,12 +17,12 @@ defmodule MatrixServerWeb.Federation.Request.GetSigningKeys do
%__MODULE__{} %__MODULE__{}
|> cast(params, [:server_name, :verify_keys, :old_verify_keys, :signatures, :valid_until_ts]) |> cast(params, [:server_name, :verify_keys, :old_verify_keys, :signatures, :valid_until_ts])
|> validate_required([:server_name, :verify_keys, :valid_until_ts]) |> validate_required([:server_name, :verify_keys, :valid_until_ts])
|> MatrixServer.validate_change_simple(:verify_keys, fn map -> |> Architex.validate_change_simple(:verify_keys, fn map ->
Enum.all?(map, fn {_, map} -> Enum.all?(map, fn {_, map} ->
is_map_key(map, "key") is_map_key(map, "key")
end) end)
end) end)
|> MatrixServer.validate_change_simple(:old_verify_keys, fn map -> |> Architex.validate_change_simple(:old_verify_keys, fn map ->
Enum.all?(map, fn Enum.all?(map, fn
{_, %{"key" => key, "expired_ts" => expired_ts}} {_, %{"key" => key, "expired_ts" => expired_ts}}
when is_binary(key) and is_integer(expired_ts) -> when is_binary(key) and is_integer(expired_ts) ->

View file

@ -1,4 +1,4 @@
defmodule MatrixServerWeb.Federation.Middleware.SignRequest do defmodule ArchitexWeb.Federation.Middleware.SignRequest do
@behaviour Tesla.Middleware @behaviour Tesla.Middleware
def call(%Tesla.Env{opts: opts} = env, next, _opts) do def call(%Tesla.Env{opts: opts} = env, next, _opts) do
@ -13,7 +13,7 @@ defmodule MatrixServerWeb.Federation.Middleware.SignRequest do
defp sign_request(env, false), do: env defp sign_request(env, false), do: env
defp sign_request(%Tesla.Env{method: method, url: path, opts: opts, body: body} = env, true) do defp sign_request(%Tesla.Env{method: method, url: path, opts: opts, body: body} = env, true) do
origin = MatrixServer.server_name() origin = Architex.server_name()
object_to_sign = %{ object_to_sign = %{
method: Atom.to_string(method) |> String.upcase(), method: Atom.to_string(method) |> String.upcase(),
@ -25,7 +25,7 @@ defmodule MatrixServerWeb.Federation.Middleware.SignRequest do
object_to_sign = object_to_sign =
if not is_nil(body), do: Map.put(object_to_sign, :content, body), else: object_to_sign if not is_nil(body), do: Map.put(object_to_sign, :content, body), else: object_to_sign
with {:ok, sig, key_id} <- MatrixServer.KeyServer.sign_object(object_to_sign) do with {:ok, sig, key_id} <- Architex.KeyServer.sign_object(object_to_sign) do
sigs = %{origin => %{key_id => sig}} sigs = %{origin => %{key_id => sig}}
auth_headers = create_signature_authorization_headers(sigs, origin) auth_headers = create_signature_authorization_headers(sigs, origin)

View file

@ -1,6 +1,6 @@
defmodule MatrixServerWeb.Federation.Transaction do defmodule ArchitexWeb.Federation.Transaction do
alias MatrixServer.Event alias Architex.Event
alias MatrixServerWeb.Federation.Transaction alias ArchitexWeb.Federation.Transaction
# TODO # TODO
@type edu :: any() @type edu :: any()
@ -27,9 +27,9 @@ defmodule MatrixServerWeb.Federation.Transaction do
@spec new([Event.t()], [edu()] | nil) :: t() @spec new([Event.t()], [edu()] | nil) :: t()
def new(pdu_events, edus \\ nil) do def new(pdu_events, edus \\ nil) do
%Transaction{ %Transaction{
origin: MatrixServer.server_name(), origin: Architex.server_name(),
origin_server_ts: System.os_time(:millisecond), origin_server_ts: System.os_time(:millisecond),
pdus: Enum.map(pdu_events, &MatrixServer.to_serializable_map/1), pdus: Enum.map(pdu_events, &Architex.to_serializable_map/1),
edus: edus edus: edus
} }
end end

View file

@ -1,4 +1,4 @@
defmodule MatrixServerWeb.Request do defmodule ArchitexWeb.Request do
import Ecto.Changeset import Ecto.Changeset
alias Ecto.Changeset alias Ecto.Changeset
@ -19,7 +19,7 @@ defmodule MatrixServerWeb.Request do
@spec parse(map()) :: {:ok, struct()} | {:error, Changeset.t()} @spec parse(map()) :: {:ok, struct()} | {:error, Changeset.t()}
def parse(params) do def parse(params) do
MatrixServerWeb.Request.parse(__MODULE__, params) ArchitexWeb.Request.parse(__MODULE__, params)
end end
end end
end end

View file

@ -1,7 +1,7 @@
defmodule MatrixServerWeb.Router do defmodule ArchitexWeb.Router do
use MatrixServerWeb, :router use ArchitexWeb, :router
alias MatrixServerWeb.Client.Plug.AuthenticateClient alias ArchitexWeb.Client.Plug.AuthenticateClient
# TODO: might be able to handle malformed JSON with custom body reader: # TODO: might be able to handle malformed JSON with custom body reader:
# https://elixirforum.com/t/write-malformed-json-in-the-body-plug/30578/13 # https://elixirforum.com/t/write-malformed-json-in-the-body-plug/30578/13
@ -22,7 +22,7 @@ defmodule MatrixServerWeb.Router do
end end
# Public client endpoint. # Public client endpoint.
scope "/_matrix/client", MatrixServerWeb.Client do scope "/_matrix/client", ArchitexWeb.Client do
pipe_through :public pipe_through :public
scope "/r0" do scope "/r0" do
@ -37,14 +37,14 @@ defmodule MatrixServerWeb.Router do
end end
# Public federation endpoint. # Public federation endpoint.
scope "/_matrix", MatrixServerWeb.Federation do scope "/_matrix", ArchitexWeb.Federation do
scope "/key/v2" do scope "/key/v2" do
get "/server", KeyController, :get_signing_keys get "/server", KeyController, :get_signing_keys
end end
end end
# Authenticated client endpoint. # Authenticated client endpoint.
scope "/_matrix/client", MatrixServerWeb.Client do scope "/_matrix/client", ArchitexWeb.Client do
pipe_through :authenticate_client pipe_through :authenticate_client
scope "/r0" do scope "/r0" do
@ -72,7 +72,7 @@ defmodule MatrixServerWeb.Router do
end end
# Authenticated federation endpoint. # Authenticated federation endpoint.
scope "/_matrix/federation", MatrixServerWeb.Federation do scope "/_matrix/federation", ArchitexWeb.Federation do
pipe_through :authenticate_server pipe_through :authenticate_server
scope "/v1" do scope "/v1" do
@ -83,7 +83,7 @@ defmodule MatrixServerWeb.Router do
end end
end end
scope "/", MatrixServerWeb.Client do scope "/", ArchitexWeb.Client do
match :*, "/*path", InfoController, :unrecognized match :*, "/*path", InfoController, :unrecognized
end end
end end

View file

@ -1,4 +1,4 @@
defmodule MatrixServerWeb.Telemetry do defmodule ArchitexWeb.Telemetry do
use Supervisor use Supervisor
import Telemetry.Metrics import Telemetry.Metrics
@ -31,11 +31,11 @@ defmodule MatrixServerWeb.Telemetry do
), ),
# Database Metrics # Database Metrics
summary("matrix_server.repo.query.total_time", unit: {:native, :millisecond}), summary("architex.repo.query.total_time", unit: {:native, :millisecond}),
summary("matrix_server.repo.query.decode_time", unit: {:native, :millisecond}), summary("architex.repo.query.decode_time", unit: {:native, :millisecond}),
summary("matrix_server.repo.query.query_time", unit: {:native, :millisecond}), summary("architex.repo.query.query_time", unit: {:native, :millisecond}),
summary("matrix_server.repo.query.queue_time", unit: {:native, :millisecond}), summary("architex.repo.query.queue_time", unit: {:native, :millisecond}),
summary("matrix_server.repo.query.idle_time", unit: {:native, :millisecond}), summary("architex.repo.query.idle_time", unit: {:native, :millisecond}),
# VM Metrics # VM Metrics
summary("vm.memory.total", unit: {:byte, :kilobyte}), summary("vm.memory.total", unit: {:byte, :kilobyte}),
@ -49,7 +49,7 @@ defmodule MatrixServerWeb.Telemetry do
[ [
# A module, function and arguments to be invoked periodically. # A module, function and arguments to be invoked periodically.
# This function must call :telemetry.execute/3 and a metric must be added above. # This function must call :telemetry.execute/3 and a metric must be added above.
# {MatrixServerWeb, :count_users, []} # {ArchitexWeb, :count_users, []}
] ]
end end
end end

View file

@ -1,29 +0,0 @@
defmodule MatrixServer.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
def start(_type, _args) do
children = [
MatrixServer.Repo,
MatrixServerWeb.Telemetry,
{Phoenix.PubSub, name: MatrixServer.PubSub},
MatrixServerWeb.Endpoint,
{Registry, keys: :unique, name: MatrixServer.RoomServer.Registry},
{DynamicSupervisor, name: MatrixServer.RoomServer.Supervisor, strategy: :one_for_one},
MatrixServer.KeyServer,
{Finch, name: MatrixServerWeb.HTTPClient}
]
Supervisor.start_link(children, name: MatrixServer.Supervisor, strategy: :one_for_one)
end
# Tell Phoenix to update the endpoint configuration
# whenever the application is updated.
def config_change(changed, _new, removed) do
MatrixServerWeb.Endpoint.config_change(changed, removed)
:ok
end
end

View file

@ -1,5 +0,0 @@
defmodule MatrixServer.Repo do
use Ecto.Repo,
otp_app: :matrix_server,
adapter: Ecto.Adapters.Postgres
end

View file

@ -1,9 +1,9 @@
defmodule MatrixServer.MixProject do defmodule Architex.MixProject do
use Mix.Project use Mix.Project
def project do def project do
[ [
app: :matrix_server, app: :architex,
version: "0.1.0", version: "0.1.0",
elixir: "~> 1.7", elixir: "~> 1.7",
elixirc_paths: elixirc_paths(Mix.env()), elixirc_paths: elixirc_paths(Mix.env()),
@ -23,7 +23,7 @@ defmodule MatrixServer.MixProject do
# Type `mix help compile.app` for more information. # Type `mix help compile.app` for more information.
def application do def application do
[ [
mod: {MatrixServer.Application, []}, mod: {Architex.Application, []},
extra_applications: [:logger, :runtime_tools] extra_applications: [:logger, :runtime_tools]
] ]
end end

View file

@ -1,4 +1,4 @@
defmodule MatrixServer.Repo.Migrations.CreateInitialTables do defmodule Architex.Repo.Migrations.CreateInitialTables do
use Ecto.Migration use Ecto.Migration
def change do def change do

View file

@ -1,4 +1,4 @@
alias MatrixServer.{Repo, Account} alias Architex.{Repo, Account}
account = account =
Repo.insert!(%Account{ Repo.insert!(%Account{

View file

@ -1,2 +1,2 @@
#!/bin/bash #!/bin/bash
sudo -u postgres psql -d matrix_server_dev sudo -u postgres psql -d architex_dev

View file

@ -1,5 +1,5 @@
defmodule MatrixServerWeb.InfoControllerTest do defmodule ArchitexWeb.InfoControllerTest do
use MatrixServerWeb.ConnCase use ArchitexWeb.ConnCase
test "versions endpoint returns a list of supported Matrix spec versions", %{conn: conn} do test "versions endpoint returns a list of supported Matrix spec versions", %{conn: conn} do
conn = get(conn, Routes.info_path(conn, :versions)) conn = get(conn, Routes.info_path(conn, :versions))
@ -9,7 +9,7 @@ defmodule MatrixServerWeb.InfoControllerTest do
end end
test "unrecognized route renders M_UNRECOGNIZED error", %{conn: conn} do test "unrecognized route renders M_UNRECOGNIZED error", %{conn: conn} do
conn = get(conn, MatrixServerWeb.Endpoint.url() <> "/sneed") conn = get(conn, ArchitexWeb.Endpoint.url() <> "/sneed")
assert %{"errcode" => "M_UNRECOGNIZED"} = json_response(conn, 400) assert %{"errcode" => "M_UNRECOGNIZED"} = json_response(conn, 400)
end end

View file

@ -1,8 +1,8 @@
defmodule MatrixServerWeb.LoginControllerTest do defmodule ArchitexWeb.LoginControllerTest do
use MatrixServerWeb.ConnCase use ArchitexWeb.ConnCase
alias MatrixServer.Factory alias Architex.Factory
alias MatrixServerWeb.Endpoint alias ArchitexWeb.Endpoint
@basic_params %{ @basic_params %{
"type" => "m.login.password", "type" => "m.login.password",
@ -31,7 +31,7 @@ defmodule MatrixServerWeb.LoginControllerTest do
recycle(conn) recycle(conn)
|> post_json(Routes.login_path(Endpoint, :login), %{ |> post_json(Routes.login_path(Endpoint, :login), %{
@basic_params @basic_params
| "identifier" => %{"type" => "m.id.user", "user" => MatrixServer.get_mxid("sneed")} | "identifier" => %{"type" => "m.id.user", "user" => Architex.get_mxid("sneed")}
}) })
assert %{"user_id" => _, "access_token" => _, "device_id" => _} = json_response(conn, 200) assert %{"user_id" => _, "access_token" => _, "device_id" => _} = json_response(conn, 200)

View file

@ -1,10 +1,10 @@
defmodule MatrixServerWeb.RegisterControllerTest do defmodule ArchitexWeb.RegisterControllerTest do
use MatrixServerWeb.ConnCase use ArchitexWeb.ConnCase
import Ecto.Query import Ecto.Query
alias MatrixServer.{Repo, Device, Factory} alias Architex.{Repo, Device, Factory}
alias MatrixServerWeb.Endpoint alias ArchitexWeb.Endpoint
@basic_params %{ @basic_params %{
"username" => "user", "username" => "user",
@ -22,7 +22,7 @@ defmodule MatrixServerWeb.RegisterControllerTest do
test "registers account with minimal information", %{conn: conn} do test "registers account with minimal information", %{conn: conn} do
conn = post_json(conn, Routes.register_path(Endpoint, :register), @basic_params) conn = post_json(conn, Routes.register_path(Endpoint, :register), @basic_params)
user_id = MatrixServer.get_mxid("user") user_id = Architex.get_mxid("user")
assert %{"access_token" => _, "device_id" => _, "user_id" => ^user_id} = assert %{"access_token" => _, "device_id" => _, "user_id" => ^user_id} =
json_response(conn, 200) json_response(conn, 200)

View file

@ -1,4 +1,4 @@
defmodule MatrixServerWeb.ConnCase do defmodule ArchitexWeb.ConnCase do
@moduledoc """ @moduledoc """
This module defines the test case to be used by This module defines the test case to be used by
tests that require setting up a connection. tests that require setting up a connection.
@ -11,7 +11,7 @@ defmodule MatrixServerWeb.ConnCase do
we enable the SQL sandbox, so changes done to the database we enable the SQL sandbox, so changes done to the database
are reverted at the end of every test. If you are using are reverted at the end of every test. If you are using
PostgreSQL, you can even run database tests asynchronously PostgreSQL, you can even run database tests asynchronously
by setting `use MatrixServerWeb.ConnCase, async: true`, although by setting `use ArchitexWeb.ConnCase, async: true`, although
this option is not recommended for other databases. this option is not recommended for other databases.
""" """
@ -22,20 +22,20 @@ defmodule MatrixServerWeb.ConnCase do
# Import conveniences for testing with connections # Import conveniences for testing with connections
import Plug.Conn import Plug.Conn
import Phoenix.ConnTest import Phoenix.ConnTest
import MatrixServerWeb.ConnCase import ArchitexWeb.ConnCase
alias MatrixServerWeb.Router.Helpers, as: Routes alias ArchitexWeb.Router.Helpers, as: Routes
# The default endpoint for testing # The default endpoint for testing
@endpoint MatrixServerWeb.Endpoint @endpoint ArchitexWeb.Endpoint
end end
end end
setup tags do setup tags do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(MatrixServer.Repo) :ok = Ecto.Adapters.SQL.Sandbox.checkout(Architex.Repo)
unless tags[:async] do unless tags[:async] do
Ecto.Adapters.SQL.Sandbox.mode(MatrixServer.Repo, {:shared, self()}) Ecto.Adapters.SQL.Sandbox.mode(Architex.Repo, {:shared, self()})
end end
{:ok, conn: Phoenix.ConnTest.build_conn()} {:ok, conn: Phoenix.ConnTest.build_conn()}

View file

@ -1,4 +1,4 @@
defmodule MatrixServer.DataCase do defmodule Architex.DataCase do
@moduledoc """ @moduledoc """
This module defines the setup for tests requiring This module defines the setup for tests requiring
access to the application's data layer. access to the application's data layer.
@ -10,7 +10,7 @@ defmodule MatrixServer.DataCase do
we enable the SQL sandbox, so changes done to the database we enable the SQL sandbox, so changes done to the database
are reverted at the end of every test. If you are using are reverted at the end of every test. If you are using
PostgreSQL, you can even run database tests asynchronously PostgreSQL, you can even run database tests asynchronously
by setting `use MatrixServer.DataCase, async: true`, although by setting `use Architex.DataCase, async: true`, although
this option is not recommended for other databases. this option is not recommended for other databases.
""" """
@ -18,20 +18,20 @@ defmodule MatrixServer.DataCase do
using do using do
quote do quote do
alias MatrixServer.Repo alias Architex.Repo
import Ecto import Ecto
import Ecto.Changeset import Ecto.Changeset
import Ecto.Query import Ecto.Query
import MatrixServer.DataCase import Architex.DataCase
end end
end end
setup tags do setup tags do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(MatrixServer.Repo) :ok = Ecto.Adapters.SQL.Sandbox.checkout(Architex.Repo)
unless tags[:async] do unless tags[:async] do
Ecto.Adapters.SQL.Sandbox.mode(MatrixServer.Repo, {:shared, self()}) Ecto.Adapters.SQL.Sandbox.mode(Architex.Repo, {:shared, self()})
end end
:ok :ok

View file

@ -1,7 +1,7 @@
defmodule MatrixServer.Factory do defmodule Architex.Factory do
use ExMachina.Ecto, repo: MatrixServer.Repo use ExMachina.Ecto, repo: Architex.Repo
alias MatrixServer.{Account, Device} alias Architex.{Account, Device}
def account_factory do def account_factory do
%Account{ %Account{

View file

@ -1,2 +1,2 @@
ExUnit.start() ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(MatrixServer.Repo, :manual) Ecto.Adapters.SQL.Sandbox.mode(Architex.Repo, :manual)