Explicitly start messenger

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>
This commit is contained in:
Andrea Maria Piana 2020-01-29 16:57:12 +01:00
parent 128f44f58b
commit 6ff878c836
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
6 changed files with 25 additions and 8 deletions

View File

@ -31,6 +31,7 @@
"shh_generateSymKeyFromPassword" {}
"shh_getSymKey" {}
"shh_markTrustedPeer" {}
"shhext_startMessenger" {}
"shhext_sendPairInstallation" {}
"shhext_syncDevices" {}
"shhext_requestMessages" {}

View File

@ -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))))))))

View File

@ -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))))
@ -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)

View File

@ -68,4 +68,4 @@
(not initialization-complete?)
(assoc :initialization-protocol initialization-protocol))}
(when initialization-complete?
(transport/init-whisper)))))
(transport/init-messenger)))))

View File

@ -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]
@ -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)

View File

@ -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"
}