[fix 3806] Provide separate MailServers for each network

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Eric Dvorsak 2018-04-12 20:04:00 +02:00 committed by Andrey Shovkoplyas
parent 4de886241c
commit 3612fd8c47
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
13 changed files with 72 additions and 67 deletions

View File

@ -38,7 +38,9 @@
(def default-account-settings (def default-account-settings
{:wallet {:visible-tokens {:testnet #{:STT} {:wallet {:visible-tokens {:testnet #{:STT}
:mainnet #{:SNT}}}}) :mainnet #{:SNT}}}
:wnode {:testnet "main"
:mainnet "main"}})
(defn- transform-config [networks] (defn- transform-config [networks]
(->> networks (->> networks
@ -87,19 +89,17 @@
(merge testnet-networks (merge testnet-networks
(when config/mainnet-networks-enabled? mainnet-networks)))) (when config/mainnet-networks-enabled? mainnet-networks))))
;; adamb's status-cluster enode
(def default-wnode "main")
(def default-wnodes (def default-wnodes
{"main" {:id "main" {:testnet {"main" {:id "main"
:name "Status mailserver A" :name "Status testnet mailserver A"
:address "enode://fa63a6cc730468c5456eab365b2a7a68a166845423c8c9acc363e5f8c4699ff6d954e7ec58f13ae49568600cff9899561b54f6fc2b9923136cd7104911f31cce@163.172.168.202:30303"} :address "enode://fa63a6cc730468c5456eab365b2a7a68a166845423c8c9acc363e5f8c4699ff6d954e7ec58f13ae49568600cff9899561b54f6fc2b9923136cd7104911f31cce@163.172.168.202:30303"}
"backup" {:id "backup" "backup" {:id "backup"
:name "Status mailserver B" :name "Status testnet mailserver B"
:address "enode://90cbf961c87eb837adc1300a0a6722a57134d843f0028a976d35dff387f101a2754842b6b694e50a01093808f304440d4d968bcbc599259e895ff26e5a1a17cf@51.15.194.39:30303"}}) :address "enode://90cbf961c87eb837adc1300a0a6722a57134d843f0028a976d35dff387f101a2754842b6b694e50a01093808f304440d4d968bcbc599259e895ff26e5a1a17cf@51.15.194.39:30303"}}
:mainnet {"main" {:id "main"
:name "Status mainnet mailserver"
:address "enode://b963569aac14785f756ecf97e7549a513dea993a1bc744c4f8efe2b4e9479500dd3f5d18f3da19f6550b8bd0d8770350950c9a7da8168b44865402dcc9a51657@51.15.35.110:30403"}}})
;; TODO(oskarth): Determine if this is the correct topic or not
(def inbox-topic "0xaabb11ee")
(def inbox-password "status-offline-inbox") (def inbox-password "status-offline-inbox")
;; Used to generate topic for contact discoveries ;; Used to generate topic for contact discoveries

View File

@ -18,7 +18,6 @@
:network :string :network :string
:networks {:type :list :networks {:type :list
:objectType :network} :objectType :network}
:wnode :string
:settings {:type :string} :settings {:type :string}
:sharing-usage-data? {:type :bool :default false} :sharing-usage-data? {:type :bool :default false}
:dev-mode? {:type :bool :default false} :dev-mode? {:type :bool :default false}

View File

@ -5,7 +5,8 @@
[status-im.utils.handlers :as handlers] [status-im.utils.handlers :as handlers]
[status-im.transport.utils :as web3.utils] [status-im.transport.utils :as web3.utils]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[status-im.utils.ethereum.core :as ethereum]))
(defn- parse-json (defn- parse-json
;; NOTE(dmitryn) Expects JSON response like: ;; NOTE(dmitryn) Expects JSON response like:
@ -35,14 +36,18 @@
(error-fn error) (error-fn error)
(success-fn result))))) (success-fn result)))))
(defn get-current-wnode-address [{:accounts/keys [current-account-id accounts] :as db}]
(let [network (ethereum/network->chain-keyword (get db :network))
wnode-id (get-in accounts [current-account-id :settings :wnode network])]
(get-in db [:inbox/wnodes network wnode-id :address])))
(defn initialize-offline-inbox (defn initialize-offline-inbox
"Initialises offline inbox by producing `::add-peer` effect if inboxing enabled in config, "Initialises offline inbox by producing `::add-peer` effect if inboxing enabled in config,
then the event chan is: then the event chan is:
add-peer -> fetch-peers -> check-peer-added -> mark-trusted-peer -> get-sym-key -> request-messages" add-peer -> fetch-peers -> check-peer-added -> mark-trusted-peer -> get-sym-key -> request-messages"
[{:keys [db]}] [{:keys [db]}]
(when config/offline-inbox-enabled? (when config/offline-inbox-enabled?
(let [wnode-id (get db :inbox/wnode) (let [wnode (get-current-wnode-address db)]
wnode (get-in db [:inbox/wnodes wnode-id :address])]
(log/info "offline inbox: initialize") (log/info "offline inbox: initialize")
{::add-peer {:wnode wnode}}))) {::add-peer {:wnode wnode}})))
@ -91,10 +96,6 @@
(success-fn resp) (success-fn resp)
(error-fn err topic)))))))) (error-fn err topic))))))))
(defn get-wnode [db]
(let [wnode-id (get db :inbox/wnode)]
(get-in db [:inbox/wnodes wnode-id :address])))
(re-frame/reg-fx (re-frame/reg-fx
::add-peer ::add-peer
(fn [{:keys [wnode]}] (fn [{:keys [wnode]}]
@ -144,7 +145,7 @@
;; if not we dispatch a new fetch-peer event for later ;; if not we dispatch a new fetch-peer event for later
(fn [{:keys [db]} [_ peers retries]] (fn [{:keys [db]} [_ peers retries]]
(let [web3 (:web3 db) (let [web3 (:web3 db)
wnode (get-wnode db)] wnode (get-current-wnode-address db)]
(log/info "offline inbox: fetch-peers response" peers) (log/info "offline inbox: fetch-peers response" peers)
(if (registered-peer? peers wnode) (if (registered-peer? peers wnode)
{::mark-trusted-peer {:web3 web3 {::mark-trusted-peer {:web3 web3
@ -163,7 +164,7 @@
;; with add-peer ;; with add-peer
(fn [{:keys [db]} [_ response]] (fn [{:keys [db]} [_ response]]
(let [web3 (:web3 db) (let [web3 (:web3 db)
wnode (get-wnode db) wnode (get-current-wnode-address db)
password (:inbox/password db)] password (:inbox/password db)]
(log/info "offline inbox: mark-trusted-peer response" wnode response) (log/info "offline inbox: mark-trusted-peer response" wnode response)
{:shh/generate-sym-key-from-password {:password password {:shh/generate-sym-key-from-password {:password password
@ -179,7 +180,7 @@
(fn [{:keys [db]} [_ sym-key-id]] (fn [{:keys [db]} [_ sym-key-id]]
(log/info "offline inbox: get-sym-key response") sym-key-id (log/info "offline inbox: get-sym-key response") sym-key-id
(let [web3 (:web3 db) (let [web3 (:web3 db)
wnode (get-wnode db) wnode (get-current-wnode-address db)
topics (map #(:topic %) (vals (:transport/chats db))) topics (map #(:topic %) (vals (:transport/chats db)))
to nil to nil
from nil] from nil]

View File

@ -49,11 +49,10 @@
(defn add-account (defn add-account
"Takes db and new account, creates map of effects describing adding account to database and realm" "Takes db and new account, creates map of effects describing adding account to database and realm"
[{:keys [network inbox/wnode] :networks/keys [networks] :as db} {:keys [address] :as account}] [{:keys [network] :networks/keys [networks] :as db} {:keys [address] :as account}]
(let [enriched-account (assoc account (let [enriched-account (assoc account
:network network :network network
:networks networks :networks networks
:wnode wnode
:address address)] :address address)]
{:db (assoc-in db [:accounts/accounts address] enriched-account) {:db (assoc-in db [:accounts/accounts address] enriched-account)
:data-store/save-account enriched-account})) :data-store/save-account enriched-account}))
@ -106,10 +105,11 @@
{:db (assoc-in db [:accounts/accounts id] new-account) {:db (assoc-in db [:accounts/accounts id] new-account)
:data-store/save-account new-account}))) :data-store/save-account new-account})))
(defn update-wallet-settings [{:accounts/keys [current-account-id accounts] :as db} settings] (defn update-settings [settings {:keys [db] :as cofx}]
(let [new-account (-> (get accounts current-account-id) (let [{:accounts/keys [current-account-id accounts]} db
(assoc :settings settings))] new-account (-> (get accounts current-account-id)
{:db (assoc-in db [:accounts/accounts current-account-id] new-account) (assoc :settings settings))]
{:db (assoc-in db [:accounts/accounts current-account-id] new-account)
:data-store/save-account new-account})) :data-store/save-account new-account}))
(defn account-update (defn account-update

View File

@ -67,9 +67,6 @@
{:network network {:network network
:config config})) :config config}))
(defn get-wnode-by-address [db address]
(get-in db [:accounts/accounts address :wnode] constants/default-wnode))
(defn wrap-with-initialize-geth-fx [db address password] (defn wrap-with-initialize-geth-fx [db address password]
(let [{:keys [network config]} (get-network-by-address db address)] (let [{:keys [network config]} (get-network-by-address db address)]
{:initialize-geth-fx config {:initialize-geth-fx config
@ -91,9 +88,7 @@
:login-account :login-account
(fn [{{:keys [network status-node-started?] :as db} :db} [_ address password]] (fn [{{:keys [network status-node-started?] :as db} :db} [_ address password]]
(let [{account-network :network} (get-network-by-address db address) (let [{account-network :network} (get-network-by-address db address)
wnode (get-wnode-by-address db address)
db' (-> db db' (-> db
(assoc :inbox/wnode wnode)
(assoc-in [:accounts/login :processing] true)) (assoc-in [:accounts/login :processing] true))
wrap-fn (cond (not status-node-started?) wrap-fn (cond (not status-node-started?)
wrap-with-initialize-geth-fx wrap-with-initialize-geth-fx

View File

@ -41,9 +41,7 @@
:notifications {} :notifications {}
:network constants/default-network :network constants/default-network
:networks/networks constants/default-networks :networks/networks constants/default-networks
:inbox/wnode constants/default-wnode
:inbox/wnodes constants/default-wnodes :inbox/wnodes constants/default-wnodes
:inbox/topic constants/inbox-topic
:inbox/password constants/inbox-password :inbox/password constants/inbox-password
:my-profile/editing? false :my-profile/editing? false
:transport/chats {} :transport/chats {}
@ -162,9 +160,7 @@
:networks/networks :networks/networks
:node/after-start :node/after-start
:node/after-stop :node/after-stop
:inbox/wnode
:inbox/wnodes :inbox/wnodes
:inbox/topic
:inbox/password :inbox/password
:browser/browsers :browser/browsers
:browser/options :browser/options

View File

@ -244,10 +244,8 @@
(fn [{:keys [accounts/accounts accounts/create contacts/contacts networks/networks (fn [{:keys [accounts/accounts accounts/create contacts/contacts networks/networks
network network-status view-id navigation-stack network network-status view-id navigation-stack
access-scope->commands-responses access-scope->commands-responses
status-module-initialized? status-node-started? status-module-initialized? status-node-started?]
inbox/wnode] :or [network (get app-db :network)]} [_ address]]
:or [network (get app-db :network)
wnode (get app-db :inbox/wnode)]} [_ address]]
(let [console-contact (get contacts constants/console-chat-id)] (let [console-contact (get contacts constants/console-chat-id)]
(cond-> (assoc app-db (cond-> (assoc app-db
:access-scope->commands-responses access-scope->commands-responses :access-scope->commands-responses access-scope->commands-responses
@ -264,8 +262,7 @@
:accounts/create create :accounts/create create
:networks/networks networks :networks/networks networks
:network-status network-status :network-status network-status
:network network :network network)
:inbox/wnode wnode)
console-contact console-contact
(assoc :contacts/contacts {constants/console-chat-id console-contact}))))) (assoc :contacts/contacts {constants/console-chat-id console-contact})))))

View File

@ -11,7 +11,5 @@
(spec/def :wnode/id ::not-blank-string) (spec/def :wnode/id ::not-blank-string)
(spec/def :wnode/wnode (allowed-keys :req-un [:wnode/address :wnode/name :wnode/id])) (spec/def :wnode/wnode (allowed-keys :req-un [:wnode/address :wnode/name :wnode/id]))
(spec/def :inbox/topic ::not-blank-string)
(spec/def :inbox/password ::not-blank-string) (spec/def :inbox/password ::not-blank-string)
(spec/def :inbox/wnode ::not-blank-string) (spec/def :inbox/wnodes (spec/nilable (spec/map-of keyword? (spec/map-of :wnode/id :wnode/wnode))))
(spec/def :inbox/wnodes (spec/nilable (spec/map-of :wnode/id :wnode/wnode)))

View File

@ -3,22 +3,26 @@
[status-im.utils.handlers :as handlers] [status-im.utils.handlers :as handlers]
[status-im.ui.screens.accounts.events :as accounts-events] [status-im.ui.screens.accounts.events :as accounts-events]
[status-im.i18n :as i18n] [status-im.i18n :as i18n]
[status-im.transport.core :as transport])) [status-im.transport.core :as transport]
[status-im.utils.ethereum.core :as ethereum]))
(handlers/register-handler-fx (handlers/register-handler-fx
::save-wnode ::save-wnode
(fn [{:keys [db now] :as cofx} [_ wnode]] (fn [{:keys [db now] :as cofx} [_ wnode]]
(handlers/merge-fx cofx (let [{:accounts/keys [current-account-id accounts]} db
{:dispatch [:navigate-to-clean :accounts]} network (ethereum/network->chain-keyword (:network db))
(accounts-events/account-update {:wnode wnode :last-updated now}) settings (get-in accounts [current-account-id :settings])]
(transport/stop-whisper)))) (handlers/merge-fx cofx
{:dispatch [:logout]}
(accounts-events/update-settings (assoc-in settings [:wnode network] wnode))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:connect-wnode :connect-wnode
(fn [{:keys [db]} [_ wnode]] (fn [{:keys [db]} [_ wnode]]
{:show-confirmation {:title (i18n/label :t/close-app-title) (let [network (ethereum/network->chain-keyword (:network db))]
:content (i18n/label :t/connect-wnode-content {:show-confirmation {:title (i18n/label :t/close-app-title)
{:name (get-in db [:inbox/wnodes wnode :name])}) :content (i18n/label :t/connect-wnode-content
:confirm-button-text (i18n/label :t/close-app-button) {:name (get-in db [:inbox/wnodes network wnode :name])})
:on-accept #(dispatch [::save-wnode wnode]) :confirm-button-text (i18n/label :t/close-app-button)
:on-cancel nil}})) :on-accept #(dispatch [::save-wnode wnode])
:on-cancel nil}})))

View File

@ -0,0 +1,17 @@
(ns status-im.ui.screens.offline-messaging-settings.subs
(:require [re-frame.core :as re-frame]
[status-im.utils.ethereum.core :as ethereum]))
(re-frame/reg-sub :settings/current-wnode
:<- [:network]
:<- [:get-current-account]
(fn [[network current-account]]
(let [chain (ethereum/network->chain-keyword network)]
(get-in current-account [:settings :wnode chain]))))
(re-frame/reg-sub :settings/network-wnodes
:<- [:network]
:<- [:get :inbox/wnodes]
(fn [[network wnodes]]
(let [chain (ethereum/network->chain-keyword network)]
(chain wnodes))))

View File

@ -26,8 +26,8 @@
name]]]]))) name]]]])))
(views/defview offline-messaging-settings [] (views/defview offline-messaging-settings []
(views/letsubs [current-wnode [:get :inbox/wnode] (views/letsubs [current-wnode [:settings/current-wnode]
wnodes [:get :inbox/wnodes]] wnodes [:settings/network-wnodes]]
[react/view {:flex 1} [react/view {:flex 1}
[status-bar/status-bar] [status-bar/status-bar]
[toolbar/simple-toolbar (i18n/label :t/offline-messaging-settings)] [toolbar/simple-toolbar (i18n/label :t/offline-messaging-settings)]

View File

@ -13,6 +13,7 @@
status-im.ui.screens.wallet.settings.subs status-im.ui.screens.wallet.settings.subs
status-im.ui.screens.wallet.transactions.subs status-im.ui.screens.wallet.transactions.subs
status-im.ui.screens.network-settings.subs status-im.ui.screens.network-settings.subs
status-im.ui.screens.offline-messaging-settings.subs
status-im.ui.screens.browser.subs status-im.ui.screens.browser.subs
status-im.bots.subs status-im.bots.subs
status-im.ui.screens.add-new.new-chat.subs status-im.ui.screens.add-new.new-chat.subs

View File

@ -10,11 +10,8 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.settings/toggle-visible-token :wallet.settings/toggle-visible-token
(fn [{{:keys [network] :accounts/keys [current-account-id] :as db} :db} [_ symbol checked?]] (fn [{{:keys [network] :accounts/keys [current-account-id] :as db} :db :as cofx} [_ symbol checked?]]
(let [chain (ethereum/network->chain-keyword network) (let [chain (ethereum/network->chain-keyword network)
path [:accounts/accounts current-account-id :settings] settings (get-in db [:accounts/accounts current-account-id :settings])
settings (get-in db path)
new-settings (update-in settings [:wallet :visible-tokens chain] #(toggle-checked % symbol checked?))] new-settings (update-in settings [:wallet :visible-tokens chain] #(toggle-checked % symbol checked?))]
(-> db (accounts/update-settings new-settings cofx))))
(assoc-in path new-settings)
(accounts/update-wallet-settings new-settings)))))