amark / gun

An open source cybersecurity protocol for syncing decentralized graph data.
https://gun.eco/docs
Other
18.03k stars 1.16k forks source link

Heroku 1-clicker problems with syncing user graph data #1262

Open colinbrogan opened 2 years ago

colinbrogan commented 2 years ago

I had problems with user graph data syncing between browsers on the heroku 1-clicker. After some investigation, I discovered that the same problem occured when cloning the master branch, and either doing a local docker build, or an npm install from the github source.

In contrast to all of this, if I just ran npm install gun on a seperate folder, and started it from within the node_modules folder, the problem went away, and everything behaved as it should.

Here is the test code:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>

<script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script>

<script type="text/javascript">
    var gun, user, gun_users_test, username;
    document.addEventListener("DOMContentLoaded", function() {

        gun = Gun("http://localhost:8765/gun"); 

        user = gun.user().recall({sessionStorage: true});
        if(user.is) {
            console.log("user is");

            go();
        } else {
            console.log("user is not");
            username = prompt("Enter a username");
            var pass = prompt("Enter a pass");
            user.create(username, pass, function(create_response) {
                user.auth(username, pass, function(a,b) {
                    go();
                });
            });
        }
        console.log(10);
    gun.get('#users').map().on(function(u_pub) {
      console.log("Here is a u_pub");
      console.log(u_pub)
      gun.get("~"+u_pub).get("location").on(function(location) {
        console.log(location);
      });
    });

        function go() {
                publicizeUser(user);
            console.log("go!");
            tinker = 0;
            setInterval(function() {
                console.log(6);
                tinker += 1;
                var location = { x: tinker, y: tinker, username: username };
                user.get("location").put(location);
            }, 500);
        };

        function publicizeUser(user) {
          console.log(1);
          user.once(function(u_data) {
            console.log(2);
            username = u_data.alias;
            console.log(3);
            var hash_prom = SEA.work(u_data.pub, null, null, {name: "SHA-256"});
            console.log(4);
            hash_prom.then(function(hash) {
                gun.get('#users').get(hash).put(u_data.pub);
            });
            console.log(5);
          });
        }

    });
</script>

</body>
</html>

So, the following two approaches for creating the server have problems:

git clone https://github.com/amark/gun gun_from_github
cd gun_from_github
npm install
npm start
# or alternatively ofcourse through docker
docker build -t myrepo/gundb:v1 .
docker run -p 8765:8765 myrepo/gundb:v1

When you open the above html file in 2 browsers, you can see that only the location of the user logged into a given browser tab is logged to console.

Now, if you start a completely new folder and pull from npm:

mkdir gun_from_npm
cd gun_from_npm
npm install gun
cd node_modules/gun
npm start

When you open the html example again in two browser tabs, then both user locations are shown on each tab. This is correct.

Finally, if I then check the version that NPM brought in for me of gun, it outputs: 0.2020.1237 When I looked at the tag of the github master branch, it was set to 0.2019.plus-other-stuff. It appears that the github repo is out of date with your npm package. This wouldn't matter so much, except for the heroku 1-clicker. If you had this version in the github repo as a tag, then I could use heroku to generate a functional relay server for myself.

amark commented 2 years ago

Different things are definitely using different versions. :/ (I'm not very smart with the docker/etc. stuff, help?)

I did publish a new version to NPM recently 0.2020.1238 so hopefully Heroku will now use that?

People also keep talking about "git tag" and I also get very confused with that - how do I delete or deprecate it so it doesn't get loaded or used?