Konubinix' opinionated web of thoughts

Gundb

Fleeting

GUN documentation

GUN is fully decentralized (peer-to-peer or multi-master), meaning that changes are not controlled by a centralized server. A server can be just another peer in the network, one that may have more reliable resources than a browser. You save data on one machine, and it will sync it to other peers without needing a complex consensus protocol. It just works.

https://gun.eco/docs/

we recommend you include these dependencies with your app, rather than trusting a public CDN

https://gun.eco/docs/Todo-Dapp

Browsers (and internet firewalls) and even WebRTC, for legacy security reasons, won’t let you directly connect to other machines unless they have a publicly accessible IP address (your localhost might! If you have an IPv6 address and no firewall). To get around this, WebRTC uses public “signaling servers” to coordinate where non-IPv6 peers (like a browser) are, and then attempts to establish a P2P connection if possible.

https://gun.eco/docs/Todo-Dapp

If you want to have meta information about the relationship, simply create an “edge” node that both properties point to instead. Many graph databases do this by default, but because not all data structures require it, gun leaves it to you to specify.

https://gun.eco/docs/Graph-Guide

Am I connected

Am I Connected? (Peer counting) There’s currently no single method provisioned to quickly check whether you’re connected, or to how many peers. However, you can retrieve gun’s backend list of peers, and then filter the list on specific parameters (which might change as Gun is currently reaching an alchemical state of transmutation).

const opt_peers = gun.back(‘opt.peers’); // get peers, as configured in the setup let connectedPeers = _.filter(Object.values(opt_peers), (peer) > { return peer && peer.wire && peer.wire.readyState == 1 && peer.wire.OPEN = 1 && peer.wire.constructor.name = ‘WebSocket’; }); The length of connectedPeers corresponds to the connected peers, which you can now use in your UI.

Reconnecting Here again, due to convoluted reasons which need high priority addressing, after going offline and then hopping back on, GUN doesn’t reliably re-connect to its peers (unless you’d refresh the page/app). In some cases, the peers even get removed from the opt.peers list which we’ve accessed above to count connected peers.

It’s being debated how to approach this most reasonably. In the meantime you can trigger a reconnect by re-adding the peers to GUN’s opt list using the following code:

gun.opt({peers: [‘http://server1.com/gun’, ‘http://server2.com/gun’]}); // re-add peers to GUN-options

gun.get(‘heartbeat’).put(“heartbeat”) // optional: tell GUN to put something small, forcing GUN to establish connection, as GUN is lazy by nature to make it save on data transfer. In the case of counting your peers using the previous example, after reconnecting you’ll see the peer count go back up.

https://gun.eco/docs/API#options

Notes linking here