B4J Library [Web] SithasoGunDB - Offline First Peer to Peer Database using NodeJS and GunDB (with Subscriptions)

Hi Fam

This is a BANano b4xlib to use GunDB (Peer to Peer Database) which is able to store data offline and sync to peers once connected.

1703945472890.png


One can deploy a peer relay using NodeJS. Find it in the example. We are still studying this tech and looking at other deployment possibilities.

The data is stored in IndexedDB.

Check the attached 6 page eBook out on how you can set up your Peer Relay and create a CRUD app with subscriptions (basic example includes) on the

1. Copy the b4xlib to your additional libraries folder.
2. Read the ebook and create your own local NodeJS peer relay and start it.
3. Run the attached example (basic CRUD)
4. You can then implement in your project and test by opening multiple tabs in your browser.


Have Fun.

PS: If you love my work, please consider a certificate of appreciation via Paypal.


Thanks in advance

UPDATED INSTRUCTIONS ON POST #9
 

Attachments

  • SithasoGunDB.pdf
    111.1 KB · Views: 81
  • SithasoGUNDB.b4xlib
    86.1 KB · Views: 47
Last edited:

Magma

Expert
Licensed User
Longtime User

Magma

Expert
Licensed User
Longtime User
What I have learned so far...


1. This can be used WITHOUT a NodeJS peer relay but as a standalone IndexedDB back-end also.
2. It has built in user registration and authentication system. Awesome.
3. Uses SEA for encryption.

Watch this space
When u mean standalone... you mean without p2p nodes..?
 

Mashiane

Expert
Licensed User
Longtime User
When u mean standalone... you mean without p2p nodes..?
You can run it in your browser without a nodejs peer relay installed. I.e no need to set up nodejs and run the nodejs app attached.

The data will stored either in localstorage or indexeddb as a back end as usual as in the nodejs example there is no back end setup.

You will still be able to run your app as a peer between the different tabs of your browser and these will sync in real time.

This means your app will work without connections to external relays but just on your browser with your data persisted.

I hope it's clear.
 

Magma

Expert
Licensed User
Longtime User
You can run it in your browser without a nodejs peer relay installed. I.e no need to set up nodejs and run the nodejs app attached.

The data will stored either in localstorage or indexeddb as a back end as usual as in the nodejs example there is no back end setup.

You will still be able to run your app as a peer between the different tabs of your browser and these will sync in real time.

This means your app will work without connections to external relays but just on your browser with your data persisted.

I hope it's clear.
I see..

But this how gun .js works with the Sithaso solution...

The java solution.. Need to run somewhere node.js too ? To multicast? Or doing that somehow on its code.. (don't read about it yet.. how it works)
 

Mashiane

Expert
Licensed User
Longtime User
But this how gun .js works with the Sithaso solution...
SithasoDB is built to be used with any BANano project, which in essence, is just JavaScript.

Whilst I sent you the java related content to this, I have also not looked at it and how it works, so sadly I cant really answer you on that one. I assume it could work with b4j jserver or something, not sure.

Like I mentioned before, there is no need for NodeJS if you will run GunDB as a stand-alone using IndexedDB, however for peer to peer use, you need some kind of peer relay.

I am actually talking about SEA here

 

Mashiane

Expert
Licensed User
Longtime User
Version 1.01

Bug fixes and simpler to use library.

NodeJS Peer Relay


1. Install NodeJS
2. Clone the Repo
3. CD to the repo folder and execute "npm install"
4. Execute "node run start"
5. Peer Relay should run on http://localhost://8765"

1704744628559.png
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User

Magma

Expert
Licensed User
Longtime User
Hi Mashiane... one question... or may be more

1. The example you have is only for local lan... or automatically if PnP Router... finding nodes in the world and cloning db ? (or parts of it)...

2. I understand that you can "clone-share" the db ofcourse to all nodes in the world but when having special user-permissions those data kept encrypted and not shared - right ?

is something like blockchains... sharing all the index between nodes... but not the whole data if not having the special key (coin)..

3. If not sharing to all nodes... targetting any Central or Many Index Node that you can have ? and what step of tutorial is that ?

or am I missing something ?
 

Mashiane

Expert
Licensed User
Longtime User
Version 1.02

Below is an example of what has been added.

1. Ability to store a list of registered users using their "alias" and public key. This is just an optional feature, which might be useful
2. The alias cannot contain '@' or '.' as these are used for paths. The example has been updated to include username.
3. When a user is registered, a "profile" collection is added to his / her account. This is private and encrypted for the user.
4. One is able to view a list of all registered users in the master node implementation.
5. When allowing people to "write" to your private data, you can provide them the "pub" key.
6. You can subscribe to the list of users.

1704801889130.png
 

Mashiane

Expert
Licensed User
Longtime User
1. The example you have is only for local lan... or automatically if PnP Router... finding nodes in the world and cloning db ? (or parts of it)...
I excluded the NodeJS part in the example because I didnt want to create confusion. You can create as many nodes as you want and add them to the project using .AddPeer.
The data you write to the db & read will first be written to IndexedDB, in case a peer gets disconnected / becomes unavailable. As soon as a peer is online, your data will be synced to the other peers, provided they are subscribed to it.

Also, if you are subscribed to content that is "stored" in another peer, it will be synced with your IndexedDB to be available for you. To avoid loading everything at ones, the subscription model is used. Thus the cloning will be on everything you want to "watch".

2. I understand that you can "clone-share" the db ofcourse to all nodes in the world but when having special user-permissions those data kept encrypted and not shared - right ?
Yes. There are 3 sets of data storage, 2.1 public, 2.2 user and 2.3 frozen.

2.1 Content in public is accessible to everyone. They can read & write & delete it
2.2 User is available to everyone but people cannot write / delete it, only the user can. This content can be encrypted by the user and secrets shared between people who will have access to it. The public who sees the content sees is as encrypted data. In the example, I added Email, First and LastName in the "profile" collection of the user. Only the logged user has access to that information for write/delete. Others can see it but wont. If I wanted that data to be encrypted, then I will add that for reading & writing.
2.3 Frozen space is basically that, frozen. You write to it using a hash and no one can do anything to it.

3. If not sharing to all nodes... targetting any Central or Many Index Node that you can have ? and what step of tutorial is that ?
Yes you can. This is a key-value store database afterall. You can use if for anything actually. They just don't recommend banking apps for it. I will be making a CRUD example soon also including a chat app in the future.

4. Relaying to others.
You need a relay peer server to do this otherwise content will not be relayed to others on the network. Perhaps I can get lucky deploying the NodeJS code somewhere to explore this.

You can also find details about gunDB from their site, https://gun.eco/
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Interesting Reads

 
Top