Skip to content

Commit

Permalink
ignore-previous-peers
Browse files Browse the repository at this point in the history
  • Loading branch information
alex2006hw committed Dec 11, 2018
1 parent f758fbb commit cd415dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var ROOT_ATTRIBUTES = "ROOT/ATTRIBUTES";
var ROOT_CONTRACTS = "ROOT/CONTRACTS";
var ROOT_CHANNELS = "ROOT/CHANNELS";
var GENESIS = 'GENESIS';
var tokenPeers = [];

/**
* Create a new token or connect to existing by providing OPTIONS = { id: id, peers: peer || [peers] }
Expand Down Expand Up @@ -97,11 +98,16 @@ module.exports = function(CB, OPTIONS) {
token.get('ROOT').put(ROOT);
token.get('id').put(id);

broadcast.get('PING').put(id)
broadcast.get('PONG').on((peer) => {
if (peer === id) return
token.get('PEERS').put(peer);
});

token.get('PEERS').once((peer) => {
if (tokenPeers.indexOf(peer) === -1) {
broadcast.get('PING').put(id)
broadcast.get('PONG').on((peer) => {
if (peer === id) return
token.get('PEERS').put(peer);
tokenPeers.push(peer);
});
};
});
CB({id: id, root: root, token: token, broadcast: broadcast, listen: listen});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "token-memory",
"version": "0.2.0",
"version": "0.2.1",
"description": "Durable distributed memory token",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit cd415dd

Please sign in to comment.