[fix] recover lost contact requests and following messages

- Fetch discovery topic from offline inboxing
- Send ContactRequestResponse on discovery channel with new-key message
for recovery of invited contacts

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Eric Dvorsak 2018-05-07 01:33:21 +02:00 committed by Andrea Maria Piana
parent df901e8748
commit b7ab49d305
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 23 additions and 18 deletions

View File

@ -3,13 +3,14 @@
(:require [re-frame.core :as re-frame]
[status-im.native-module.core :as status]
[status-im.utils.handlers :as handlers]
[status-im.transport.utils :as web3.utils]
[status-im.transport.utils :as transport.utils]
[status-im.utils.config :as config]
[taoensso.timbre :as log]
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.utils :as utils]
[status-im.i18n :as i18n]
[day8.re-frame.async-flow-fx]))
[day8.re-frame.async-flow-fx]
[status-im.constants :as constants]))
(defn- parse-json
;; NOTE(dmitryn) Expects JSON response like:
@ -48,13 +49,13 @@
{:first-dispatch [:inbox/get-sym-key]
:rules [{:when :seen-both?
:events [:inbox/get-sym-key-success :inbox/connection-success]
:dispatch [:inbox/request-messages]}]})
:dispatch [:inbox/request-messages {:discover? true}]}]})
(defn recover-offline-inbox-flow []
{:first-dispatch [:inbox/fetch-peers]
:rules [{:when :seen?
:events :inbox/connection-success
:dispatch [:inbox/request-messages]}]})
:dispatch [:inbox/request-messages {:discover? true}]}]})
(defn initialize-offline-inbox
"Initialises offline inbox if inboxing enabled in config"
@ -96,11 +97,11 @@
(defn registered-peer? [peers enode]
(let [peer-ids (into #{} (map :id) peers)
enode-id (web3.utils/extract-enode-id enode)]
enode-id (transport.utils/extract-enode-id enode)]
(contains? peer-ids enode-id)))
(defn mark-trusted-peer [web3 enode success-fn error-fn]
(.markTrustedPeer (web3.utils/shh web3)
(.markTrustedPeer (transport.utils/shh web3)
enode
(fn [err resp]
(if-not err
@ -116,7 +117,7 @@
(doseq [topic topics]
(let [opts (assoc opts :topic topic)]
(log/info "offline inbox: request-messages args" (pr-str opts))
(.requestMessages (web3.utils/shh web3)
(.requestMessages (transport.utils/shh web3)
(clj->js opts)
(fn [err resp]
(if-not err
@ -215,7 +216,7 @@
(handlers/register-handler-fx
:inbox/request-messages
(fn [{:keys [db now]} [_ {:keys [from topics]}]]
(fn [{:keys [db now]} [_ {:keys [from topics discover?]}]]
(let [web3 (:web3 db)
wnode (get-current-wnode-address db)
topics (or topics
@ -223,7 +224,9 @@
from (or from (:inbox/last-request db) nil)
sym-key-id (:inbox/sym-key-id db)]
{::request-messages {:wnode wnode
:topics topics
:topics (if discover?
(conj topics (transport.utils/get-topic constants/contact-discovery))
topics)
;;TODO (yenda) fix from, right now mailserver is dropping us
;;when we send a requestMessage with a from field
;;:from from

View File

@ -45,10 +45,12 @@
(protocol/init-chat chat-id topic)
#_(protocol/requires-ack message-id chat-id))))
(receive [this chat-id signature {:keys [db] :as cofx}]
(let [message-id (transport.utils/message-id this)]
(let [message-id (transport.utils/message-id this)
topic (transport.utils/get-topic chat-id)]
(when (protocol/is-new? message-id)
(handlers-macro/merge-fx cofx
#_(protocol/ack message-id chat-id)
{:dispatch [:inbox/request-messages {:topics [topic]}]}
(contacts/receive-contact-request signature
this))))))