From 0470d806b542c1366a349dfeec354daa4553d513 Mon Sep 17 00:00:00 2001 From: ehsan shariati Date: Sat, 8 Jul 2023 13:02:08 -0400 Subject: [PATCH] Added a testData test data does not need init and it does not use WNFS --- android/build.gradle | 3 +- .../main/java/land/fx/fula/FulaModule.java | 33 +++++++++++++++++++ example/android/build.gradle | 2 +- example/src/App.tsx | 20 +++++++++++ src/interfaces/fulaNativeModule.ts | 2 ++ src/protocols/fula.ts | 8 +++++ 6 files changed, 66 insertions(+), 2 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 722c3d7..f2b59f9 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -62,8 +62,9 @@ repositories { dependencies { //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules - implementation 'com.github.functionland:fula-build-aar:1.9.0' // From jitpack.io + implementation 'com.github.functionland:fula-build-aar:1.11.2' // From jitpack.io implementation 'com.github.functionland:wnfs-build-aar:v1.4.1' // From jitpack.io implementation 'commons-io:commons-io:20030203.000550' + implementation 'commons-codec:commons-codec:1.15' // implementation files('mobile.aar') } diff --git a/android/src/main/java/land/fx/fula/FulaModule.java b/android/src/main/java/land/fx/fula/FulaModule.java index c14b8df..1006a81 100755 --- a/android/src/main/java/land/fx/fula/FulaModule.java +++ b/android/src/main/java/land/fx/fula/FulaModule.java @@ -13,6 +13,7 @@ import com.facebook.react.module.annotations.ReactModule; import org.apache.commons.io.FileUtils; +import org.apache.commons.codec.binary.Base32; import org.jetbrains.annotations.Contract; import java.io.File; @@ -23,6 +24,7 @@ import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.Arrays; +import java.util.Random; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; @@ -1390,4 +1392,35 @@ public void reboot(Promise promise) { }); } + @ReactMethod + public void testData(String identityString, String bloxAddr, Promise promise) { + try { + byte[] identity = toByte(identityString); + byte[] peerIdByte = this.newClientInternal(identity, "", bloxAddr, "", true, true, true); + + String peerIdReturned = Arrays.toString(peerIdByte); + Log.d("ReactNative", "newClient peerIdReturned= " + peerIdReturned); + String peerId = this.fula.id(); + Log.d("ReactNative", "newClient peerId= " + peerId); + byte[] bytes = {1, 85, 18, 32, 11, -31, 75, -78, -109, 11, -111, 97, -47, -78, -22, 84, 39, -117, -64, -70, -91, 55, -23, -80, 116, -123, -97, -26, 126, -70, -76, 35, 54, -106, 55, -9}; + + byte[] key = this.fula.put(bytes, 85); + Log.d("ReactNative", "testData put result string="+Arrays.toString(key)); + + byte[] value = this.fula.get(key); + Log.d("ReactNative", "testData get result string="+Arrays.toString(value)); + + this.fula.push(key); + //this.fula.flush(); + + byte[] fetchedVal = this.fula.get(key); + this.fula.pull(key); + + promise.resolve(Arrays.toString(fetchedVal)); + } catch (Exception e) { + Log.d("ReactNative", "ERROR:" + e.getMessage()); + promise.reject(e); + } + } + } diff --git a/example/android/build.gradle b/example/android/build.gradle index 91b6d80..8431b66 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -2,7 +2,7 @@ buildscript { ext { - minSdkVersion = 26 + minSdkVersion = 30 compileSdkVersion = 31 targetSdkVersion = 31 ndkVersion = '25.1.8937393' diff --git a/example/src/App.tsx b/example/src/App.tsx index a42c66d..75963ce 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -131,6 +131,26 @@ const App = () => {