Skip to content

Commit

Permalink
Explicitly start messenger
Browse files Browse the repository at this point in the history
We should only start receiving messages/processing topics once all the
initializiation is completed, so an endpoint that start the messenger
has been added.
Before we would initialize the topics/receiving messages at the same time,
which resulted in a race condition where a topic was signaled from
status-go and was considered new just because was not loaded yet.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
  • Loading branch information
cammellos committed Jan 29, 2020
1 parent 128f44f commit 6ff878c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/status_im/ethereum/json_rpc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"shh_generateSymKeyFromPassword" {}
"shh_getSymKey" {}
"shh_markTrustedPeer" {}
"shhext_startMessenger" {}
"shhext_sendPairInstallation" {}
"shhext_syncDevices" {}
"shhext_requestMessages" {}
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/mailserver/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@
:on-success
#(log/debug "added mailserver-topic successfully")
:on-failure
#(log/error "failed to delete mailserver topic" %)})
#(log/error "failed to add mailserver topic" %)})
mailserver-topics)}
(process-next-messages-request))))))))

Expand Down
8 changes: 5 additions & 3 deletions src/status_im/mailserver/topics.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
[status-im.utils.fx :as fx]
[taoensso.timbre :as log]))

(defn calculate-last-request [{:keys [discovery?]}
(defn calculate-last-request [{:keys [negotiated?
discovery?]}
{:keys [previous-last-request
now-s]}]
;; New topic, if discovery we don't fetch history
(if (and (nil? previous-last-request)
discovery?)
(or discovery?
negotiated?))
(- now-s 10)
(max previous-last-request
(- now-s constants/max-request-range))))
Expand All @@ -34,7 +36,7 @@
{::json-rpc/call [{:method "mailservers_addMailserverTopic"
:params [mailserver-topic]
:on-success #(log/debug "added mailserver-topic successfully")
:on-failure #(log/error "failed to delete mailserver topic" %)}]}))
:on-failure #(log/error "failed to add mailserver topic" %)}]}))

(defn new-chat-ids? [previous-mailserver-topic new-mailserver-topic]
(seq (clojure.set/difference (:chat-ids new-mailserver-topic)
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/protocol/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@
(not initialization-complete?)
(assoc :initialization-protocol initialization-protocol))}
(when initialization-complete?
(transport/init-whisper)))))
(transport/init-messenger)))))
14 changes: 14 additions & 0 deletions src/status_im/transport/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
status-im.transport.core
(:require
[re-frame.core :as re-frame]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.native-module.core :as status]
[status-im.mailserver.core :as mailserver]
[status-im.transport.message.core :as message]
Expand Down Expand Up @@ -34,10 +35,23 @@
(fx/defn fetch-node-info-fx [cofx]
{::fetch-node-info []})

(fx/defn init-messenger
"We should only start receiving messages/processing topics once all the
initializiation is completed, otherwise we might receive messages/topics
when the state has not been properly initialized."
[cofx]
{::json-rpc/call [{:method "shhext_startMessenger"
:on-success #(do
(log/debug "messenger initialized")
(re-frame/dispatch [::init-whisper]))
:on-failure #(log/error "failed to init messenger")}]})

(fx/defn init-whisper
"Initialises whisper protocol by:
- (optionally) initializing mailserver"
{:events [::init-whisper]}
[cofx]
(log/debug "Initializing whisper")
(fx/merge cofx
(fetch-node-info-fx)
(pairing/init)
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.40.0",
"commit-sha1": "dc31c818fce6dbff6cfd76da09d901b0df742e2e",
"src-sha256": "1f0fp5c4lqnh244wcvbnl5i4p9fb0f3i0rjjvbiqwkz9zwwp3xlv"
"version": "v0.41.0",
"commit-sha1": "8931b14c4e40261e6161a3c776bf16cc0fdd1f3a",
"src-sha256": "16r3xbzhh3fljpx11yahm1r5xh4cyvggy5avg6smkpw9m93cb6f7"
}

0 comments on commit 6ff878c

Please sign in to comment.