Add pfs flag, installation id and nobackup data directory

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2018-09-20 11:49:34 +02:00
parent 83cd95ff3c
commit df51731fca
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
21 changed files with 142 additions and 22 deletions

1
.env
View File

@ -16,3 +16,4 @@ GROUP_CHATS_ENABLED=0
CACHED_WEBVIEWS_ENABLED=1 CACHED_WEBVIEWS_ENABLED=1
EXTENSIONS=1 EXTENSIONS=1
HARDWALLET_ENABLED=0 HARDWALLET_ENABLED=0
PFS_ENCRYPTION_ENABLED=0

View File

@ -11,3 +11,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=1 DEBUG_WEBVIEW=1
GROUP_CHATS_ENABLED=1 GROUP_CHATS_ENABLED=1
EXTENSIONS=0 EXTENSIONS=0
PFS_ENCRYPTION_ENABLED=0

View File

@ -14,3 +14,4 @@ GROUP_CHATS_ENABLED=0
MAINNET_WARNING_ENABLED=1 MAINNET_WARNING_ENABLED=1
CACHED_WEBVIEWS_ENABLED=1 CACHED_WEBVIEWS_ENABLED=1
EXTENSIONS=0 EXTENSIONS=0
PFS_ENCRYPTION_ENABLED=0

View File

@ -13,3 +13,4 @@ DEBUG_WEBVIEW=1
GROUP_CHATS_ENABLED=0 GROUP_CHATS_ENABLED=0
MAINNET_WARNING_ENABLED=1 MAINNET_WARNING_ENABLED=1
EXTENSIONS=1 EXTENSIONS=1
PFS_ENCRYPTION_ENABLED=0

View File

@ -14,3 +14,4 @@ INSTABUG_SURVEYS=1
GROUP_CHATS_ENABLED=0 GROUP_CHATS_ENABLED=0
MAINNET_WARNING_ENABLED=1 MAINNET_WARNING_ENABLED=1
EXTENSIONS=0 EXTENSIONS=0
PFS_ENCRYPTION_ENABLED=0

View File

@ -15,3 +15,4 @@ DEBUG_WEBVIEW=0
GROUP_CHATS_ENABLED=0 GROUP_CHATS_ENABLED=0
MAINNET_WARNING_ENABLED=1 MAINNET_WARNING_ENABLED=1
EXTENSIONS=0 EXTENSIONS=0
PFS_ENCRYPTION_ENABLED=0

View File

@ -99,6 +99,7 @@ void RCTStatus::startNode(QString configString) {
} }
configJSON["DataDir"] = absDataDirPath; configJSON["DataDir"] = absDataDirPath;
configJSON["BackupDisabledDataDir"] = absDataDirPath;
configJSON["KeyStoreDir"] = rootDir.absoluteFilePath("keystore"); configJSON["KeyStoreDir"] = rootDir.absoluteFilePath("keystore");
configJSON["LogFile"] = dataDir.absoluteFilePath("geth.log"); configJSON["LogFile"] = dataDir.absoluteFilePath("geth.log");

View File

@ -11,6 +11,7 @@
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.ui.screens.navigation :as navigation] [status-im.ui.screens.navigation :as navigation]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.utils.random :as random]
[status-im.utils.gfycat.core :as gfycat] [status-im.utils.gfycat.core :as gfycat]
[status-im.utils.handlers-macro :as handlers-macro] [status-im.utils.handlers-macro :as handlers-macro]
[status-im.utils.hex :as utils.hex] [status-im.utils.hex :as utils.hex]
@ -48,9 +49,13 @@
{:db (assoc-in db [:accounts/accounts address] enriched-account) {:db (assoc-in db [:accounts/accounts address] enriched-account)
:data-store/base-tx [(accounts-store/save-account-tx enriched-account)]})) :data-store/base-tx [(accounts-store/save-account-tx enriched-account)]}))
(defn on-account-created [{:keys [pubkey address mnemonic]} password seed-backed-up {:keys [signing-phrase status db] :as cofx}] (defn on-account-created [{:keys [pubkey address mnemonic]} password seed-backed-up {:keys [random-guid-generator
signing-phrase
status
db] :as cofx}]
(let [normalized-address (utils.hex/normalize-hex address) (let [normalized-address (utils.hex/normalize-hex address)
account {:public-key pubkey account {:public-key pubkey
:installation-id (random-guid-generator)
:address normalized-address :address normalized-address
:name (gfycat/generate-gfy pubkey) :name (gfycat/generate-gfy pubkey)
:status status :status status

View File

@ -40,12 +40,14 @@
(spec/def :account/sharing-usage-data? (spec/nilable boolean?)) (spec/def :account/sharing-usage-data? (spec/nilable boolean?))
(spec/def :account/dev-mode? (spec/nilable boolean?)) (spec/def :account/dev-mode? (spec/nilable boolean?))
(spec/def :account/seed-backed-up? (spec/nilable boolean?)) (spec/def :account/seed-backed-up? (spec/nilable boolean?))
(spec/def :account/installation-id :global/not-empty-string)
(spec/def :account/wallet-set-up-passed? (spec/nilable boolean?)) (spec/def :account/wallet-set-up-passed? (spec/nilable boolean?))
(spec/def :account/mainnet-warning-shown? (spec/nilable boolean?)) (spec/def :account/mainnet-warning-shown? (spec/nilable boolean?))
(spec/def :accounts/account (allowed-keys (spec/def :accounts/account (allowed-keys
:req-un [:account/name :account/address :account/public-key :req-un [:account/name :account/address :account/public-key
:account/photo-path :account/signing-phrase] :account/photo-path :account/signing-phrase
:account/installation-id]
:opt-un [:account/debug? :account/status :account/last-updated :opt-un [:account/debug? :account/status :account/last-updated
:account/email :account/signed-up? :account/network :account/email :account/signed-up? :account/network
:account/networks :account/settings :account/wnode :account/networks :account/settings :account/wnode

View File

@ -55,14 +55,9 @@
(.-defaultPath rn-dependencies/realm)) (.-defaultPath rn-dependencies/realm))
(def realm-dir (def realm-dir
(cond (if-let [path (utils.platform/no-backup-directory)]
utils.platform/android? (str (str path "/realm/")
(.-DocumentDirectoryPath rn-dependencies/fs) (.-defaultPath rn-dependencies/realm)))
"/../no_backup/realm/")
utils.platform/ios? (str
(.-LibraryDirectoryPath rn-dependencies/fs)
"/realm/")
:else (.-defaultPath rn-dependencies/realm)))
(def old-realm-dir (def old-realm-dir
(string/replace old-base-realm-path #"default\.realm$" "")) (string/replace old-base-realm-path #"default\.realm$" ""))

View File

@ -8,7 +8,8 @@
[status-im.data-store.realm.schemas.base.v7.core :as v7] [status-im.data-store.realm.schemas.base.v7.core :as v7]
[status-im.data-store.realm.schemas.base.v8.core :as v8] [status-im.data-store.realm.schemas.base.v8.core :as v8]
[status-im.data-store.realm.schemas.base.v9.core :as v9] [status-im.data-store.realm.schemas.base.v9.core :as v9]
[status-im.data-store.realm.schemas.base.v10.core :as v10])) [status-im.data-store.realm.schemas.base.v10.core :as v10]
[status-im.data-store.realm.schemas.base.v11.core :as v11]))
;; put schemas ordered by version ;; put schemas ordered by version
(def schemas [{:schema v1/schema (def schemas [{:schema v1/schema
@ -40,4 +41,7 @@
:migration v9/migration} :migration v9/migration}
{:schema v10/schema {:schema v10/schema
:schemaVersion 10 :schemaVersion 10
:migration v10/migration}]) :migration v10/migration}
{:schema v11/schema
:schemaVersion 11
:migration v11/migration}])

View File

@ -0,0 +1,22 @@
(ns status-im.data-store.realm.schemas.base.v11.account
(:require [taoensso.timbre :as log]
[clojure.string :as string]
[cognitect.transit :as transit]
[clojure.set :as set]
[status-im.utils.random :as random]
[status-im.data-store.realm.schemas.base.v10.account :as v10]))
(def schema
(assoc-in v10/schema
[:properties :installation-id]
{:type :string}))
(defn migration [old-realm new-realm]
(log/debug "migrating accounts schema v11")
(let [accounts (.objects new-realm "account")]
(dotimes [i (.-length accounts)]
(let [account (aget accounts i)
old-installation-id (aget account "installation-id")
installation-id (random/guid)]
(when (string/blank? old-installation-id)
(aset account "installation-id" installation-id))))))

View File

@ -0,0 +1,13 @@
(ns status-im.data-store.realm.schemas.base.v11.core
(:require [status-im.data-store.realm.schemas.base.v1.network :as network]
[status-im.data-store.realm.schemas.base.v4.bootnode :as bootnode]
[status-im.data-store.realm.schemas.base.v11.account :as account]
[taoensso.timbre :as log]))
(def schema [network/schema
bootnode/schema
account/schema])
(defn migration [old-realm new-realm]
(log/debug "migrating base database v11: " old-realm new-realm)
(account/migration old-realm new-realm))

View File

@ -138,7 +138,8 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:accounts.create.callback/create-account-success :accounts.create.callback/create-account-success
[(re-frame/inject-cofx :accounts.create/get-signing-phrase) [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx :accounts.create/get-signing-phrase)
(re-frame/inject-cofx :accounts.create/get-status)] (re-frame/inject-cofx :accounts.create/get-status)]
(fn [cofx [_ result password]] (fn [cofx [_ result password]]
(accounts.create/on-account-created result password false cofx))) (accounts.create/on-account-created result password false cofx)))
@ -187,7 +188,8 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:accounts.recover.callback/recover-account-success :accounts.recover.callback/recover-account-success
[(re-frame/inject-cofx :accounts.create/get-signing-phrase) [(re-frame/inject-cofx :random-guid-generator)
(re-frame/inject-cofx :accounts.create/get-signing-phrase)
(re-frame/inject-cofx :accounts.create/get-status)] (re-frame/inject-cofx :accounts.create/get-status)]
(fn [cofx [_ result password]] (fn [cofx [_ result password]]
(accounts.recover/on-account-recovered result password cofx))) (accounts.recover/on-account-recovered result password cofx)))

View File

@ -4,6 +4,7 @@
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.utils.config :as config] [status-im.utils.config :as config]
[status-im.utils.types :as types] [status-im.utils.types :as types]
[status-im.utils.platform :as utils.platform]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
(defn- add-custom-bootnodes [config network all-bootnodes] (defn- add-custom-bootnodes [config network all-bootnodes]
@ -65,6 +66,7 @@
current-fleet-key (fleet/current-fleet db address) current-fleet-key (fleet/current-fleet db address)
current-fleet (get fleet/fleets current-fleet-key) current-fleet (get fleet/fleets current-fleet-key)
{:keys [network {:keys [network
installation-id
settings settings
bootnodes bootnodes
networks]} (get accounts address) networks]} (get accounts address)
@ -85,11 +87,15 @@
:StaticNodes (pick-nodes 2 (vals (:whisper current-fleet)))}) :StaticNodes (pick-nodes 2 (vals (:whisper current-fleet)))})
:always :always
(assoc :WhisperConfig {:Enabled true (assoc :WhisperConfig {:Enabled true
:LightClient true :LightClient true
:MinimumPoW 0.001 :MinimumPoW 0.001
:EnableNTPSync true} :EnableNTPSync true}
:RequireTopics (get-topics network)) :RequireTopics (get-topics network)
:BackupDisabledDataDir (utils.platform/no-backup-directory)
:InstallationID installation-id
:PFSEnabled (or config/pfs-encryption-enabled?
config/group-chats-enabled?))
(and (and
config/bootnodes-settings-enabled? config/bootnodes-settings-enabled?
@ -102,6 +108,7 @@
(defn get-node-config [db network] (defn get-node-config [db network]
(-> (get-in (:networks/networks db) [network :config]) (-> (get-in (:networks/networks db) [network :config])
(get-base-node-config) (get-base-node-config)
(assoc :PFSEnabled false)
(assoc :NoDiscovery true) (assoc :NoDiscovery true)
(add-log-level config/log-level-status-go))) (add-log-level config/log-level-status-go)))

View File

@ -23,6 +23,7 @@
(def rpc-networks-only? (enabled? (get-config :RPC_NETWORKS_ONLY "1"))) (def rpc-networks-only? (enabled? (get-config :RPC_NETWORKS_ONLY "1")))
(def group-chats-enabled? (enabled? (get-config :GROUP_CHATS_ENABLED))) (def group-chats-enabled? (enabled? (get-config :GROUP_CHATS_ENABLED)))
(def mainnet-warning-enabled? (enabled? (get-config :MAINNET_WARNING_ENABLED 0))) (def mainnet-warning-enabled? (enabled? (get-config :MAINNET_WARNING_ENABLED 0)))
(def pfs-encryption-enabled? (enabled? (get-config :PFS_ENCRYPTION_ENABLED "0")))
(def in-app-notifications-enabled? (enabled? (get-config :IN_APP_NOTIFICATIONS_ENABLED 0))) (def in-app-notifications-enabled? (enabled? (get-config :IN_APP_NOTIFICATIONS_ENABLED 0)))
(def cached-webviews-enabled? (enabled? (get-config :CACHED_WEBVIEWS_ENABLED 0))) (def cached-webviews-enabled? (enabled? (get-config :CACHED_WEBVIEWS_ENABLED 0)))
(def rn-bridge-threshold-warnings-enabled? (enabled? (get-config :RN_BRIDGE_THRESHOLD_WARNINGS 0))) (def rn-bridge-threshold-warnings-enabled? (enabled? (get-config :RN_BRIDGE_THRESHOLD_WARNINGS 0)))

View File

@ -26,3 +26,9 @@
android? android/platform-specific android? android/platform-specific
ios? ios/platform-specific ios? ios/platform-specific
:else (desktop/platform-specific (if platform (.-isMacOs platform) true)))) :else (desktop/platform-specific (if platform (.-isMacOs platform) true))))
(defn no-backup-directory []
(cond
android? (str (.-DocumentDirectoryPath rn-dependencies/fs)
"/../no_backup")
ios? (.-LibraryDirectoryPath rn-dependencies/fs)))

View File

@ -5,6 +5,9 @@
(def chance (dependencies/Chance.)) (def chance (dependencies/Chance.))
(defn guid []
(.guid chance))
(defn id [] (defn id []
(str (datetime/timestamp) "-" (.guid chance))) (str (datetime/timestamp) "-" (.guid chance)))
@ -19,6 +22,11 @@
[gen coll] [gen coll]
(nth coll (seeded-rand-int gen (count coll)))) (nth coll (seeded-rand-int gen (count coll))))
(re-frame/reg-cofx
:random-guid-generator
(fn [coeffects _]
(assoc coeffects :random-guid-generator guid)))
(re-frame/reg-cofx (re-frame/reg-cofx
:random-id :random-id
(fn [coeffects _] (fn [coeffects _]

View File

@ -0,0 +1,46 @@
(ns status-im.test.node.core
(:require [cljs.test :refer-macros [deftest is testing]]
[status-im.utils.config :as config]
[status-im.node.core :as node]))
(defn- parse-node-config [config]
(-> config
:node/start
(js/JSON.parse)
(js->clj :keywordize-keys true)))
(deftest start-test
(let [address "a"
cofx {:db {:accounts/accounts {address {:installation-id "id"}}}}]
(testing "installation-id"
(testing "the user is not logged in"
(let [actual (parse-node-config (node/start nil cofx))]
(is (not (:InstallationID actual)))))
(testing "the user is logged in"
(let [actual (parse-node-config (node/start address cofx))]
(is (= "id" (:InstallationID actual))))))
(testing "pfs & group chats disabled"
(with-redefs [config/pfs-encryption-enabled? false
config/group-chats-enabled? false]
(testing "the user is not logged in"
(let [actual (parse-node-config (node/start nil cofx))]
(is (not (:PFSEnabled actual)))))
(testing "the user is logged in"
(let [actual (parse-node-config (node/start address cofx))]
(is (not (:PFSEnabled actual))))))
(testing "pfs is enabled"
(with-redefs [config/pfs-encryption-enabled? true]
(testing "the user is not logged in"
(let [actual (parse-node-config (node/start nil cofx))]
(is (not (:PFSEnabled actual)))))
(testing "the user is logged in"
(let [actual (parse-node-config (node/start address cofx))]
(is (:PFSEnabled actual))))))
(testing "group chats is enabled"
(with-redefs [config/group-chats-enabled? true]
(testing "the user is not logged in"
(let [actual (parse-node-config (node/start nil cofx))]
(is (not (:PFSEnabled actual)))))
(testing "the user is logged in"
(let [actual (parse-node-config (node/start address cofx))]
(is (:PFSEnabled actual)))))))))

View File

@ -10,6 +10,7 @@
[status-im.test.wallet.transactions.subs] [status-im.test.wallet.transactions.subs]
[status-im.test.wallet.transactions.views] [status-im.test.wallet.transactions.views]
[status-im.test.mailserver.core] [status-im.test.mailserver.core]
[status-im.test.node.core]
[status-im.test.models.bootnode] [status-im.test.models.bootnode]
[status-im.test.models.account] [status-im.test.models.account]
[status-im.test.models.contact] [status-im.test.models.contact]
@ -74,6 +75,7 @@
'status-im.test.init.core 'status-im.test.init.core
'status-im.test.data-store.realm.core 'status-im.test.data-store.realm.core
'status-im.test.mailserver.core 'status-im.test.mailserver.core
'status-im.test.node.core
'status-im.test.models.bootnode 'status-im.test.models.bootnode
'status-im.test.models.account 'status-im.test.models.account
'status-im.test.models.contact 'status-im.test.models.contact

View File

@ -13,10 +13,10 @@
(deftest receive-whisper-messages-test (deftest receive-whisper-messages-test
(testing "an error is reported" (testing "an error is reported"
(is (nil? (handlers/receive-whisper-messages {} [_ "error" #js [] nil])))) (is (nil? (handlers/receive-whisper-messages {} [nil "error" #js [] nil]))))
(testing "messages is undefined" (testing "messages is undefined"
(is (nil? (handlers/receive-whisper-messages {} [_ nil js/undefined nil])))) (is (nil? (handlers/receive-whisper-messages {} [nil nil js/undefined nil]))))
(testing "happy path" (testing "happy path"
(let [actual (handlers/receive-whisper-messages {} [_ nil messages "1"])] (let [actual (handlers/receive-whisper-messages {} [nil nil messages "1"])]
(testing "it add an fx for the message" (testing "it add an fx for the message"
(is (:chat-received-message/add-fx actual)))))) (is (:chat-received-message/add-fx actual))))))