add customized logging on android and whisper ver5 support

This commit is contained in:
Roman Volosovskyi 2017-03-29 10:32:53 +03:00 committed by Roman Volosovskyi
parent 41af22463a
commit 7b89adc877
12 changed files with 106 additions and 34 deletions

View File

@ -49,7 +49,7 @@ public class MainApplication extends Application implements ReactApplication {
new NfcReactNativePackage(), new NfcReactNativePackage(),
new RNInstabugReactnativePackage("b239f82a9cb00464e4c72cc703e6821e",MainApplication.this,"shake"), new RNInstabugReactnativePackage("b239f82a9cb00464e4c72cc703e6821e",MainApplication.this,"shake"),
new SplashScreenReactPackage(), new SplashScreenReactPackage(),
new StatusPackage(), new StatusPackage(BuildConfig.DEBUG),
new RealmReactPackage(), new RealmReactPackage(),
new VectorIconsPackage(), new VectorIconsPackage(),
new ReactNativeContacts(), new ReactNativeContacts(),

View File

@ -14,5 +14,5 @@ android {
dependencies { dependencies {
compile 'com.facebook.react:react-native:+' compile 'com.facebook.react:react-native:+'
compile(group: 'status-im', name: 'status-go', version: '0.9.5-51-g8ef2206', ext: 'aar') compile(group: 'status-im', name: 'status-go', version: '0.9.5-55-g01a1550', ext: 'aar')
} }

View File

@ -2,7 +2,6 @@ package im.status.ethereum.module;
import android.app.Activity; import android.app.Activity;
import android.os.*; import android.os.*;
import android.os.Process;
import android.view.WindowManager; import android.view.WindowManager;
import android.util.Log; import android.util.Log;
import android.webkit.CookieManager; import android.webkit.CookieManager;
@ -20,6 +19,9 @@ import java.util.UUID;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import org.json.JSONObject;
import org.json.JSONException;
class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ConnectorHandler { class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ConnectorHandler {
private static final String TAG = "StatusModule"; private static final String TAG = "StatusModule";
@ -29,12 +31,14 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
private static StatusModule module; private static StatusModule module;
private ServiceConnector status = null; private ServiceConnector status = null;
private ExecutorService executor = null; private ExecutorService executor = null;
private boolean debug;
StatusModule(ReactApplicationContext reactContext) { StatusModule(ReactApplicationContext reactContext, boolean debug) {
super(reactContext); super(reactContext);
if (executor == null) { if (executor == null) {
executor = Executors.newCachedThreadPool(); executor = Executors.newCachedThreadPool();
} }
this.debug = debug;
reactContext.addLifecycleEventListener(this); reactContext.addLifecycleEventListener(this);
} }
@ -133,7 +137,23 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
} }
} }
Statusgo.StartNode(Statusgo.GenerateConfig(dataFolder, 3)); String config;
String defaultConfig = Statusgo.GenerateConfig(dataFolder, 3);
try {
JSONObject jsonConfig = new JSONObject(defaultConfig);
jsonConfig.put("LogEnabled", this.debug);
jsonConfig.put("LogFile", "geth.log");
jsonConfig.put("LogLevel", "DEBUG");
config = jsonConfig.toString();
} catch (JSONException e) {
Log.d(TAG, "Something went wrong " + e.getMessage());
Log.d(TAG, "Default configuration will be used");
config = defaultConfig;
}
Statusgo.StartNode(config);
Log.d(TAG, "Geth node started"); Log.d(TAG, "Geth node started");
} }

View File

@ -12,12 +12,18 @@ import java.util.List;
public class StatusPackage implements ReactPackage { public class StatusPackage implements ReactPackage {
private boolean debug;
public StatusPackage (boolean debug) {
this.debug = debug;
}
@Override @Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>(); List<NativeModule> modules = new ArrayList<>();
System.loadLibrary("statusgoraw"); System.loadLibrary("statusgoraw");
System.loadLibrary("statusgo"); System.loadLibrary("statusgo");
modules.add(new StatusModule(reactContext)); modules.add(new StatusModule(reactContext, this.debug));
return modules; return modules;
} }

View File

@ -162,14 +162,6 @@ RCT_EXPORT_METHOD(startNode:(RCTResponseSenderBlock)onResultCallback) {
char *config = GenerateConfig([folderName.path UTF8String], 3); char *config = GenerateConfig([folderName.path UTF8String], 3);
StartNode(config); StartNode(config);
}); });
NSString *peer1 = @"enode://5f23bf4913dd005ce945648cb12d3ef970069818d8563a3fe054e5e1dc3898b9cb83e0af1f51b2dce75eaffc76e93f996caf538e21c5b64db5fa324958d59630@95.85.40.211:30303";
NSString *peer2 = @"enode://b9de2532421f15ac55da9d9a7cddc0dc08b0d646d631fd7ab2a170bd2163fb86b095dd8bde66b857592812f7cd9539f2919b6c64bc1a784a1d1c6ec8137681ed@188.166.229.119:30303";
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)),
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^(void) {
AddPeer((char *) [peer1 UTF8String]);
AddPeer((char *) [peer2 UTF8String]);
});
onResultCallback(@[[NSNull null]]); onResultCallback(@[[NSNull null]]);
//Screen lock notifications //Screen lock notifications
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center

View File

@ -25,7 +25,7 @@
<artifactItem> <artifactItem>
<groupId>status-im</groupId> <groupId>status-im</groupId>
<artifactId>status-go-ios-simulator</artifactId> <artifactId>status-go-ios-simulator</artifactId>
<version>0.9.5-51-g8ef2206</version> <version>0.9.5-55-g01a1550</version>
<type>zip</type> <type>zip</type>
<overWrite>true</overWrite> <overWrite>true</overWrite>
<outputDirectory>./</outputDirectory> <outputDirectory>./</outputDirectory>

View File

@ -81,7 +81,7 @@
"tty-browserify": "0.0.0", "tty-browserify": "0.0.0",
"url": "^0.10.3", "url": "^0.10.3",
"vm-browserify": "0.0.4", "vm-browserify": "0.0.4",
"web3": "0.16.0" "web3": "github:status-im/web3.js#status-0.18.4"
}, },
"browser": { "browser": {
"crypto": "react-native-crypto", "crypto": "react-native-crypto",

View File

@ -9,7 +9,9 @@
(defn- parse-payload [payload] (defn- parse-payload [payload]
(debug :parse-payload) (debug :parse-payload)
(try (try
{:payload (r/read-string (u/to-utf8 payload))} ;; todo figure why we have to call to-utf8 twice
(let [read (comp r/read-string u/to-utf8 u/to-utf8)]
{:payload (read payload)})
(catch :default err (catch :default err
(debug :parse-payload-error err) (debug :parse-payload-error err)
{:error err}))) {:error err})))
@ -36,7 +38,7 @@
(when error (when error
(debug :listener-error error)) (debug :listener-error error))
(when-not error (when-not error
(debug :message-received) (debug :message-received (js->clj js-message))
(let [{:keys [from payload to] :as message} (let [{:keys [from payload to] :as message}
(js->clj js-message :keywordize-keys true) (js->clj js-message :keywordize-keys true)
@ -50,7 +52,9 @@
(= type :discover))) (= type :discover)))
(let [{:keys [content error]} (parse-content (:private keypair) (let [{:keys [content error]} (parse-content (:private keypair)
payload' payload'
(not= "0x0" to))] (and (not= "0x0" to)
(not= "" to)
(not (nil? to))))]
(if error (if error
(debug :failed-to-handle-message error) (debug :failed-to-handle-message error)
(let [payload'' (assoc payload' :content content) (let [payload'' (assoc payload' :content content)

View File

@ -128,10 +128,10 @@
:last-attempt (u/timestamp))))) :last-attempt (u/timestamp)))))
(defn delivery-callback (defn delivery-callback
[web3 post-error-callback {:keys [id requires-ack? to]}] [web3 post-error-callback {:keys [id requires-ack? to]} message]
(fn [error _] (fn [error _]
(when error (when error
(log/warn :shh-post-error error) (log/warn :shh-post-error error message)
(when post-error-callback (when post-error-callback
(post-error-callback error))) (post-error-callback error)))
(when-not error (when-not error
@ -207,7 +207,7 @@
(when (should-be-retransmitted? options data) (when (should-be-retransmitted? options data)
(try (try
(let [message' (check-ttl message type ttl-config default-ttl) (let [message' (check-ttl message type ttl-config default-ttl)
callback (delivery-callback web3 post-error-callback data)] callback (delivery-callback web3 post-error-callback data message')]
(t/post-message! web3 message' callback)) (t/post-message! web3 message' callback))
(catch :default err (catch :default err
(log/error :post-message-error err)) (log/error :post-message-error err))

View File

@ -1,7 +1,7 @@
(ns status-im.protocol.web3.filtering (ns status-im.protocol.web3.filtering
(:require [status-im.protocol.web3.utils :as u] (:require [status-im.protocol.web3.utils :as u]
[cljs.spec :as s] [cljs.spec :as s]
[taoensso.timbre :refer-macros [debug]])) [taoensso.timbre :as log]))
(def status-topic "status-dapp-topic") (def status-topic "status-dapp-topic")
(defonce filters (atom {})) (defonce filters (atom {}))
@ -10,18 +10,45 @@
(defn remove-filter! [web3 options] (defn remove-filter! [web3 options]
(when-let [filter (get-in @filters [web3 options])] (when-let [filter (get-in @filters [web3 options])]
(.stopWatching filter) (.stopWatching filter
(debug :stop-watching options) (fn [error _]
(when error
(log/warn :remove-filter-error options error))))
(log/debug :stop-watching options)
(swap! filters update web3 dissoc options))) (swap! filters update web3 dissoc options)))
(defn add-filter! (defn add-shh-filter!
[web3 options callback] [web3 options callback]
(fn do-add-filter-fn
([] (do-add-filter-fn nil))
([keyname]
(let [options' (if keyname
(assoc options :keyname keyname)
options)
filter (.filter (u/shh web3) (clj->js options')
callback
#(log/warn :add-filter-error options %))]
(swap! filters assoc-in [web3 options] filter)))))
(defn add-filter!
[web3 {:keys [topics to] :as options} callback]
(remove-filter! web3 options) (remove-filter! web3 options)
(debug :add-filter options) (log/debug :add-filter options)
(let [filter (.filter (u/shh web3) (let [shh (u/shh web3)
(clj->js options) encrypted? (boolean to)
callback)] do-add-filter (add-shh-filter! web3 options callback)]
(swap! filters assoc-in [web3 options] filter))) (if encrypted?
(do-add-filter)
(let [topic (first topics)]
(.hasSymKey
shh topic
(fn [error res]
(if-not res
(.addSymKey
shh topic u/status-key-data
(fn [error res]
(when-not error (do-add-filter topic))))
(do-add-filter topic))))))))
(defn remove-all-filters! [] (defn remove-all-filters! []
(doseq [[web3 filters] @filters] (doseq [[web3 filters] @filters]

View File

@ -11,7 +11,24 @@
:opt-un [:message/to])) :opt-un [:message/to]))
(defn post-message! (defn post-message!
[web3 message callback] [web3 {:keys [topics from to] :as message} callback]
{:pre [(valid? :shh/message message)]} {:pre [(valid? :shh/message message)]}
(debug :post-message message) (debug :post-message message)
(.post (u/shh web3) (clj->js message) callback)) (let [topic (first topics)
shh (u/shh web3)
encrypted? (boolean to)
message' (if encrypted?
message
(assoc message :keyname topic))
do-post (fn [] (.post shh (clj->js message') callback))]
(if encrypted?
(do-post)
(.hasSymKey
shh topic
(fn [_ res]
(if-not res
(.addSymKey
shh topic u/status-key-data
(fn [error _]
(when-not error (do-post))))
(do-post)))))))

View File

@ -7,8 +7,11 @@
(defn from-utf8 [s] (defn from-utf8 [s]
(.fromUtf8 web3.prototype s)) (.fromUtf8 web3.prototype s))
(defn to-ascii [s]
(.toAscii web3.prototype s))
(defn to-utf8 [s] (defn to-utf8 [s]
(.toUtf8 web3.prototype s)) (.toUtf8 web3.prototype (str s)))
(defn shh [web3] (defn shh [web3]
(.-shh web3)) (.-shh web3))
@ -20,3 +23,6 @@
(defn timestamp [] (defn timestamp []
(to-long (now))) (to-long (now)))
(def status-key-data (.toHex web3.prototype "status-key-data"))