diff --git a/assets/js/user_socket.js b/assets/js/user_socket.js
index 3e0e94b..1b61fe5 100644
--- a/assets/js/user_socket.js
+++ b/assets/js/user_socket.js
@@ -57,8 +57,9 @@ let channel = socket.channel('room:lobby', {}); // connect to chat "room"
channel.on('shout', function (payload) { // listen to the 'shout' event
let li = document.createElement("li"); // create new list item DOM element
- let name = payload.name || 'guest'; // get name from payload or set default
- li.innerHTML = '' + name + ': ' + payload.message; // set li contents
+ let source = payload.source || "";
+ let name = payload.name || 'guest';
+ li.innerHTML = '' + source + ' :: ' + name + ': ' + payload.message; // set li contents
ul.appendChild(li); // append to list
});
diff --git a/config/config.exs b/config/config.exs
index c187d63..6052d67 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -16,7 +16,6 @@ config :chat, ChatWeb.Endpoint,
config :floof,
listen_port: nil,
- pubkey_config: %{:keydb => "data/keydb"},
spool_dir: "data/spool",
sessions_file: "data/sessions.dets"
diff --git a/lib/chat/application.ex b/lib/chat/application.ex
index e0351c7..5775098 100644
--- a/lib/chat/application.ex
+++ b/lib/chat/application.ex
@@ -43,14 +43,12 @@ defmodule Chat.Application do
defp relay_loop do
receive do
- {:fwdxfer, {_, {:XferBlob, source, _, _, _, xfinner}}} ->
+ {:fwdxfer, {_, {:XferBlob, _, _, {:Signature, _, source, _}, xfinner}}} ->
{:ok, dcdi} = :FloofProtocol.decode(:XferInner, xfinner)
{:XferInner, topic, attrs, _, data} = dcdi
if topic == [{:RelativeDistinguishedName, {0, 9, 2342, 19200300, 100, 1, 14}, "Chat"}] do
[{:RelativeDistinguishedName, {0, 9, 2342, 19200300, 100, 1, 4}, name}] = attrs
- {:ok, source_encd} = :FloofProtocol.encode(:RDNSequence, source)
- source_encd = Base.url_encode64(source_encd)
- ChatWeb.Endpoint.broadcast!("room:lobby", "shout", %{"name" => source_encd <> " :: " <> name, "message" => data})
+ ChatWeb.Endpoint.broadcast!("room:lobby", "shout", %{"source" => Base.url_encode64(source), "name" => name, "message" => data})
end
x -> Logger.error("unable to handle message #{inspect(x)}")
end
diff --git a/lib/chat/floof.ex b/lib/chat/floof.ex
index 041e1b8..1f1b2d4 100644
--- a/lib/chat/floof.ex
+++ b/lib/chat/floof.ex
@@ -2,14 +2,13 @@ defmodule Chat.Floof do
use Agent
require Logger
- defstruct secret: "", source: []
+ defstruct secret: ""
def start_link([]) do
Agent.start_link(fn ->
secret_file = Application.fetch_env!(:chat, :secret_file)
- source = Application.fetch_env!(:chat, :source)
{:ok, secret} = File.read(secret_file)
- %Chat.Floof{secret: secret, source: source}
+ %Chat.Floof{secret: secret}
end, name: __MODULE__)
end
@@ -17,11 +16,7 @@ defmodule Chat.Floof do
# generate and save a keypair
kp = :enacl.sign_keypair()
secret_file = Application.fetch_env!(:chat, :secret_file)
- source = Application.fetch_env!(:chat, :source)
:ok = File.write(secret_file, kp.secret)
- {:ok, pkname} = :FloofProtocol.encode(:RDNSequence, source)
- pubkey_config = Application.fetch_env!(:floof, :pubkey_config)
- :ok = File.write(pubkey_config.keydb <> "/" <> Base.url_encode64(pkname), kp.public)
end
def send_message(name, data) do
@@ -29,7 +24,7 @@ defmodule Chat.Floof do
msg_attrs = [{:RelativeDistinguishedName, {0, 9, 2342, 19200300, 100, 1, 4}, name}]
msg_inner = Floof.Message.pack_inner(msg_topic, msg_attrs, :info, data)
Agent.cast(__MODULE__, fn state ->
- msg_outer = Floof.Message.build_outer(state.source, 255, [], state.secret, msg_inner)
+ msg_outer = Floof.Message.build_outer(255, [], state.secret, msg_inner)
Floof.Message.emit(msg_outer)
state
end)
diff --git a/lib/chat_web/channels/room_channel.ex b/lib/chat_web/channels/room_channel.ex
index 2c15d22..40a2ba9 100644
--- a/lib/chat_web/channels/room_channel.ex
+++ b/lib/chat_web/channels/room_channel.ex
@@ -22,7 +22,8 @@ defmodule ChatWeb.RoomChannel do
@impl true
def handle_in("shout", payload, socket) do
Chat.Floof.send_message(payload["name"], payload["message"])
- broadcast(socket, "shout", payload)
+ # floof broadcasts back into the channel with correct `source` attached
+ #broadcast(socket, "shout", payload)
{:noreply, socket}
end
diff --git a/mix.lock b/mix.lock
index 4ecce2d..849c627 100644
--- a/mix.lock
+++ b/mix.lock
@@ -7,7 +7,7 @@
"esbuild": {:hex, :esbuild, "0.5.0", "d5bb08ff049d7880ee3609ed5c4b864bd2f46445ea40b16b4acead724fb4c4a3", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "f183a0b332d963c4cfaf585477695ea59eef9a6f2204fdd0efa00e099694ffe5"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"floki": {:hex, :floki, "0.34.0", "002d0cc194b48794d74711731db004fafeb328fe676976f160685262d43706a8", [:mix], [], "hexpm", "9c3a9f43f40dde00332a589bd9d389b90c1f518aef500364d00636acc5ebc99c"},
- "floof": {:git, "https://git.exozy.me/zseri/floof.git", "6b2c5b2695c5bd153326354799265eaf55015cd5", []},
+ "floof": {:git, "https://git.exozy.me/zseri/floof.git", "740bee0073d3281a358ebb74585989c3b0303dd9", []},
"gettext": {:hex, :gettext, "0.20.0", "75ad71de05f2ef56991dbae224d35c68b098dd0e26918def5bb45591d5c8d429", [:mix], [], "hexpm", "1c03b177435e93a47441d7f681a7040bd2a816ece9e2666d1c9001035121eb3d"},
"jason": {:hex, :jason, "1.4.0", "e855647bc964a44e2f67df589ccf49105ae039d4179db7f6271dfd3843dc27e6", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "79a3791085b2a0f743ca04cec0f7be26443738779d09302e01318f97bdb82121"},
"mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"},