Enable partitioned topic

This commit is contained in:
Roman Volosovskyi 2019-03-05 10:14:39 +02:00
parent dc0d42ee6b
commit 7f76e2fbf0
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
12 changed files with 60 additions and 32 deletions

1
.env
View File

@ -18,3 +18,4 @@ POW_TIME=1
RN_BRIDGE_THRESHOLD_WARNINGS=0
RPC_NETWORKS_ONLY=0
STICKERS_ENABLED=1
PARTITIONED_TOPIC=1

View File

@ -15,3 +15,4 @@ POW_TARGET=0.002
POW_TIME=1
RN_BRIDGE_THRESHOLD_WARNINGS=0
STICKERS_ENABLED=0
PARTITIONED_TOPIC=1

View File

@ -18,3 +18,4 @@ POW_TIME=1
RN_BRIDGE_THRESHOLD_WARNINGS=0
RPC_NETWORKS_ONLY=0
STICKERS_ENABLED=1
PARTITIONED_TOPIC=1

View File

@ -16,3 +16,4 @@ POW_TIME=1
RN_BRIDGE_THRESHOLD_WARNINGS=0
RPC_NETWORKS_ONLY=0
STICKERS_ENABLED=0
PARTITIONED_TOPIC=1

View File

@ -15,3 +15,4 @@ POW_TARGET=0.002
POW_TIME=1
RN_BRIDGE_THRESHOLD_WARNINGS=0
STICKERS_ENABLED=0
PARTITIONED_TOPIC=1

View File

@ -16,3 +16,4 @@ POW_TIME=1
RN_BRIDGE_THRESHOLD_WARNINGS=0
RPC_NETWORKS_ONLY=1
STICKERS_ENABLED=0
PARTITIONED_TOPIC=1

View File

@ -56,6 +56,7 @@
[{:web3 web3
:src current-public-key
:dst public-key
:topics (get-in cofx [:db :mailserver/topics])
:payload ""}]}))
(re-frame/reg-fx

View File

@ -137,6 +137,7 @@
{:web3 web3
:src current-public-key
:dsts destinations
:available-topics (get-in cofx [:db :mailserver/topics])
:success-event [:transport/message-sent
chat-id
message-id

View File

@ -209,6 +209,7 @@
[{:web3 web3
:src current-public-key
:dst current-public-key
:topics (get-in cofx [:db :mailserver/topics])
:payload payload}]}))
(fx/defn send-installation-message-fx [cofx payload]

View File

@ -69,6 +69,7 @@
:success-event success-event
:src (accounts.db/current-public-key cofx)
:dst dst
:topics (:mailserver/topics db)
:payload payload}]}))
(fx/defn send-with-pubkey
@ -81,13 +82,18 @@
chat-id
success-event
payload)
(let [partitioned-topic-hash (transport.topic/public-key->discovery-topic-hash chat-id)
topics (db :mailserver/topics)
topic-hash (if (contains? topics partitioned-topic-hash)
partitioned-topic-hash
transport.topic/discovery-topic-hash)]
{:shh/post [{:web3 web3
:success-event success-event
:message (merge {:sig (accounts.db/current-public-key cofx)
:pubKey chat-id
:payload payload
:topic (transport.topic/public-key->discovery-topic-hash chat-id)}
whisper-opts)}]}))))
:topic topic-hash}
whisper-opts)}]})))))
(defrecord Message [content content-type message-type clock-value timestamp]
StatusMessage

View File

@ -37,6 +37,7 @@
partitioned-topic
utils/get-topic))
(def discovery-topic constants/contact-discovery)
(def discovery-topic-hash (utils/get-topic constants/contact-discovery))
(defn public-key->discovery-topic
@ -45,10 +46,15 @@
(partitioned-topic public-key)
constants/contact-discovery))
(defn public-key->discovery-topic-hash [public-key]
(defn public-key->discovery-topic-hash
[public-key]
(if config/partitioned-topic-enabled?
(partitioned-topic-hash public-key)
discovery-topic-hash))
(defn discovery-topics [public-key]
[(partitioned-topic-hash public-key) discovery-topic-hash])
(defn contains-topic?
[available-topics topic]
(contains? available-topics (utils/get-topic topic)))

View File

@ -80,11 +80,15 @@
(re-frame/reg-fx
:shh/send-direct-message
(fn [post-calls]
(doseq [{:keys [web3 payload src dst success-event error-event]
(doseq [{:keys [web3 payload src dst success-event error-event topics]
:or {error-event :transport/send-status-message-error}} post-calls]
(let [direct-message {:pubKey dst
(let [part-topic-hash (transport.topic/public-key->discovery-topic-hash dst)
topic (if (contains? topics part-topic-hash)
(transport.topic/public-key->discovery-topic dst)
transport.topic/discovery-topic)
direct-message {:pubKey dst
:sig src
:chat (transport.topic/public-key->discovery-topic dst)
:chat topic
:payload payload}]
(send-direct-message! web3 direct-message success-event error-event 1)))))
@ -107,12 +111,15 @@
(re-frame/reg-fx
:shh/send-group-message
(fn [params]
(let [{:keys [web3 payload chat src dsts success-event error-event]
(let [{:keys [web3 payload src dsts success-event error-event available-topics]
:or {error-event :transport/send-status-message-error}} params]
(doseq [{:keys [public-key chat]} dsts]
(let [message
(let [topic (if (transport.topic/contains-topic? available-topics chat)
chat
transport.topic/discovery-topic)
message
(clj->js {:pubKey public-key
:chat chat
:chat topic
:sig src
:payload (-> payload
transit/serialize