Rename repository
This commit is contained in:
parent
4aeb2d2cd8
commit
232df26b85
71 changed files with 348 additions and 345 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -20,7 +20,7 @@ erl_crash.dump
|
|||
*.ez
|
||||
|
||||
# Ignore package tarball (built via "mix hex.build").
|
||||
matrix_server-*.tar
|
||||
architex-*.tar
|
||||
|
||||
# Since we are building assets from assets/,
|
||||
# we ignore priv/static. You may want to comment
|
||||
|
|
|
@ -7,15 +7,15 @@
|
|||
# General application configuration
|
||||
use Mix.Config
|
||||
|
||||
config :matrix_server,
|
||||
ecto_repos: [MatrixServer.Repo]
|
||||
config :architex,
|
||||
ecto_repos: [Architex.Repo]
|
||||
|
||||
# Configures the endpoint
|
||||
config :matrix_server, MatrixServerWeb.Endpoint,
|
||||
config :architex, ArchitexWeb.Endpoint,
|
||||
url: [host: "localhost"],
|
||||
secret_key_base: "npI0xfNYxf5FoTIdAoc7er0ZvdCJgQFZQ9LcpUFL6dsPXyQllMv45zaQQoO4ZLu1",
|
||||
render_errors: [view: MatrixServerWeb.ErrorView, accepts: ~w(json), layout: false],
|
||||
pubsub_server: MatrixServer.PubSub,
|
||||
render_errors: [view: ArchitexWeb.ErrorView, accepts: ~w(json), layout: false],
|
||||
pubsub_server: Architex.PubSub,
|
||||
live_view: [signing_salt: "6ymoi3Gx"]
|
||||
|
||||
# Configures Elixir's Logger
|
||||
|
@ -26,7 +26,7 @@ config :logger, :console,
|
|||
# Use Jason for JSON parsing in Phoenix
|
||||
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,
|
||||
origin: ["*"],
|
||||
|
|
|
@ -4,10 +4,10 @@ hostname = "localhost"
|
|||
port = System.get_env("PORT") || 4000
|
||||
|
||||
# Configure your database
|
||||
config :matrix_server, MatrixServer.Repo,
|
||||
username: "matrix_server",
|
||||
password: "matrix_server",
|
||||
database: "matrix_server_dev",
|
||||
config :architex, Architex.Repo,
|
||||
username: "architex",
|
||||
password: "architex",
|
||||
database: "architex_dev",
|
||||
hostname: hostname,
|
||||
show_sensitive_data_on_connection_error: true,
|
||||
pool_size: 10
|
||||
|
@ -18,7 +18,7 @@ config :matrix_server, MatrixServer.Repo,
|
|||
# The watchers configuration can be used to run external
|
||||
# watchers to your application. For example, we use it
|
||||
# with webpack to recompile .js and .css sources.
|
||||
config :matrix_server, MatrixServerWeb.Endpoint,
|
||||
config :architex, ArchitexWeb.Endpoint,
|
||||
http: [port: port],
|
||||
debug_errors: true,
|
||||
code_reloader: true,
|
||||
|
@ -59,5 +59,5 @@ config :phoenix, :stacktrace_depth, 20
|
|||
# Initialize plugs at runtime for faster development compilation
|
||||
config :phoenix, :plug_init_mode, :runtime
|
||||
|
||||
config :matrix_server, server_name: "#{hostname}:#{port}"
|
||||
config :matrix_server, private_key_file: "keys/id_ed25519"
|
||||
config :architex, server_name: "#{hostname}:#{port}"
|
||||
config :architex, private_key_file: "keys/id_ed25519"
|
||||
|
|
|
@ -9,7 +9,7 @@ use Mix.Config
|
|||
# manifest is generated by the `mix phx.digest` task,
|
||||
# which you should run after static files are built and
|
||||
# before starting your production server.
|
||||
config :matrix_server, MatrixServerWeb.Endpoint,
|
||||
config :architex, ArchitexWeb.Endpoint,
|
||||
url: [host: "example.com", port: 80],
|
||||
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 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],
|
||||
# https: [
|
||||
|
@ -45,7 +45,7 @@ config :logger, level: :info
|
|||
# We also recommend setting `force_ssl` in your endpoint, ensuring
|
||||
# no data is ever sent via http, always redirecting to https:
|
||||
#
|
||||
# config :matrix_server, MatrixServerWeb.Endpoint,
|
||||
# config :architex, ArchitexWeb.Endpoint,
|
||||
# force_ssl: [hsts: true]
|
||||
#
|
||||
# Check `Plug.SSL` for all available options in `force_ssl`.
|
||||
|
|
|
@ -11,7 +11,7 @@ database_url =
|
|||
For example: ecto://USER:PASS@HOST/DATABASE
|
||||
"""
|
||||
|
||||
config :matrix_server, MatrixServer.Repo,
|
||||
config :architex, Architex.Repo,
|
||||
# ssl: true,
|
||||
url: database_url,
|
||||
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
|
||||
"""
|
||||
|
||||
config :matrix_server, MatrixServerWeb.Endpoint,
|
||||
config :architex, ArchitexWeb.Endpoint,
|
||||
http: [
|
||||
port: String.to_integer(System.get_env("PORT") || "4000"),
|
||||
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
|
||||
# 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`.
|
||||
# See `mix help release` for more information.
|
||||
|
|
|
@ -8,21 +8,21 @@ port = System.get_env("PORT") || 4000
|
|||
# The MIX_TEST_PARTITION environment variable can be used
|
||||
# to provide built-in test partitioning in CI environment.
|
||||
# Run `mix help test` for more information.
|
||||
config :matrix_server, MatrixServer.Repo,
|
||||
username: "matrix_server",
|
||||
password: "matrix_server",
|
||||
database: "matrix_server_test#{System.get_env("MIX_TEST_PARTITION")}",
|
||||
config :architex, Architex.Repo,
|
||||
username: "architex",
|
||||
password: "architex",
|
||||
database: "architex_test#{System.get_env("MIX_TEST_PARTITION")}",
|
||||
hostname: hostname,
|
||||
pool: Ecto.Adapters.SQL.Sandbox
|
||||
|
||||
# We don't run a server during test. If one is required,
|
||||
# you can enable the server option below.
|
||||
config :matrix_server, MatrixServerWeb.Endpoint,
|
||||
config :architex, ArchitexWeb.Endpoint,
|
||||
http: [port: port],
|
||||
server: false
|
||||
|
||||
# Print only warnings and errors during test
|
||||
config :logger, level: :warn
|
||||
|
||||
config :matrix_server, server_name: "#{hostname}:#{port}"
|
||||
config :matrix_server, private_key_file: "keys/id_ed25519"
|
||||
config :architex, server_name: "#{hostname}:#{port}"
|
||||
config :architex, private_key_file: "keys/id_ed25519"
|
||||
|
|
3
element.sh
Executable file
3
element.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
docker run --rm -d -p ${1-80}:80 vectorim/element-web
|
|
@ -1,9 +1,9 @@
|
|||
defmodule MatrixServer do
|
||||
defmodule Architex do
|
||||
@moduledoc """
|
||||
Utility functions used throughout the project.
|
||||
"""
|
||||
|
||||
alias MatrixServer.EncodableMap
|
||||
alias Architex.EncodableMap
|
||||
|
||||
@random_string_alphabet Enum.into(?a..?z, []) ++ Enum.into(?A..?Z, [])
|
||||
@ipv6_regex ~r/^\[(?<ip>[^\]]+)\](?<port>:\d{1,5})?$/
|
||||
|
@ -24,7 +24,7 @@ defmodule MatrixServer do
|
|||
"""
|
||||
@spec server_name() :: String.t()
|
||||
def server_name do
|
||||
Application.get_env(:matrix_server, :server_name)
|
||||
Application.get_env(:architex, :server_name)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
@ -171,12 +171,12 @@ defmodule MatrixServer do
|
|||
"""
|
||||
@spec add_signature(map(), String.t(), String.t()) :: map()
|
||||
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
|
||||
|
||||
def add_signature(%{signatures: sigs} = object, key_id, sig) do
|
||||
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}
|
||||
end
|
29
lib/architex/application.ex
Normal file
29
lib/architex/application.ex
Normal 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
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServer.Check do
|
||||
defmodule Architex.Check do
|
||||
import Ecto.Query
|
||||
alias MatrixServer.{Repo, Account, Room}
|
||||
alias MatrixServerWeb.Client.Request.CreateRoom
|
||||
alias Architex.{Repo, Account, Room}
|
||||
alias ArchitexWeb.Client.Request.CreateRoom
|
||||
|
||||
def create_room do
|
||||
account = Repo.one!(from a in Account, limit: 1)
|
|
@ -1,7 +1,7 @@
|
|||
# https://github.com/michalmuskala/jason/issues/69
|
||||
defmodule MatrixServer.EncodableMap do
|
||||
alias MatrixServer.EncodableMap
|
||||
alias MatrixServer.Types.{UserId, RoomId, EventId, GroupId, AliasId}
|
||||
defmodule Architex.EncodableMap do
|
||||
alias Architex.EncodableMap
|
||||
alias Architex.Types.{UserId, RoomId, EventId, GroupId, AliasId}
|
||||
|
||||
defstruct pairs: []
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServer.KeyServer do
|
||||
defmodule Architex.KeyServer do
|
||||
@moduledoc """
|
||||
A GenServer holding the homeserver's keys, and responsible for signing objects.
|
||||
|
||||
|
@ -54,7 +54,7 @@ defmodule MatrixServer.KeyServer do
|
|||
end
|
||||
|
||||
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}
|
||||
end
|
||||
|
@ -64,11 +64,11 @@ defmodule MatrixServer.KeyServer do
|
|||
defp sign_object(object, private_key) do
|
||||
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 =
|
||||
json
|
||||
|> :enacl.sign_detached(private_key)
|
||||
|> MatrixServer.encode_unpadded_base64()
|
||||
|> Architex.encode_unpadded_base64()
|
||||
|
||||
{:ok, signature}
|
||||
end
|
||||
|
@ -78,7 +78,7 @@ defmodule MatrixServer.KeyServer do
|
|||
@spec read_keys() :: {binary(), binary()}
|
||||
defp read_keys do
|
||||
raw_priv_key =
|
||||
Application.get_env(:matrix_server, :private_key_file)
|
||||
Application.get_env(:architex, :private_key_file)
|
||||
|> File.read!()
|
||||
|
||||
"-----BEGIN OPENSSH PRIVATE KEY-----\n" <> rest = raw_priv_key
|
5
lib/architex/repo.ex
Normal file
5
lib/architex/repo.ex
Normal file
|
@ -0,0 +1,5 @@
|
|||
defmodule Architex.Repo do
|
||||
use Ecto.Repo,
|
||||
otp_app: :architex,
|
||||
adapter: Ecto.Adapters.Postgres
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServer.RoomServer do
|
||||
defmodule Architex.RoomServer do
|
||||
@moduledoc """
|
||||
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.Changeset
|
||||
|
||||
alias MatrixServer.{
|
||||
alias Architex.{
|
||||
Repo,
|
||||
Room,
|
||||
Event,
|
||||
|
@ -24,11 +24,11 @@ defmodule MatrixServer.RoomServer do
|
|||
DeviceTransaction
|
||||
}
|
||||
|
||||
alias MatrixServer.StateResolution.Authorization
|
||||
alias MatrixServerWeb.Client.Request.{CreateRoom, Kick, Ban}
|
||||
alias Architex.StateResolution.Authorization
|
||||
alias ArchitexWeb.Client.Request.{CreateRoom, Kick, Ban}
|
||||
|
||||
@registry MatrixServer.RoomServer.Registry
|
||||
@supervisor MatrixServer.RoomServer.Supervisor
|
||||
@registry Architex.RoomServer.Registry
|
||||
@supervisor Architex.RoomServer.Supervisor
|
||||
|
||||
### Interface
|
||||
|
||||
|
@ -215,7 +215,7 @@ defmodule MatrixServer.RoomServer do
|
|||
result =
|
||||
Enum.any?(state_set, fn
|
||||
{{"m.room.member", user_id}, %Event{content: %{"membership" => "join"}}} ->
|
||||
MatrixServer.get_domain(user_id) == domain
|
||||
Architex.get_domain(user_id) == domain
|
||||
|
||||
_ ->
|
||||
false
|
||||
|
@ -607,19 +607,19 @@ defmodule MatrixServer.RoomServer do
|
|||
# Update local accounts' room membership if applicable.
|
||||
@spec update_joined_rooms(Room.t(), t()) :: JoinedRoom.t() | nil
|
||||
defp update_joined_rooms(%Room{id: room_id}, state_set) do
|
||||
server_name = MatrixServer.server_name()
|
||||
server_name = Architex.server_name()
|
||||
|
||||
{joined, not_joined} =
|
||||
state_set
|
||||
|> 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)
|
||||
|> Enum.split_with(fn {_, %Event{content: %{"membership" => membership}}} ->
|
||||
membership == "join"
|
||||
end)
|
||||
|
||||
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)
|
||||
not_joined_localparts = map_localparts.(not_joined)
|
|
@ -1,10 +1,10 @@
|
|||
defmodule MatrixServer.Account do
|
||||
defmodule Architex.Account do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.{Changeset, Query}
|
||||
|
||||
alias MatrixServer.{Repo, Account, Device, Room, JoinedRoom}
|
||||
alias MatrixServerWeb.Client.Request.{Register, Login}
|
||||
alias Architex.{Repo, Account, Device, Room, JoinedRoom}
|
||||
alias ArchitexWeb.Client.Request.{Register, Login}
|
||||
alias Ecto.{Multi, Changeset}
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
|
@ -30,7 +30,7 @@ defmodule MatrixServer.Account do
|
|||
"""
|
||||
@spec available?(String.t()) :: :ok | {:error, :user_in_use | :invalid_username}
|
||||
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
|
||||
if Repo.one!(
|
||||
Account
|
||||
|
@ -56,7 +56,7 @@ defmodule MatrixServer.Account do
|
|||
initial_device_display_name: initial_device_display_name,
|
||||
password: password
|
||||
}) do
|
||||
localpart = username || MatrixServer.random_string(10, ?a..?z)
|
||||
localpart = username || Architex.random_string(10, ?a..?z)
|
||||
|
||||
account_params = %{
|
||||
localpart: localpart,
|
||||
|
@ -126,7 +126,7 @@ defmodule MatrixServer.Account do
|
|||
|> cast(params, [:localpart, :password_hash])
|
||||
|> validate_required([:localpart, :password_hash])
|
||||
|> validate_length(:password_hash, max: 60)
|
||||
|> validate_format(:localpart, MatrixServer.localpart_regex())
|
||||
|> validate_format(:localpart, Architex.localpart_regex())
|
||||
|> validate_length(:localpart, max: localpart_length())
|
||||
|> unique_constraint(:localpart, name: :accounts_localpart_index)
|
||||
end
|
||||
|
@ -134,7 +134,7 @@ defmodule MatrixServer.Account do
|
|||
@spec localpart_length :: integer()
|
||||
defp localpart_length do
|
||||
# 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
|
||||
|
||||
@spec try_get_localpart(String.t()) :: String.t()
|
||||
|
@ -152,6 +152,6 @@ defmodule MatrixServer.Account do
|
|||
"""
|
||||
@spec get_mxid(Account.t()) :: String.t()
|
||||
def get_mxid(%Account{localpart: localpart}) do
|
||||
"@" <> localpart <> ":" <> MatrixServer.server_name()
|
||||
"@" <> localpart <> ":" <> Architex.server_name()
|
||||
end
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
defmodule MatrixServer.Alias do
|
||||
defmodule Architex.Alias do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
||||
alias MatrixServer.{Repo, Alias, Room}
|
||||
alias Architex.{Repo, Alias, Room}
|
||||
alias Ecto.Changeset
|
||||
|
||||
@primary_key {:alias, :string, []}
|
|
@ -1,10 +1,10 @@
|
|||
defmodule MatrixServer.Device do
|
||||
defmodule Architex.Device do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.{Changeset, Query}
|
||||
|
||||
alias MatrixServer.{Account, Device, Repo, DeviceTransaction}
|
||||
alias MatrixServerWeb.Client.Request.Login
|
||||
alias Architex.{Account, Device, Repo, DeviceTransaction}
|
||||
alias ArchitexWeb.Client.Request.Login
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
device_id: String.t(),
|
||||
|
@ -30,7 +30,7 @@ defmodule MatrixServer.Device do
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def generate_device_id(localpart) do
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServer.DeviceTransaction do
|
||||
defmodule Architex.DeviceTransaction do
|
||||
use Ecto.Schema
|
||||
|
||||
alias MatrixServer.Device
|
||||
alias Architex.Device
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
txn_id: String.t(),
|
|
@ -1,10 +1,10 @@
|
|||
defmodule MatrixServer.Event do
|
||||
defmodule Architex.Event do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
alias MatrixServer.{Repo, Room, Event, Account, EncodableMap, KeyServer}
|
||||
alias MatrixServer.Types.UserId
|
||||
alias Architex.{Repo, Room, Event, Account, EncodableMap, KeyServer}
|
||||
alias Architex.Types.UserId
|
||||
|
||||
# TODO: Could refactor to also always set prev_events, but not necessary.
|
||||
@type t :: %__MODULE__{
|
||||
|
@ -66,7 +66,7 @@ defmodule MatrixServer.Event do
|
|||
def new(%Room{id: room_id}, %Account{localpart: localpart}) do
|
||||
%Event{
|
||||
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),
|
||||
prev_events: [],
|
||||
auth_events: []
|
||||
|
@ -119,7 +119,7 @@ defmodule MatrixServer.Event do
|
|||
# Check rules: 1.1, 1.2
|
||||
prev_events == [] and
|
||||
auth_events == [] and
|
||||
domain == MatrixServer.get_domain(room_id)
|
||||
domain == Architex.get_domain(room_id)
|
||||
end
|
||||
|
||||
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
|
||||
length(auth_events) == length(auth_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
|
||||
Enum.find_value(state_pairs, false, &(&1 == {"m.room.create", ""})) and
|
||||
do_prevalidate(event, auth_events, prev_events)
|
||||
|
@ -152,7 +152,7 @@ defmodule MatrixServer.Event do
|
|||
_
|
||||
) do
|
||||
# Check rule: 4.2
|
||||
domain == MatrixServer.get_domain(state_key)
|
||||
domain == Architex.get_domain(state_key)
|
||||
end
|
||||
|
||||
# Rule 5.1 is left to changeset validation.
|
||||
|
@ -222,7 +222,7 @@ defmodule MatrixServer.Event do
|
|||
defp calculate_content_hash(event) do
|
||||
m =
|
||||
event
|
||||
|> MatrixServer.to_serializable_map()
|
||||
|> Architex.to_serializable_map()
|
||||
|> Map.drop([:unsigned, :signature, :hashes])
|
||||
|> EncodableMap.from_map()
|
||||
|
||||
|
@ -235,7 +235,7 @@ defmodule MatrixServer.Event do
|
|||
defp redact(%Event{type: type, content: content} = event) do
|
||||
redacted_event =
|
||||
event
|
||||
|> MatrixServer.to_serializable_map()
|
||||
|> Architex.to_serializable_map()
|
||||
|> Map.take([
|
||||
:event_id,
|
||||
:type,
|
||||
|
@ -285,11 +285,11 @@ defmodule MatrixServer.Event do
|
|||
@spec post_process(t()) :: {:ok, t()} | :error
|
||||
def post_process(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}}
|
||||
|
||||
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
|
||||
{:ok, event}
|
||||
|
@ -312,7 +312,7 @@ defmodule MatrixServer.Event do
|
|||
@spec generate_event_id(t()) :: {:ok, String.t()} | {:error, Jason.EncodeError.t()}
|
||||
defp generate_event_id(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
|
||||
|
||||
|
@ -323,7 +323,7 @@ defmodule MatrixServer.Event do
|
|||
|> redact()
|
||||
|> 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)}
|
||||
end
|
||||
end
|
|
@ -1,9 +1,9 @@
|
|||
defmodule MatrixServer.Event.Join do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.Join do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t()) :: Event.t()
|
||||
def new(room, %Account{localpart: localpart} = sender) do
|
||||
mxid = MatrixServer.get_mxid(localpart)
|
||||
mxid = Architex.get_mxid(localpart)
|
||||
|
||||
%Event{
|
||||
Event.new(room, sender)
|
||||
|
@ -16,12 +16,12 @@ defmodule MatrixServer.Event.Join do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.CreateRoom do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.CreateRoom do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t(), String.t()) :: Event.t()
|
||||
def new(room, %Account{localpart: localpart} = creator, room_version) do
|
||||
mxid = MatrixServer.get_mxid(localpart)
|
||||
mxid = Architex.get_mxid(localpart)
|
||||
|
||||
%Event{
|
||||
Event.new(room, creator)
|
||||
|
@ -29,18 +29,18 @@ defmodule MatrixServer.Event.CreateRoom do
|
|||
state_key: "",
|
||||
content: %{
|
||||
"creator" => mxid,
|
||||
"room_version" => room_version || MatrixServer.default_room_version()
|
||||
"room_version" => room_version || Architex.default_room_version()
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.PowerLevels do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.PowerLevels do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t()) :: Event.t()
|
||||
def new(room, %Account{localpart: localpart} = sender) do
|
||||
mxid = MatrixServer.get_mxid(localpart)
|
||||
mxid = Architex.get_mxid(localpart)
|
||||
|
||||
%Event{
|
||||
Event.new(room, sender)
|
||||
|
@ -66,8 +66,8 @@ defmodule MatrixServer.Event.PowerLevels do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.Name do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.Name do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t(), String.t()) :: Event.t()
|
||||
def new(room, sender, name) do
|
||||
|
@ -82,8 +82,8 @@ defmodule MatrixServer.Event.Name do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.Topic do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.Topic do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t(), String.t()) :: Event.t()
|
||||
def new(room, sender, topic) do
|
||||
|
@ -98,8 +98,8 @@ defmodule MatrixServer.Event.Topic do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.JoinRules do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.JoinRules do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t(), String.t()) :: Event.t()
|
||||
def new(room, sender, join_rule) do
|
||||
|
@ -114,8 +114,8 @@ defmodule MatrixServer.Event.JoinRules do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.HistoryVisibility do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.HistoryVisibility do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t(), String.t()) :: Event.t()
|
||||
def new(room, sender, history_visibility) do
|
||||
|
@ -130,8 +130,8 @@ defmodule MatrixServer.Event.HistoryVisibility do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.GuestAccess do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.GuestAccess do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t(), String.t()) :: Event.t()
|
||||
def new(room, sender, guest_access) do
|
||||
|
@ -146,8 +146,8 @@ defmodule MatrixServer.Event.GuestAccess do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.Invite do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.Invite do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t(), String.t()) :: Event.t()
|
||||
def new(room, sender, user_id) do
|
||||
|
@ -162,8 +162,8 @@ defmodule MatrixServer.Event.Invite do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.Leave do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.Leave do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t()) :: Event.t()
|
||||
def new(room, sender) do
|
||||
|
@ -178,8 +178,8 @@ defmodule MatrixServer.Event.Leave do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.Kick do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.Kick do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t(), String.t(), String.t() | nil) :: Event.t()
|
||||
def new(room, sender, user_id, reason \\ nil) do
|
||||
|
@ -195,8 +195,8 @@ defmodule MatrixServer.Event.Kick do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.Ban do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.Ban do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t(), String.t(), String.t() | nil) :: Event.t()
|
||||
def new(room, sender, user_id, reason \\ nil) do
|
||||
|
@ -212,8 +212,8 @@ defmodule MatrixServer.Event.Ban do
|
|||
end
|
||||
end
|
||||
|
||||
defmodule MatrixServer.Event.Unban do
|
||||
alias MatrixServer.{Event, Account, Room}
|
||||
defmodule Architex.Event.Unban do
|
||||
alias Architex.{Event, Account, Room}
|
||||
@spec new(Room.t(), Account.t(), String.t()) :: Event.t()
|
||||
def new(room, sender, user_id) do
|
||||
%Event{
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServer.JoinedRoom do
|
||||
defmodule Architex.JoinedRoom do
|
||||
use Ecto.Schema
|
||||
|
||||
alias MatrixServer.{Account, Room}
|
||||
alias Architex.{Account, Room}
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
account_id: integer(),
|
|
@ -1,11 +1,11 @@
|
|||
defmodule MatrixServer.Room do
|
||||
defmodule Architex.Room do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
|
||||
alias MatrixServer.{Repo, Room, Event, Alias, RoomServer}
|
||||
alias MatrixServerWeb.Client.Request.CreateRoom
|
||||
alias Architex.{Repo, Room, Event, Alias, RoomServer}
|
||||
alias ArchitexWeb.Client.Request.CreateRoom
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
visibility: :public | :private,
|
||||
|
@ -34,7 +34,7 @@ defmodule MatrixServer.Room do
|
|||
end
|
||||
|
||||
def generate_room_id do
|
||||
"!" <> MatrixServer.random_string(18) <> ":" <> MatrixServer.server_name()
|
||||
"!" <> Architex.random_string(18) <> ":" <> Architex.server_name()
|
||||
end
|
||||
|
||||
def update_forward_extremities(
|
|
@ -1,11 +1,11 @@
|
|||
defmodule MatrixServer.ServerKeyInfo do
|
||||
defmodule Architex.ServerKeyInfo do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
alias MatrixServer.{Repo, ServerKeyInfo, SigningKey}
|
||||
alias MatrixServerWeb.Federation.HTTPClient
|
||||
alias MatrixServerWeb.Federation.Request.GetSigningKeys
|
||||
alias Architex.{Repo, ServerKeyInfo, SigningKey}
|
||||
alias ArchitexWeb.Federation.HTTPClient
|
||||
alias ArchitexWeb.Federation.Request.GetSigningKeys
|
||||
alias Ecto.Multi
|
||||
|
||||
@primary_key {:server_name, :string, []}
|
||||
|
@ -53,7 +53,7 @@ defmodule MatrixServer.ServerKeyInfo do
|
|||
ski = %ServerKeyInfo{
|
||||
server_name: server_name,
|
||||
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
|
|
@ -1,10 +1,10 @@
|
|||
defmodule MatrixServer.SigningKey do
|
||||
defmodule Architex.SigningKey do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
|
||||
alias MatrixServer.{Repo, SigningKey, ServerKeyInfo}
|
||||
alias Architex.{Repo, SigningKey, ServerKeyInfo}
|
||||
|
||||
@primary_key false
|
||||
schema "signing_keys" do
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServer.StateResolution do
|
||||
defmodule Architex.StateResolution do
|
||||
@moduledoc """
|
||||
Functions for resolving the state of a Matrix room.
|
||||
|
||||
|
@ -20,8 +20,8 @@ defmodule MatrixServer.StateResolution do
|
|||
|
||||
import Ecto.Query
|
||||
|
||||
alias MatrixServer.{Repo, Event, Room}
|
||||
alias MatrixServer.StateResolution.Authorization
|
||||
alias Architex.{Repo, Event, Room}
|
||||
alias Architex.StateResolution.Authorization
|
||||
|
||||
@type state_set :: map()
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
defmodule MatrixServer.StateResolution.Authorization do
|
||||
defmodule Architex.StateResolution.Authorization do
|
||||
@moduledoc """
|
||||
Implementation of Matrix event authorization rules for state resolution.
|
||||
|
||||
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
|
||||
|
||||
alias MatrixServer.{Repo, Event}
|
||||
alias MatrixServer.Types.UserId
|
||||
alias MatrixServer.StateResolution, as: StateRes
|
||||
alias Architex.{Repo, Event}
|
||||
alias Architex.Types.UserId
|
||||
alias Architex.StateResolution, as: StateRes
|
||||
|
||||
@typep action :: :invite | :ban | :redact | :kick | {:event, Event.t()}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServer.Types.AliasId do
|
||||
defmodule Architex.Types.AliasId do
|
||||
use Ecto.Type
|
||||
|
||||
alias MatrixServer.Types.AliasId
|
||||
alias Architex.Types.AliasId
|
||||
|
||||
defstruct [:localpart, :domain]
|
||||
|
||||
|
@ -17,7 +17,7 @@ defmodule MatrixServer.Types.AliasId do
|
|||
with "#" <> rest <- s,
|
||||
[localpart, domain] <- String.split(rest, ":", parts: 2) do
|
||||
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}}
|
||||
else
|
||||
:error
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServer.Types.EventId do
|
||||
defmodule Architex.Types.EventId do
|
||||
use Ecto.Type
|
||||
|
||||
alias MatrixServer.Types.EventId
|
||||
alias Architex.Types.EventId
|
||||
|
||||
defstruct [:id]
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServer.Types.GroupId do
|
||||
defmodule Architex.Types.GroupId do
|
||||
use Ecto.Type
|
||||
|
||||
alias MatrixServer.Types.GroupId
|
||||
alias Architex.Types.GroupId
|
||||
|
||||
defstruct [:localpart, :domain]
|
||||
|
||||
|
@ -20,7 +20,7 @@ defmodule MatrixServer.Types.GroupId do
|
|||
[localpart, domain] <- String.split(rest, ":", parts: 2) do
|
||||
if String.length(localpart) + String.length(domain) + 2 <= 255 and
|
||||
Regex.match?(@localpart_regex, localpart) and
|
||||
MatrixServer.valid_domain?(domain) do
|
||||
Architex.valid_domain?(domain) do
|
||||
{:ok, %GroupId{localpart: localpart, domain: domain}}
|
||||
else
|
||||
:error
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServer.Types.RoomId do
|
||||
defmodule Architex.Types.RoomId do
|
||||
use Ecto.Type
|
||||
|
||||
alias MatrixServer.Types.RoomId
|
||||
alias Architex.Types.RoomId
|
||||
|
||||
defstruct [:localpart, :domain]
|
||||
|
||||
|
@ -16,7 +16,7 @@ defmodule MatrixServer.Types.RoomId do
|
|||
def cast(s) when is_binary(s) do
|
||||
with "!" <> rest <- s,
|
||||
[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}}
|
||||
else
|
||||
:error
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServer.Types.UserId do
|
||||
defmodule Architex.Types.UserId do
|
||||
use Ecto.Type
|
||||
|
||||
alias MatrixServer.Types.UserId
|
||||
alias Architex.Types.UserId
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
localpart: String.t(),
|
||||
|
@ -30,7 +30,7 @@ defmodule MatrixServer.Types.UserId do
|
|||
with "@" <> rest <- s,
|
||||
[localpart, domain] <- String.split(rest, ":", parts: 2) do
|
||||
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}}
|
||||
else
|
||||
:error
|
|
@ -1,12 +1,12 @@
|
|||
defmodule MatrixServerWeb do
|
||||
defmodule ArchitexWeb do
|
||||
@moduledoc """
|
||||
The entrypoint for defining your web interface, such
|
||||
as controllers, views, channels and so on.
|
||||
|
||||
This can be used in your application as:
|
||||
|
||||
use MatrixServerWeb, :controller
|
||||
use MatrixServerWeb, :view
|
||||
use ArchitexWeb, :controller
|
||||
use ArchitexWeb, :view
|
||||
|
||||
The definitions below will be executed for every view,
|
||||
controller, etc, so keep them short and clean, focused
|
||||
|
@ -19,18 +19,18 @@ defmodule MatrixServerWeb do
|
|||
|
||||
def controller do
|
||||
quote do
|
||||
use Phoenix.Controller, namespace: MatrixServerWeb
|
||||
use Phoenix.Controller, namespace: ArchitexWeb
|
||||
|
||||
import Plug.Conn
|
||||
alias MatrixServerWeb.Router.Helpers, as: Routes
|
||||
alias ArchitexWeb.Router.Helpers, as: Routes
|
||||
end
|
||||
end
|
||||
|
||||
def view do
|
||||
quote do
|
||||
use Phoenix.View,
|
||||
root: "lib/matrix_server_web/templates",
|
||||
namespace: MatrixServerWeb
|
||||
root: "lib/architex_web/templates",
|
||||
namespace: ArchitexWeb
|
||||
|
||||
# Import convenience functions from controllers
|
||||
import Phoenix.Controller,
|
||||
|
@ -61,8 +61,8 @@ defmodule MatrixServerWeb do
|
|||
# Import basic rendering functionality (render, render_layout, etc)
|
||||
import Phoenix.View
|
||||
|
||||
import MatrixServerWeb.ErrorHelpers
|
||||
alias MatrixServerWeb.Router.Helpers, as: Routes
|
||||
import ArchitexWeb.ErrorHelpers
|
||||
alias ArchitexWeb.Router.Helpers, as: Routes
|
||||
end
|
||||
end
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
defmodule MatrixServerWeb.Client.Plug.AuthenticateClient do
|
||||
import MatrixServerWeb.Error
|
||||
defmodule ArchitexWeb.Client.Plug.AuthenticateClient do
|
||||
import ArchitexWeb.Error
|
||||
import Plug.Conn
|
||||
|
||||
alias MatrixServer.Account
|
||||
alias Architex.Account
|
||||
alias Plug.Conn
|
||||
|
||||
def init(opts), do: opts
|
|
@ -1,10 +1,10 @@
|
|||
defmodule MatrixServerWeb.Client.AccountController do
|
||||
use MatrixServerWeb, :controller
|
||||
defmodule ArchitexWeb.Client.AccountController do
|
||||
use ArchitexWeb, :controller
|
||||
|
||||
import MatrixServer
|
||||
import MatrixServerWeb.Error
|
||||
import Architex
|
||||
import ArchitexWeb.Error
|
||||
|
||||
alias MatrixServer.{Account, Repo}
|
||||
alias Architex.{Account, Repo}
|
||||
alias Plug.Conn
|
||||
|
||||
@doc """
|
|
@ -1,9 +1,9 @@
|
|||
defmodule MatrixServerWeb.Client.AliasesController do
|
||||
use MatrixServerWeb, :controller
|
||||
defmodule ArchitexWeb.Client.AliasesController do
|
||||
use ArchitexWeb, :controller
|
||||
|
||||
import MatrixServerWeb.Error
|
||||
import ArchitexWeb.Error
|
||||
|
||||
alias MatrixServer.Alias
|
||||
alias Architex.Alias
|
||||
|
||||
@doc """
|
||||
Create a new mapping from room alias to room ID.
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServerWeb.Client.InfoController do
|
||||
use MatrixServerWeb, :controller
|
||||
defmodule ArchitexWeb.Client.InfoController do
|
||||
use ArchitexWeb, :controller
|
||||
|
||||
import MatrixServerWeb.Error
|
||||
import ArchitexWeb.Error
|
||||
|
||||
@supported_versions ["r0.6.1"]
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
defmodule MatrixServerWeb.Client.LoginController do
|
||||
use MatrixServerWeb, :controller
|
||||
defmodule ArchitexWeb.Client.LoginController do
|
||||
use ArchitexWeb, :controller
|
||||
|
||||
import MatrixServerWeb.Error
|
||||
import ArchitexWeb.Error
|
||||
import Ecto.Changeset
|
||||
|
||||
alias MatrixServer.{Repo, Account, Device}
|
||||
alias MatrixServerWeb.Client.Request.Login
|
||||
alias Architex.{Repo, Account, Device}
|
||||
alias ArchitexWeb.Client.Request.Login
|
||||
alias Ecto.Changeset
|
||||
|
||||
@login_type "m.login.password"
|
||||
|
@ -42,7 +42,7 @@ defmodule MatrixServerWeb.Client.LoginController do
|
|||
{%Account{localpart: localpart},
|
||||
%Device{access_token: access_token, device_id: device_id}}} ->
|
||||
data = %{
|
||||
user_id: MatrixServer.get_mxid(localpart),
|
||||
user_id: Architex.get_mxid(localpart),
|
||||
access_token: access_token,
|
||||
device_id: device_id
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
defmodule MatrixServerWeb.Client.RegisterController do
|
||||
use MatrixServerWeb, :controller
|
||||
defmodule ArchitexWeb.Client.RegisterController do
|
||||
use ArchitexWeb, :controller
|
||||
|
||||
import MatrixServerWeb.Error
|
||||
import ArchitexWeb.Error
|
||||
import Ecto.Changeset
|
||||
|
||||
alias MatrixServer.{Repo, Account, Device}
|
||||
alias MatrixServerWeb.Client.Request.Register
|
||||
alias Architex.{Repo, Account, Device}
|
||||
alias ArchitexWeb.Client.Request.Register
|
||||
alias Ecto.Changeset
|
||||
|
||||
@register_type "m.login.dummy"
|
||||
|
@ -26,7 +26,7 @@ defmodule MatrixServerWeb.Client.RegisterController do
|
|||
account: %Account{localpart: localpart},
|
||||
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 =
|
||||
if not inhibit_login do
|
|
@ -1,12 +1,12 @@
|
|||
defmodule MatrixServerWeb.Client.RoomController do
|
||||
use MatrixServerWeb, :controller
|
||||
defmodule ArchitexWeb.Client.RoomController do
|
||||
use ArchitexWeb, :controller
|
||||
|
||||
import MatrixServerWeb.Error
|
||||
import ArchitexWeb.Error
|
||||
import Ecto.{Changeset, Query}
|
||||
|
||||
alias MatrixServer.{Repo, Room, RoomServer}
|
||||
alias MatrixServer.Types.UserId
|
||||
alias MatrixServerWeb.Client.Request.{CreateRoom, Kick, Ban}
|
||||
alias Architex.{Repo, Room, RoomServer}
|
||||
alias Architex.Types.UserId
|
||||
alias ArchitexWeb.Client.Request.{CreateRoom, Kick, Ban}
|
||||
alias Ecto.Changeset
|
||||
alias Plug.Conn
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
defmodule MatrixServerWeb.Client.RoomDirectoryController do
|
||||
use MatrixServerWeb, :controller
|
||||
defmodule ArchitexWeb.Client.RoomDirectoryController do
|
||||
use ArchitexWeb, :controller
|
||||
|
||||
import MatrixServerWeb.Error
|
||||
import ArchitexWeb.Error
|
||||
import Ecto.Query
|
||||
|
||||
alias MatrixServer.{Repo, Room, RoomServer}
|
||||
alias Architex.{Repo, Room, RoomServer}
|
||||
alias Plug.Conn
|
||||
|
||||
@doc """
|
|
@ -1,5 +1,5 @@
|
|||
defmodule MatrixServerWeb.Client.Request.Ban do
|
||||
use MatrixServerWeb.Request
|
||||
defmodule ArchitexWeb.Client.Request.Ban do
|
||||
use ArchitexWeb.Request
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
user_id: String.t(),
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServerWeb.Client.Request.CreateRoom do
|
||||
defmodule ArchitexWeb.Client.Request.CreateRoom do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
|
@ -1,5 +1,5 @@
|
|||
defmodule MatrixServerWeb.Client.Request.Kick do
|
||||
use MatrixServerWeb.Request
|
||||
defmodule ArchitexWeb.Client.Request.Kick do
|
||||
use ArchitexWeb.Request
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
user_id: String.t(),
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServerWeb.Client.Request.Login do
|
||||
defmodule ArchitexWeb.Client.Request.Login do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServerWeb.Client.Request.Register do
|
||||
defmodule ArchitexWeb.Client.Request.Register do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
|
@ -1,12 +1,12 @@
|
|||
defmodule MatrixServerWeb.Endpoint do
|
||||
use Phoenix.Endpoint, otp_app: :matrix_server
|
||||
defmodule ArchitexWeb.Endpoint do
|
||||
use Phoenix.Endpoint, otp_app: :architex
|
||||
|
||||
# The session will be stored in the cookie and signed,
|
||||
# this means its contents can be read but not tampered with.
|
||||
# Set :encryption_salt if you would also like to encrypt it.
|
||||
@session_options [
|
||||
store: :cookie,
|
||||
key: "_matrix_server_key",
|
||||
key: "_architex_key",
|
||||
signing_salt: "IGPHtnAo"
|
||||
]
|
||||
|
||||
|
@ -16,7 +16,7 @@ defmodule MatrixServerWeb.Endpoint do
|
|||
# when deploying your static files in production.
|
||||
plug Plug.Static,
|
||||
at: "/",
|
||||
from: :matrix_server,
|
||||
from: :architex,
|
||||
gzip: false,
|
||||
only: ~w(css fonts images js favicon.ico robots.txt)
|
||||
|
||||
|
@ -24,7 +24,7 @@ defmodule MatrixServerWeb.Endpoint do
|
|||
# :code_reloader configuration of your endpoint.
|
||||
if code_reloading? do
|
||||
plug Phoenix.CodeReloader
|
||||
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :matrix_server
|
||||
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :architex
|
||||
end
|
||||
|
||||
plug Plug.RequestId
|
||||
|
@ -40,5 +40,5 @@ defmodule MatrixServerWeb.Endpoint do
|
|||
plug Plug.Session, @session_options
|
||||
plug CORSPlug
|
||||
|
||||
plug MatrixServerWeb.Router
|
||||
plug ArchitexWeb.Router
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServerWeb.Error do
|
||||
defmodule ArchitexWeb.Error do
|
||||
import Plug.Conn
|
||||
import Phoenix.Controller, only: [json: 2]
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServerWeb.Federation.AuthenticateServer do
|
||||
import MatrixServerWeb.Error
|
||||
defmodule ArchitexWeb.Federation.AuthenticateServer do
|
||||
import ArchitexWeb.Error
|
||||
|
||||
alias MatrixServer.{SigningKey, ServerKeyInfo}
|
||||
alias Architex.{SigningKey, ServerKeyInfo}
|
||||
|
||||
@auth_header_regex ~r/^X-Matrix origin=(?<origin>.*),key="(?<key>.*)",sig="(?<sig>.*)"$/
|
||||
|
||||
|
@ -25,7 +25,7 @@ defmodule MatrixServerWeb.Federation.AuthenticateServer do
|
|||
object_to_sign = %{
|
||||
uri: uri,
|
||||
method: method,
|
||||
destination: MatrixServer.server_name()
|
||||
destination: Architex.server_name()
|
||||
}
|
||||
|
||||
object_to_sign =
|
||||
|
@ -43,13 +43,13 @@ defmodule MatrixServerWeb.Federation.AuthenticateServer do
|
|||
|> Enum.find(:error, fn {origin, _, sig} ->
|
||||
object = object_fun.(origin)
|
||||
|
||||
with {:ok, raw_sig} <- MatrixServer.decode_base64(sig),
|
||||
{:ok, encoded_object} <- MatrixServer.encode_canonical_json(object),
|
||||
with {:ok, raw_sig} <- Architex.decode_base64(sig),
|
||||
{:ok, encoded_object} <- Architex.encode_canonical_json(object),
|
||||
{:ok, %ServerKeyInfo{signing_keys: keys}} <-
|
||||
ServerKeyInfo.with_fresh_signing_keys(origin) do
|
||||
Enum.find_value(keys, false, fn %SigningKey{signing_key: signing_key} ->
|
||||
with {:ok, decoded_key} <- MatrixServer.decode_base64(signing_key) do
|
||||
MatrixServer.sign_verify(raw_sig, encoded_object, decoded_key)
|
||||
with {:ok, decoded_key} <- Architex.decode_base64(signing_key) do
|
||||
Architex.sign_verify(raw_sig, encoded_object, decoded_key)
|
||||
else
|
||||
_ -> false
|
||||
end
|
||||
|
@ -81,7 +81,7 @@ defmodule MatrixServerWeb.Federation.AuthenticateServer do
|
|||
action = action_name(conn)
|
||||
|
||||
if action not in unquote(except) do
|
||||
case MatrixServerWeb.Federation.AuthenticateServer.authenticate(conn) do
|
||||
case ArchitexWeb.Federation.AuthenticateServer.authenticate(conn) do
|
||||
{origin, _key, _sig} ->
|
||||
conn = Plug.Conn.assign(conn, :origin, origin)
|
||||
apply(__MODULE__, action, [conn, conn.params])
|
|
@ -1,12 +1,12 @@
|
|||
defmodule MatrixServerWeb.Federation.EventController do
|
||||
use MatrixServerWeb, :controller
|
||||
use MatrixServerWeb.Federation.AuthenticateServer
|
||||
defmodule ArchitexWeb.Federation.EventController do
|
||||
use ArchitexWeb, :controller
|
||||
use ArchitexWeb.Federation.AuthenticateServer
|
||||
|
||||
import MatrixServerWeb.Error
|
||||
import ArchitexWeb.Error
|
||||
import Ecto.Query
|
||||
|
||||
alias MatrixServer.{Repo, Event, RoomServer}
|
||||
alias MatrixServerWeb.Federation.Transaction
|
||||
alias Architex.{Repo, Event, RoomServer}
|
||||
alias ArchitexWeb.Federation.Transaction
|
||||
|
||||
@doc """
|
||||
Retrieves a single event.
|
|
@ -1,9 +1,9 @@
|
|||
defmodule MatrixServerWeb.Federation.KeyController do
|
||||
use MatrixServerWeb, :controller
|
||||
defmodule ArchitexWeb.Federation.KeyController do
|
||||
use ArchitexWeb, :controller
|
||||
|
||||
import MatrixServerWeb.Error
|
||||
import ArchitexWeb.Error
|
||||
|
||||
alias MatrixServer.KeyServer
|
||||
alias Architex.KeyServer
|
||||
|
||||
@doc """
|
||||
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)
|
||||
|
||||
data = %{
|
||||
server_name: MatrixServer.server_name(),
|
||||
server_name: Architex.server_name(),
|
||||
verify_keys: keys,
|
||||
old_verify_keys: %{},
|
||||
valid_until_ts: DateTime.to_unix(valid_until, :millisecond)
|
||||
|
@ -30,7 +30,7 @@ defmodule MatrixServerWeb.Federation.KeyController do
|
|||
|
||||
case KeyServer.sign_object(data) do
|
||||
{:ok, sig, key_id} ->
|
||||
signed_data = MatrixServer.add_signature(data, key_id, sig)
|
||||
signed_data = Architex.add_signature(data, key_id, sig)
|
||||
|
||||
conn
|
||||
|> put_status(200)
|
|
@ -1,12 +1,12 @@
|
|||
defmodule MatrixServerWeb.Federation.QueryController do
|
||||
use MatrixServerWeb, :controller
|
||||
use MatrixServerWeb.Federation.AuthenticateServer
|
||||
defmodule ArchitexWeb.Federation.QueryController do
|
||||
use ArchitexWeb, :controller
|
||||
use ArchitexWeb.Federation.AuthenticateServer
|
||||
|
||||
import MatrixServerWeb.Error
|
||||
import ArchitexWeb.Error
|
||||
import Ecto.Query
|
||||
|
||||
alias MatrixServer.{Repo, Account}
|
||||
alias MatrixServer.Types.UserId
|
||||
alias Architex.{Repo, Account}
|
||||
alias Architex.Types.UserId
|
||||
|
||||
defmodule ProfileRequest do
|
||||
use Ecto.Schema
|
||||
|
@ -40,7 +40,7 @@ defmodule MatrixServerWeb.Federation.QueryController do
|
|||
def profile(conn, params) do
|
||||
with {:ok, %ProfileRequest{user_id: %UserId{localpart: localpart, domain: domain}}} <-
|
||||
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
|
||||
%Account{} ->
|
||||
# TODO: Return displayname and avatar_url when we implement them.
|
|
@ -1,15 +1,15 @@
|
|||
defmodule MatrixServerWeb.Federation.HTTPClient do
|
||||
defmodule ArchitexWeb.Federation.HTTPClient do
|
||||
use Tesla
|
||||
|
||||
alias MatrixServerWeb.Endpoint
|
||||
alias MatrixServerWeb.Federation.Request.GetSigningKeys
|
||||
alias MatrixServerWeb.Federation.Middleware.SignRequest
|
||||
alias MatrixServerWeb.Router.Helpers, as: RouteHelpers
|
||||
alias ArchitexWeb.Endpoint
|
||||
alias ArchitexWeb.Federation.Request.GetSigningKeys
|
||||
alias ArchitexWeb.Federation.Middleware.SignRequest
|
||||
alias ArchitexWeb.Router.Helpers, as: RouteHelpers
|
||||
|
||||
# TODO: Maybe create database-backed homeserver struct to pass to client function.
|
||||
# TODO: Fix error propagation.
|
||||
|
||||
@adapter {Tesla.Adapter.Finch, name: MatrixServerWeb.HTTPClient}
|
||||
@adapter {Tesla.Adapter.Finch, name: ArchitexWeb.HTTPClient}
|
||||
|
||||
def client(server_name) do
|
||||
Tesla.client(
|
||||
|
@ -29,17 +29,17 @@ defmodule MatrixServerWeb.Federation.HTTPClient do
|
|||
with {:ok,
|
||||
%GetSigningKeys{server_name: server_name, verify_keys: verify_keys, signatures: sigs} =
|
||||
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]),
|
||||
{: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
|
||||
# For each verify key, check if there is a matching signature.
|
||||
# If not, invalidate the whole response.
|
||||
Enum.all?(verify_keys, fn {key_id, %{"key" => key}} ->
|
||||
with true <- Map.has_key?(server_sigs, key_id),
|
||||
{:ok, decoded_key} <- MatrixServer.decode_base64(key),
|
||||
{:ok, decoded_sig} <- MatrixServer.decode_base64(server_sigs[key_id]) do
|
||||
MatrixServer.sign_verify(decoded_sig, encoded_body, decoded_key)
|
||||
{:ok, decoded_key} <- Architex.decode_base64(key),
|
||||
{:ok, decoded_sig} <- Architex.decode_base64(server_sigs[key_id]) do
|
||||
Architex.sign_verify(decoded_sig, encoded_body, decoded_key)
|
||||
else
|
||||
_ -> false
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServerWeb.Federation.Request.GetSigningKeys do
|
||||
defmodule ArchitexWeb.Federation.Request.GetSigningKeys do
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset
|
||||
|
@ -17,12 +17,12 @@ defmodule MatrixServerWeb.Federation.Request.GetSigningKeys do
|
|||
%__MODULE__{}
|
||||
|> cast(params, [:server_name, :verify_keys, :old_verify_keys, :signatures, :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} ->
|
||||
is_map_key(map, "key")
|
||||
end)
|
||||
end)
|
||||
|> MatrixServer.validate_change_simple(:old_verify_keys, fn map ->
|
||||
|> Architex.validate_change_simple(:old_verify_keys, fn map ->
|
||||
Enum.all?(map, fn
|
||||
{_, %{"key" => key, "expired_ts" => expired_ts}}
|
||||
when is_binary(key) and is_integer(expired_ts) ->
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServerWeb.Federation.Middleware.SignRequest do
|
||||
defmodule ArchitexWeb.Federation.Middleware.SignRequest do
|
||||
@behaviour Tesla.Middleware
|
||||
|
||||
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(%Tesla.Env{method: method, url: path, opts: opts, body: body} = env, true) do
|
||||
origin = MatrixServer.server_name()
|
||||
origin = Architex.server_name()
|
||||
|
||||
object_to_sign = %{
|
||||
method: Atom.to_string(method) |> String.upcase(),
|
||||
|
@ -25,7 +25,7 @@ defmodule MatrixServerWeb.Federation.Middleware.SignRequest do
|
|||
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}}
|
||||
auth_headers = create_signature_authorization_headers(sigs, origin)
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
defmodule MatrixServerWeb.Federation.Transaction do
|
||||
alias MatrixServer.Event
|
||||
alias MatrixServerWeb.Federation.Transaction
|
||||
defmodule ArchitexWeb.Federation.Transaction do
|
||||
alias Architex.Event
|
||||
alias ArchitexWeb.Federation.Transaction
|
||||
|
||||
# TODO
|
||||
@type edu :: any()
|
||||
|
@ -27,9 +27,9 @@ defmodule MatrixServerWeb.Federation.Transaction do
|
|||
@spec new([Event.t()], [edu()] | nil) :: t()
|
||||
def new(pdu_events, edus \\ nil) do
|
||||
%Transaction{
|
||||
origin: MatrixServer.server_name(),
|
||||
origin: Architex.server_name(),
|
||||
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
|
||||
}
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServerWeb.Request do
|
||||
defmodule ArchitexWeb.Request do
|
||||
import Ecto.Changeset
|
||||
|
||||
alias Ecto.Changeset
|
||||
|
@ -19,7 +19,7 @@ defmodule MatrixServerWeb.Request do
|
|||
|
||||
@spec parse(map()) :: {:ok, struct()} | {:error, Changeset.t()}
|
||||
def parse(params) do
|
||||
MatrixServerWeb.Request.parse(__MODULE__, params)
|
||||
ArchitexWeb.Request.parse(__MODULE__, params)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServerWeb.Router do
|
||||
use MatrixServerWeb, :router
|
||||
defmodule ArchitexWeb.Router do
|
||||
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:
|
||||
# https://elixirforum.com/t/write-malformed-json-in-the-body-plug/30578/13
|
||||
|
@ -22,7 +22,7 @@ defmodule MatrixServerWeb.Router do
|
|||
end
|
||||
|
||||
# Public client endpoint.
|
||||
scope "/_matrix/client", MatrixServerWeb.Client do
|
||||
scope "/_matrix/client", ArchitexWeb.Client do
|
||||
pipe_through :public
|
||||
|
||||
scope "/r0" do
|
||||
|
@ -37,14 +37,14 @@ defmodule MatrixServerWeb.Router do
|
|||
end
|
||||
|
||||
# Public federation endpoint.
|
||||
scope "/_matrix", MatrixServerWeb.Federation do
|
||||
scope "/_matrix", ArchitexWeb.Federation do
|
||||
scope "/key/v2" do
|
||||
get "/server", KeyController, :get_signing_keys
|
||||
end
|
||||
end
|
||||
|
||||
# Authenticated client endpoint.
|
||||
scope "/_matrix/client", MatrixServerWeb.Client do
|
||||
scope "/_matrix/client", ArchitexWeb.Client do
|
||||
pipe_through :authenticate_client
|
||||
|
||||
scope "/r0" do
|
||||
|
@ -72,7 +72,7 @@ defmodule MatrixServerWeb.Router do
|
|||
end
|
||||
|
||||
# Authenticated federation endpoint.
|
||||
scope "/_matrix/federation", MatrixServerWeb.Federation do
|
||||
scope "/_matrix/federation", ArchitexWeb.Federation do
|
||||
pipe_through :authenticate_server
|
||||
|
||||
scope "/v1" do
|
||||
|
@ -83,7 +83,7 @@ defmodule MatrixServerWeb.Router do
|
|||
end
|
||||
end
|
||||
|
||||
scope "/", MatrixServerWeb.Client do
|
||||
scope "/", ArchitexWeb.Client do
|
||||
match :*, "/*path", InfoController, :unrecognized
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServerWeb.Telemetry do
|
||||
defmodule ArchitexWeb.Telemetry do
|
||||
use Supervisor
|
||||
import Telemetry.Metrics
|
||||
|
||||
|
@ -31,11 +31,11 @@ defmodule MatrixServerWeb.Telemetry do
|
|||
),
|
||||
|
||||
# Database Metrics
|
||||
summary("matrix_server.repo.query.total_time", unit: {:native, :millisecond}),
|
||||
summary("matrix_server.repo.query.decode_time", unit: {:native, :millisecond}),
|
||||
summary("matrix_server.repo.query.query_time", unit: {:native, :millisecond}),
|
||||
summary("matrix_server.repo.query.queue_time", unit: {:native, :millisecond}),
|
||||
summary("matrix_server.repo.query.idle_time", unit: {:native, :millisecond}),
|
||||
summary("architex.repo.query.total_time", unit: {:native, :millisecond}),
|
||||
summary("architex.repo.query.decode_time", unit: {:native, :millisecond}),
|
||||
summary("architex.repo.query.query_time", unit: {:native, :millisecond}),
|
||||
summary("architex.repo.query.queue_time", unit: {:native, :millisecond}),
|
||||
summary("architex.repo.query.idle_time", unit: {:native, :millisecond}),
|
||||
|
||||
# VM Metrics
|
||||
summary("vm.memory.total", unit: {:byte, :kilobyte}),
|
||||
|
@ -49,7 +49,7 @@ defmodule MatrixServerWeb.Telemetry do
|
|||
[
|
||||
# A module, function and arguments to be invoked periodically.
|
||||
# This function must call :telemetry.execute/3 and a metric must be added above.
|
||||
# {MatrixServerWeb, :count_users, []}
|
||||
# {ArchitexWeb, :count_users, []}
|
||||
]
|
||||
end
|
||||
end
|
|
@ -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
|
|
@ -1,5 +0,0 @@
|
|||
defmodule MatrixServer.Repo do
|
||||
use Ecto.Repo,
|
||||
otp_app: :matrix_server,
|
||||
adapter: Ecto.Adapters.Postgres
|
||||
end
|
6
mix.exs
6
mix.exs
|
@ -1,9 +1,9 @@
|
|||
defmodule MatrixServer.MixProject do
|
||||
defmodule Architex.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :matrix_server,
|
||||
app: :architex,
|
||||
version: "0.1.0",
|
||||
elixir: "~> 1.7",
|
||||
elixirc_paths: elixirc_paths(Mix.env()),
|
||||
|
@ -23,7 +23,7 @@ defmodule MatrixServer.MixProject do
|
|||
# Type `mix help compile.app` for more information.
|
||||
def application do
|
||||
[
|
||||
mod: {MatrixServer.Application, []},
|
||||
mod: {Architex.Application, []},
|
||||
extra_applications: [:logger, :runtime_tools]
|
||||
]
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServer.Repo.Migrations.CreateInitialTables do
|
||||
defmodule Architex.Repo.Migrations.CreateInitialTables do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
alias MatrixServer.{Repo, Account}
|
||||
alias Architex.{Repo, Account}
|
||||
|
||||
account =
|
||||
Repo.insert!(%Account{
|
||||
|
|
2
psql.sh
2
psql.sh
|
@ -1,2 +1,2 @@
|
|||
#!/bin/bash
|
||||
sudo -u postgres psql -d matrix_server_dev
|
||||
sudo -u postgres psql -d architex_dev
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
defmodule MatrixServerWeb.InfoControllerTest do
|
||||
use MatrixServerWeb.ConnCase
|
||||
defmodule ArchitexWeb.InfoControllerTest do
|
||||
use ArchitexWeb.ConnCase
|
||||
|
||||
test "versions endpoint returns a list of supported Matrix spec versions", %{conn: conn} do
|
||||
conn = get(conn, Routes.info_path(conn, :versions))
|
||||
|
@ -9,7 +9,7 @@ defmodule MatrixServerWeb.InfoControllerTest do
|
|||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
defmodule MatrixServerWeb.LoginControllerTest do
|
||||
use MatrixServerWeb.ConnCase
|
||||
defmodule ArchitexWeb.LoginControllerTest do
|
||||
use ArchitexWeb.ConnCase
|
||||
|
||||
alias MatrixServer.Factory
|
||||
alias MatrixServerWeb.Endpoint
|
||||
alias Architex.Factory
|
||||
alias ArchitexWeb.Endpoint
|
||||
|
||||
@basic_params %{
|
||||
"type" => "m.login.password",
|
||||
|
@ -31,7 +31,7 @@ defmodule MatrixServerWeb.LoginControllerTest do
|
|||
recycle(conn)
|
||||
|> post_json(Routes.login_path(Endpoint, :login), %{
|
||||
@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)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
defmodule MatrixServerWeb.RegisterControllerTest do
|
||||
use MatrixServerWeb.ConnCase
|
||||
defmodule ArchitexWeb.RegisterControllerTest do
|
||||
use ArchitexWeb.ConnCase
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
alias MatrixServer.{Repo, Device, Factory}
|
||||
alias MatrixServerWeb.Endpoint
|
||||
alias Architex.{Repo, Device, Factory}
|
||||
alias ArchitexWeb.Endpoint
|
||||
|
||||
@basic_params %{
|
||||
"username" => "user",
|
||||
|
@ -22,7 +22,7 @@ defmodule MatrixServerWeb.RegisterControllerTest do
|
|||
|
||||
test "registers account with minimal information", %{conn: conn} do
|
||||
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} =
|
||||
json_response(conn, 200)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServerWeb.ConnCase do
|
||||
defmodule ArchitexWeb.ConnCase do
|
||||
@moduledoc """
|
||||
This module defines the test case to be used by
|
||||
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
|
||||
are reverted at the end of every test. If you are using
|
||||
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.
|
||||
"""
|
||||
|
||||
|
@ -22,20 +22,20 @@ defmodule MatrixServerWeb.ConnCase do
|
|||
# Import conveniences for testing with connections
|
||||
import Plug.Conn
|
||||
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
|
||||
@endpoint MatrixServerWeb.Endpoint
|
||||
@endpoint ArchitexWeb.Endpoint
|
||||
end
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(MatrixServer.Repo)
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Architex.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(MatrixServer.Repo, {:shared, self()})
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Architex.Repo, {:shared, self()})
|
||||
end
|
||||
|
||||
{:ok, conn: Phoenix.ConnTest.build_conn()}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
defmodule MatrixServer.DataCase do
|
||||
defmodule Architex.DataCase do
|
||||
@moduledoc """
|
||||
This module defines the setup for tests requiring
|
||||
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
|
||||
are reverted at the end of every test. If you are using
|
||||
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.
|
||||
"""
|
||||
|
||||
|
@ -18,20 +18,20 @@ defmodule MatrixServer.DataCase do
|
|||
|
||||
using do
|
||||
quote do
|
||||
alias MatrixServer.Repo
|
||||
alias Architex.Repo
|
||||
|
||||
import Ecto
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
import MatrixServer.DataCase
|
||||
import Architex.DataCase
|
||||
end
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(MatrixServer.Repo)
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Architex.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(MatrixServer.Repo, {:shared, self()})
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Architex.Repo, {:shared, self()})
|
||||
end
|
||||
|
||||
:ok
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
defmodule MatrixServer.Factory do
|
||||
use ExMachina.Ecto, repo: MatrixServer.Repo
|
||||
defmodule Architex.Factory do
|
||||
use ExMachina.Ecto, repo: Architex.Repo
|
||||
|
||||
alias MatrixServer.{Account, Device}
|
||||
alias Architex.{Account, Device}
|
||||
|
||||
def account_factory do
|
||||
%Account{
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
ExUnit.start()
|
||||
Ecto.Adapters.SQL.Sandbox.mode(MatrixServer.Repo, :manual)
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Architex.Repo, :manual)
|
||||
|
|
Loading…
Reference in a new issue