Skip to content

Commit

Permalink
added mdns discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed May 19, 2023
1 parent 4d5c137 commit e3c05f8
Show file tree
Hide file tree
Showing 5 changed files with 701 additions and 801 deletions.
7 changes: 3 additions & 4 deletions android/src/main/java/land/fx/fula/FulaModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,11 @@ public void listPeersFound(Promise promise) {
ThreadUtils.runOnExecutor(() -> {
Log.d("ReactNative", "listPeersFound started");
try {
string res = this.fula.listPeersFound();
String res = this.fula.listPeersFound();

//JSONArray jsonArray = new JSONArray(res);
String s = new String(res, StandardCharsets.UTF_8);
Log.d("ReactNative", "ls: res = " + s);
promise.resolve(s);
Log.d("ReactNative", "listPeersFound: res = " + res);
promise.resolve(res);
} catch (Exception e) {
Log.d("get", e.getMessage());
promise.reject(e);
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * as fula from './protocols/fula';
export * as blox from './protocols/blox';
export * as blockchain from './protocols/blockchain';
export * as chainApi from './protocols/chain-api';
export * as chainApi from './protocols/chain-api';
1 change: 1 addition & 0 deletions src/interfaces/fulaNativeModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface FulaNativeModule {
get: (key: string) => Promise<string>;
has: (key: Uint8Array) => Promise<boolean>;
push: () => Promise<string>;
listFoundPeers: () => Promise<string>;
put: (content: string, codec: string) => Promise<string>;
mkdir: (path: string) => Promise<string>;
writeFileContent: (path: string, content: string) => Promise<string>;
Expand Down
19 changes: 19 additions & 0 deletions src/protocols/blox.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Fula from '../interfaces/fulaNativeModule';

/**
* listFoundPeers uses mdns discovery mechanism to find libp2p peers that are in the same LAN (only backnd nodes).
// this function.
* @returns array
*/
export const listFoundPeers = async(): Promise<string[]> => {
let peers:string[] = [];
try {
let foundPeers:string = await Fula.listFoundPeers();
if (foundPeers != "") {
peers = foundPeers.split(",");
}
} catch (e) {

}
return peers;
};
Loading

0 comments on commit e3c05f8

Please sign in to comment.