diff --git a/.env b/.env index d479b8445f..c6654bd60c 100644 --- a/.env +++ b/.env @@ -18,3 +18,4 @@ POW_TIME=1 RN_BRIDGE_THRESHOLD_WARNINGS=0 RPC_NETWORKS_ONLY=0 STICKERS_ENABLED=1 +PARTITIONED_TOPIC=1 diff --git a/.env.e2e b/.env.e2e index 25d38f3bc6..5371f7b7dc 100644 --- a/.env.e2e +++ b/.env.e2e @@ -15,3 +15,4 @@ POW_TARGET=0.002 POW_TIME=1 RN_BRIDGE_THRESHOLD_WARNINGS=0 STICKERS_ENABLED=0 +PARTITIONED_TOPIC=1 diff --git a/.env.jenkins b/.env.jenkins index c228c3a7e5..02c2f28432 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -18,3 +18,4 @@ POW_TIME=1 RN_BRIDGE_THRESHOLD_WARNINGS=0 RPC_NETWORKS_ONLY=0 STICKERS_ENABLED=1 +PARTITIONED_TOPIC=1 diff --git a/.env.nightly b/.env.nightly index d9c562f193..c7fae9dd71 100644 --- a/.env.nightly +++ b/.env.nightly @@ -16,3 +16,4 @@ POW_TIME=1 RN_BRIDGE_THRESHOLD_WARNINGS=0 RPC_NETWORKS_ONLY=0 STICKERS_ENABLED=0 +PARTITIONED_TOPIC=1 diff --git a/.env.nightly.staging.fleet b/.env.nightly.staging.fleet index 67f7301b4d..1a707891aa 100644 --- a/.env.nightly.staging.fleet +++ b/.env.nightly.staging.fleet @@ -15,3 +15,4 @@ POW_TARGET=0.002 POW_TIME=1 RN_BRIDGE_THRESHOLD_WARNINGS=0 STICKERS_ENABLED=0 +PARTITIONED_TOPIC=1 diff --git a/.env.prod b/.env.prod index b886665d59..6893f26de5 100644 --- a/.env.prod +++ b/.env.prod @@ -16,3 +16,4 @@ POW_TIME=1 RN_BRIDGE_THRESHOLD_WARNINGS=0 RPC_NETWORKS_ONLY=1 STICKERS_ENABLED=0 +PARTITIONED_TOPIC=1 diff --git a/src/status_im/contact_recovery/core.cljs b/src/status_im/contact_recovery/core.cljs index 10665f00e6..91e21e0018 100644 --- a/src/status_im/contact_recovery/core.cljs +++ b/src/status_im/contact_recovery/core.cljs @@ -53,9 +53,10 @@ (let [{:keys [web3]} (:db cofx) current-public-key (accounts.db/current-public-key cofx)] {:shh/send-direct-message - [{:web3 web3 - :src current-public-key - :dst public-key + [{:web3 web3 + :src current-public-key + :dst public-key + :topics (get-in cofx [:db :mailserver/topics]) :payload ""}]})) (re-frame/reg-fx diff --git a/src/status_im/group_chats/core.cljs b/src/status_im/group_chats/core.cljs index 3d80868fd8..4182e89fff 100644 --- a/src/status_im/group_chats/core.cljs +++ b/src/status_im/group_chats/core.cljs @@ -134,14 +134,15 @@ (fx/merge cofx {:shh/send-group-message - {:web3 web3 - :src current-public-key - :dsts destinations - :success-event [:transport/message-sent - chat-id - message-id - :group-user-message] - :payload payload}})))) + {: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 + :group-user-message] + :payload payload}})))) (fx/defn handle-membership-update-received "Extract signatures in status-go and act if successful" diff --git a/src/status_im/pairing/core.cljs b/src/status_im/pairing/core.cljs index ed43b7caac..8b026c4d11 100644 --- a/src/status_im/pairing/core.cljs +++ b/src/status_im/pairing/core.cljs @@ -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] diff --git a/src/status_im/transport/message/protocol.cljs b/src/status_im/transport/message/protocol.cljs index 25e738dd1e..60b45fb141 100644 --- a/src/status_im/transport/message/protocol.cljs +++ b/src/status_im/transport/message/protocol.cljs @@ -65,11 +65,12 @@ "Sends the payload using to dst" [{:keys [db] :as cofx} dst success-event payload] (let [{:keys [web3]} db] - {:shh/send-direct-message [{:web3 web3 - :success-event success-event - :src (accounts.db/current-public-key cofx) - :dst dst - :payload payload}]})) + {:shh/send-direct-message [{:web3 web3 + :success-event success-event + :src (accounts.db/current-public-key cofx) + :dst dst + :topics (:mailserver/topics db) + :payload payload}]})) (fx/defn send-with-pubkey "Sends the payload using asymetric key (account `:public-key` in db) and fixed discovery topic" @@ -81,13 +82,18 @@ chat-id success-event payload) - {: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)}]})))) + (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 topic-hash} + whisper-opts)}]}))))) (defrecord Message [content content-type message-type clock-value timestamp] StatusMessage diff --git a/src/status_im/transport/partitioned_topic.cljs b/src/status_im/transport/partitioned_topic.cljs index 82d2384fd0..ce6a6ae9d5 100644 --- a/src/status_im/transport/partitioned_topic.cljs +++ b/src/status_im/transport/partitioned_topic.cljs @@ -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))) diff --git a/src/status_im/transport/shh.cljs b/src/status_im/transport/shh.cljs index 7b1f9d0694..78d69aee77 100644 --- a/src/status_im/transport/shh.cljs +++ b/src/status_im/transport/shh.cljs @@ -80,12 +80,16 @@ (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 - :sig src - :chat (transport.topic/public-key->discovery-topic dst) - :payload payload}] + (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 topic + :payload payload}] (send-direct-message! web3 direct-message success-event error-event 1))))) (re-frame/reg-fx @@ -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