4

I'm new to GUN and it looks very promising for the project I'm working on. One thing I haven't been able to make happen is restricting data on a browser peer to just data that it requests or subscribes to with on(). The following example is my very simple test setup: I have two distinct "conversations", each represented by a distinct data node. One browser gets and puts to a "blue" data node, and the other browser gets and puts to a "red" node. Both browsers sync up to a single server peer. I'd like the server peer to store a copy of all data and each browser to only store the data it subscribes to. Using version 0.9.2.

On Browser1, I run the following:

var peers = ['http://localhost:8080/gun',];
var gun = Gun(peers);
var blue = gun.get('blue');
blue.on(data => console.log('Blue update!', data.message));

On Browser2, I run the following:

var peers = ['http://localhost:8080/gun',];
var gun = Gun(peers);
var red = gun.get('red');
red.on(data => console.log('Red update!', data.message));

The server node runs this:

var http = require('http');

var server = http.createServer();
var Gun = require('gun');
var gun = Gun({web: server});

server.listen(8080, function () {
  console.log('Server listening on http://localhost:8080/gun')
})

I then use the console of each browser peer to post some data to the node it is subscribed to. I would expect that each browser's local storage should only contain data for the node it subscribes to, while the server's data.json should contain data for both nodes.

What I see is that the server is storing all data as expected, but in viewing the localstorage I see that the browsers are also storing everything, even the data they've never requested. Is this the intended behavior, or am I missing something? I thought browser peers only store data they subscribed to. While it makes sense for server peers to replicate data to maintain redundancy in the case of failures, I wouldn't want my app clients themselves to be storing countless conversations that they're not a part of.

Thanks for the help!

json
  • 41
  • 4
  • Quick question: Were your Browser 1 regular and Browser 2 incognito? If they both were in the same session, they're using the same localStorage space even if gun isn't. Could you check on that for me? – marknadal Dec 09 '17 at 07:23
  • Thanks, Mark. No, one browser was a Chrome instance, and the other was Firefox. I noticed that if I have just one browser open and I sync with the server, then close it and open the other browser, then each browser's localstorage stays isolated to the data it is using. But when both browsers are connected to the server at the same time, then any data put() will be sent to and stored on both browsers. – json Dec 09 '17 at 07:40
  • Hmm, then yes, something seems wrong here. The localStorage adapter is suppose to have a filter to ignore non-subscribed data, so I may need to get that fixed. Note: This is low priority though. – marknadal Dec 09 '17 at 07:58
  • 1
    Got it. Will keep playing with it and learning. Thanks for the quick response. – json Dec 09 '17 at 08:17
  • Is there a Github issue so we can track this? What is the progress of this? – Levi Roberts Nov 13 '18 at 03:15
  • 1
    I've added an [issue on github](https://github.com/amark/gun/issues/714) with all the details. – skoczen Mar 06 '19 at 22:34

0 Answers0