diff --git a/.env b/.env index ecf4252518..898935d330 100644 --- a/.env +++ b/.env @@ -9,3 +9,5 @@ LOG_LEVEL=debug LOG_LEVEL_STATUS_GO=info JSC_ENABLED=1 QUEUE_MESSAGE_ENABLED=1 +MANY_WHISPER_TOPICS_ENABLED=0 + diff --git a/.env.jenkins b/.env.jenkins index b8247e6498..0f02a5bb88 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -9,3 +9,4 @@ LOG_LEVEL=debug LOG_LEVEL_STATUS_GO=info JSC_ENABLED=1 QUEUE_MESSAGE_ENABLED=1 +MANY_WHISPER_TOPICS_ENABLED=0 \ No newline at end of file diff --git a/.env.prod b/.env.prod index da8af70d50..9ef13d1d18 100644 --- a/.env.prod +++ b/.env.prod @@ -8,4 +8,5 @@ OFFLINE_INBOX_MANY_ENABLED=0 LOG_LEVEL=info LOG_LEVEL_STATUS_GO=info JSC_ENABLED=0 -QUEUE_MESSAGE_ENABLED=0 \ No newline at end of file +QUEUE_MESSAGE_ENABLED=0 +MANY_WHISPER_TOPICS_ENABLED=0 diff --git a/Jenkinsfile.parameters b/Jenkinsfile.parameters index 9856a55171..b3929c0f8e 100644 --- a/Jenkinsfile.parameters +++ b/Jenkinsfile.parameters @@ -47,6 +47,7 @@ node ('macos1') { sh 'echo LOG_LEVEL_STATUS_GO=' + LOG_LEVEL_STATUS_GO + '>>' + '.env' sh 'echo JSC_ENABLED=' + JSC_ENABLED + '>>' + '.env' sh 'echo OFFLINE_INBOX_ENABLED=' + OFFLINE_INBOX_ENABLED + '>>' + '.env' + sh 'echo MANY_WHISPER_TOPICS_ENABLED=' + MANY_WHISPER_TOPICS_ENABLED + '>>' + '.env' sh 'echo "**********************************************************************"' sh 'echo PARAMETERIZED BUILD - USING CUSTOM ENVIRONMENT' diff --git a/src/status_im/protocol/chat.cljs b/src/status_im/protocol/chat.cljs index 0590c7d9f8..a6726e2f4f 100644 --- a/src/status_im/protocol/chat.cljs +++ b/src/status_im/protocol/chat.cljs @@ -2,7 +2,7 @@ (:require [cljs.spec.alpha :as s] [status-im.protocol.web3.filtering :as f] [status-im.protocol.web3.delivery :as d] - [taoensso.timbre :refer-macros [debug]] + [taoensso.timbre :refer-macros [debug] :as log] [status-im.protocol.validation :refer-macros [valid?]])) (def message-defaults @@ -17,10 +17,11 @@ (defn send! [{:keys [web3 message]}] {:pre [(valid? ::user-message message)]} - (let [message' (merge message-defaults - (assoc message - :type :message - :requires-ack? true))] + (let [topics (f/get-topics (:to message)) + message' (assoc message + :topics topics + :type :message + :requires-ack? true)] (debug :send-user-message message') (d/add-pending-message! web3 message'))) diff --git a/src/status_im/protocol/core.cljs b/src/status_im/protocol/core.cljs index 583e890068..e4d0f13443 100644 --- a/src/status_im/protocol/core.cljs +++ b/src/status_im/protocol/core.cljs @@ -98,13 +98,13 @@ web3 {:key identity :allowP2P true - :topics [f/status-topic]} + :topics (f/get-topics identity)} (l/message-listener listener-options)) (inbox/initialize! web3)) (f/add-filter! web3 {:key identity - :topics [f/status-topic]} + :topics (f/get-topics identity)} (l/message-listener listener-options))) ;; start listening to profiles diff --git a/src/status_im/protocol/web3/filtering.cljs b/src/status_im/protocol/web3/filtering.cljs index 08372d2106..316702ea0e 100644 --- a/src/status_im/protocol/web3/filtering.cljs +++ b/src/status_im/protocol/web3/filtering.cljs @@ -1,11 +1,32 @@ (ns status-im.protocol.web3.filtering (:require [status-im.protocol.web3.utils :as u] + [status-im.utils.config :as config] [cljs.spec.alpha :as s] [taoensso.timbre :as log])) +;; XXX(oskarth): Perf issue to have one topic +;; See https://github.com/status-im/ideas/issues/55#issuecomment-355511183 (def status-topic "0xaabb11ee") + (defonce filters (atom {})) +;; NOTE(oskarth): This has concerns for upgradability and chatting cross +;; versions. How can we do this breaking change gradually? + +;; NOTE(oskarth): Due to perf we don't want a single topic for all messages, +;; instead we want many. We need a way for user A and B to agree on which topics +;; to use. By using first 10 characters of the pub-key, we construct a topic +;; that requires no coordination for 1-1 chats. +(defn identity->topic [identity] + (apply str (take 10 identity))) + +(defn get-topics [& [identity]] + (if config/many-whisper-topics-enabled? + (do (log/info "FLAG: many-whisper-topics-enabled ON") + [(identity->topic identity)]) + (do (log/info "FLAG: many-whisper-topics-enabled OFF") + [status-topic]))) + (s/def ::options (s/keys :opt-un [:message/to :message/topics])) (defn remove-filter! [web3 options] diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index 000e0e2d14..9441dc2b1e 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -32,3 +32,4 @@ (def jsc-enabled? (enabled? (get-config :JSC_ENABLED 0))) (def queue-message-enabled? (enabled? (get-config :QUEUE_MESSAGE_ENABLED 0))) +(def many-whisper-topics-enabled? (enabled? (get-config :MANY_WHISPER_TOPICS_ENABLED 0)))