Adjust from value to accomodate for late-comers

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Andrea Maria Piana 2018-12-12 16:56:57 +01:00 committed by Igor Mandrigin
parent fdb808a7dc
commit 8be8f0b5c8
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
2 changed files with 42 additions and 23 deletions

View File

@ -11,6 +11,7 @@
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.transport.db :as transport.db] [status-im.transport.db :as transport.db]
[status-im.transport.message.protocol :as protocol]
[clojure.string :as string] [clojure.string :as string]
[status-im.data-store.mailservers :as data-store.mailservers] [status-im.data-store.mailservers :as data-store.mailservers]
[status-im.i18n :as i18n] [status-im.i18n :as i18n]
@ -236,26 +237,41 @@
(def limit 200) (def limit 200)
(defn adjust-request-for-transit-time
[from]
(let [ttl (:ttl protocol/whisper-opts)
whisper-tolerance (:whisper-drift-tolerance protocol/whisper-opts)
adjustment (+ whisper-tolerance ttl)
adjusted-from (- (max from adjustment) adjustment)]
(log/debug "Adjusting mailserver request" "from:" from "adjusted-from:" adjusted-from)
adjusted-from))
(defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics cursor to from]}] (defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics cursor to from]}]
(log/info "mailserver: request-messages for: " ;; Add some room to from, unless we break day boundaries so that messages that have
" topics " topics ;; been received after the last request are also fetched
" from " from (let [adjusted-from (adjust-request-for-transit-time from)
" cursor " cursor actual-from (if (> (- to adjusted-from) one-day)
" limit " limit from
" to " to) adjusted-from)]
(.requestMessages (transport.utils/shh web3) (log/info "mailserver: request-messages for: "
(clj->js {:topics topics " topics " topics
:mailServerPeer address " from " actual-from
:symKeyID sym-key-id " cursor " cursor
:timeout request-timeout " limit " limit
:limit limit " to " to)
:cursor cursor (.requestMessages (transport.utils/shh web3)
:from from (clj->js {:topics topics
:to to}) :mailServerPeer address
(fn [error request-id] :symKeyID sym-key-id
(if-not error :timeout request-timeout
(log/info "mailserver: messages request success for topic " topics "from" from "to" to) :limit limit
(log/error "mailserver: messages request error for topic " topics ": " error))))) :cursor cursor
:from actual-from
:to to})
(fn [error request-id]
(if-not error
(log/info "mailserver: messages request success for topic " topics "from" from "to" to)
(log/error "mailserver: messages request error for topic " topics ": " error))))))
(re-frame/reg-fx (re-frame/reg-fx
:mailserver/request-messages :mailserver/request-messages

View File

@ -16,10 +16,13 @@
(receive [this chat-id signature timestamp cofx] "Method producing all effects necessary for receiving the message record") (receive [this chat-id signature timestamp cofx] "Method producing all effects necessary for receiving the message record")
(validate [this] "Method returning the message if it is valid or nil if it is not")) (validate [this] "Method returning the message if it is valid or nil if it is not"))
(def ^:private whisper-opts (def whisper-opts
{:ttl 10 ;; ttl of 10 sec {;; time drift that is tolerated by whisper, in seconds
:powTarget config/pow-target :whisper-drift-tolerance 10
:powTime config/pow-time}) ;; ttl of 10 sec
:ttl 10
:powTarget config/pow-target
:powTime config/pow-time})
(fx/defn init-chat (fx/defn init-chat
"Initialises chat on protocol layer. "Initialises chat on protocol layer.