Merge pull request #262 from orbitdb/fix/replicate-wrong-heads

Fix replication starting from wrong heads
This commit is contained in:
Haad 2017-12-02 13:46:44 +01:00 committed by GitHub
commit f5d715c189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 231 additions and 157 deletions

12
dist/es5/OrbitDB.js vendored
View File

@ -4,10 +4,6 @@ var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
var _setImmediate2 = require('babel-runtime/core-js/set-immediate');
var _setImmediate3 = _interopRequireDefault(_setImmediate2);
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
@ -203,12 +199,8 @@ var OrbitDB = function () {
}, {
key: '_onWrite',
value: function _onWrite(address, entry, heads) {
var _this = this;
if (!heads) throw new Error("'heads' not defined");
if (this._pubsub) (0, _setImmediate3.default)(function () {
return _this._pubsub.publish(address, heads);
});
if (this._pubsub) this._pubsub.publish(address, heads);
}
// Callback for receiving a message from the network
@ -236,7 +228,7 @@ var OrbitDB = function () {
// Send the newly connected peer our latest heads
var heads = store._oplog.heads;
if (heads.length > 0) {
logger.debug('Send latest heads:\n', (0, _stringify2.default)(heads, null, 2));
logger.debug('Send latest heads of \'' + address + '\':\n', (0, _stringify2.default)(heads, null, 2));
room.sendTo(peer, new Buffer((0, _stringify2.default)(heads)));
}
store.events.emit('peer', peer);

2
dist/orbitdb.min.js vendored

File diff suppressed because one or more lines are too long

300
package-lock.json generated
View File

@ -224,9 +224,9 @@
"dev": true
},
"asn1.js": {
"version": "4.9.2",
"resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-4.9.2.tgz",
"integrity": "sha512-b/OsSjvWEo8Pi8H0zsDd2P6Uqo2TK2pH8gNLSJtNLM2Db0v2QaAZ0pBQJXVjAn4gBuugeVDr7s63ZogpUIwWDg==",
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-5.0.0.tgz",
"integrity": "sha512-Y+FKviD0uyIWWo/xE0XkUl0x1allKFhzEVJ+//2Dgqpy+n+B77MlPNqvyk7Vx50M9XyVzjnRhDqJAEAsyivlbA==",
"dev": true,
"requires": {
"bn.js": "4.11.8",
@ -1019,9 +1019,9 @@
}
},
"boxen": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/boxen/-/boxen-1.2.2.tgz",
"integrity": "sha1-Px1AMsMP/qnUsCwyLq8up0HcvOU=",
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/boxen/-/boxen-1.3.0.tgz",
"integrity": "sha512-TNPjfTr432qx7yOjQyaXm3dSR0MH9vXp7eT1BFSl/C51g+EFnOR9hTg1IreahGBmDNCehscshe45f+C1TBZbLw==",
"dev": true,
"requires": {
"ansi-align": "2.0.0",
@ -1030,7 +1030,7 @@
"cli-boxes": "1.0.0",
"string-width": "2.1.1",
"term-size": "1.2.0",
"widest-line": "1.0.0"
"widest-line": "2.0.0"
},
"dependencies": {
"ansi-regex": {
@ -1787,7 +1787,7 @@
"dev": true,
"requires": {
"async": "2.6.0",
"libp2p-crypto": "0.10.3",
"libp2p-crypto": "0.10.4",
"pull-defer": "0.2.2",
"pull-stream": "3.6.1",
"uuid": "3.1.0"
@ -1827,9 +1827,9 @@
"dev": true
},
"debug": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.0.1.tgz",
"integrity": "sha512-6nVc6S36qbt/mutyt+UGMnawAMrPDZUPQjRZI3FS9tCtDRhvxJbK79unYBLPi+z5SLXQ3ftoVBFCblQtNSls8w==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
@ -2389,7 +2389,7 @@
"ethereum-common": "0.2.0",
"ethereumjs-tx": "1.3.3",
"ethereumjs-util": "5.1.2",
"merkle-patricia-tree": "2.2.0"
"merkle-patricia-tree": "2.3.0"
},
"dependencies": {
"ethereumjs-util": {
@ -4922,11 +4922,11 @@
"dev": true
},
"hyperdiff": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/hyperdiff/-/hyperdiff-2.0.3.tgz",
"integrity": "sha512-NAJxMV58m7Riefe0HAVt6gQx9KgRrYIBdd2dKLZ0wzdyNJlwO3gNPt8SXNxh8VrO5eOrp3ipdOePpPdPircKLw==",
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/hyperdiff/-/hyperdiff-2.0.4.tgz",
"integrity": "sha512-rCRkwmjC2+X7YHyki1t/RCYD6NGWc9OGQiLyhSUArPWSfAeeGGBfUTApvfMEfGFov/zaVmssPWk8FN26Cz9yrQ==",
"requires": {
"debug": "3.0.1",
"debug": "3.1.0",
"lodash.clonedeep": "4.5.0",
"lodash.pullat": "4.6.0"
}
@ -5112,7 +5112,7 @@
"bl": "1.2.1",
"boom": "5.2.0",
"cids": "0.5.2",
"debug": "3.0.1",
"debug": "3.1.0",
"file-type": "6.2.0",
"filesize": "3.5.11",
"fsm-event": "2.1.0",
@ -5153,9 +5153,9 @@
"multihashes": "0.4.12",
"once": "1.4.0",
"path-exists": "3.0.0",
"peer-book": "0.5.1",
"peer-id": "0.10.2",
"peer-info": "0.11.1",
"peer-book": "0.5.2",
"peer-id": "0.10.3",
"peer-info": "0.11.3",
"prom-client": "10.2.2",
"prometheus-gc-stats": "0.5.0",
"promisify-es6": "1.0.3",
@ -5227,7 +5227,7 @@
"dev": true,
"requires": {
"async": "2.6.0",
"libp2p-crypto": "0.10.3",
"libp2p-crypto": "0.10.4",
"pull-defer": "0.2.2",
"pull-stream": "3.6.1",
"uuid": "3.1.0"
@ -5340,7 +5340,7 @@
"glob-escape": "0.0.2",
"ipfs-block": "0.6.1",
"ipfs-unixfs": "0.1.14",
"ipld-dag-pb": "0.11.3",
"ipld-dag-pb": "0.11.4",
"is-ipfs": "0.3.2",
"is-stream": "1.1.0",
"lru-cache": "4.1.1",
@ -5349,8 +5349,8 @@
"multipart-stream": "2.0.1",
"ndjson": "1.5.0",
"once": "1.4.0",
"peer-id": "0.10.2",
"peer-info": "0.11.1",
"peer-id": "0.10.3",
"peer-info": "0.11.3",
"promisify-es6": "1.0.3",
"pump": "1.0.3",
"qs": "6.5.1",
@ -5388,17 +5388,6 @@
"pull-stream": "3.6.1",
"safe-buffer": "5.1.1",
"varint-decoder": "0.1.1"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
}
}
},
"ipfs-block": {
@ -5436,9 +5425,9 @@
}
},
"ipfs-pubsub-room": {
"version": "git+https://github.com/haadcode/ipfs-pubsub-room.git#abc74650fc57a22ce0c31754b9667a6948e549d0",
"version": "github:haadcode/ipfs-pubsub-room#207f57f4715c9ae835d1f1ce30e9f311966d7687",
"requires": {
"hyperdiff": "2.0.3",
"hyperdiff": "2.0.4",
"lodash.clonedeep": "4.5.0",
"pull-pushable": "2.1.1",
"pull-stream": "3.6.1",
@ -5493,15 +5482,6 @@
"write-file-atomic": "2.3.0"
}
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"level-js": {
"version": "github:timkuijsten/level.js#18e03adab34c49523be7d3d58fafb0c632f61303",
"dev": true,
@ -5551,7 +5531,7 @@
"cids": "0.5.2",
"deep-extend": "0.5.0",
"ipfs-unixfs": "0.1.14",
"ipld-dag-pb": "0.11.3",
"ipld-dag-pb": "0.11.4",
"ipld-resolver": "0.13.4",
"left-pad": "1.2.0",
"lodash": "4.17.4",
@ -5596,9 +5576,9 @@
}
},
"ipld-dag-pb": {
"version": "0.11.3",
"resolved": "https://registry.npmjs.org/ipld-dag-pb/-/ipld-dag-pb-0.11.3.tgz",
"integrity": "sha512-EVu9hxlvvZQyEmV27vokBJbi3EgAJZYPYAbEvutcW3gQidADlgRx8R7WJ6+w/aL80H6ZyMuzR/8JT91YsoZNeA==",
"version": "0.11.4",
"resolved": "https://registry.npmjs.org/ipld-dag-pb/-/ipld-dag-pb-0.11.4.tgz",
"integrity": "sha512-A514Bt4z44bxhPQVzmBFMJsV3res92eBaDX0snzVsLLasBPNh4Z7He8N2mwSeAX9bJNywRBlJbHMQPwC45rqXw==",
"dev": true,
"requires": {
"async": "2.6.0",
@ -5627,7 +5607,7 @@
"ethereumjs-block": "1.7.0",
"ethereumjs-tx": "1.3.3",
"ipfs-block": "0.6.1",
"merkle-patricia-tree": "2.2.0",
"merkle-patricia-tree": "2.3.0",
"multihashes": "0.4.12",
"multihashing-async": "0.4.7",
"rlp": "2.0.0"
@ -5670,7 +5650,7 @@
"ipfs-block-service": "0.12.0",
"ipfs-repo": "0.17.0",
"ipld-dag-cbor": "0.11.2",
"ipld-dag-pb": "0.11.3",
"ipld-dag-pb": "0.11.4",
"ipld-ethereum": "1.4.4",
"ipld-git": "0.1.1",
"ipld-raw": "1.0.7",
@ -5743,7 +5723,7 @@
"dev": true,
"requires": {
"async": "2.6.0",
"libp2p-crypto": "0.10.3",
"libp2p-crypto": "0.10.4",
"pull-defer": "0.2.2",
"pull-stream": "3.6.1",
"uuid": "3.1.0"
@ -6407,18 +6387,18 @@
"libp2p-swarm": "0.32.4",
"mafmt": "3.0.2",
"multiaddr": "3.0.1",
"peer-book": "0.5.1",
"peer-id": "0.10.2",
"peer-info": "0.11.1"
"peer-book": "0.5.2",
"peer-id": "0.10.3",
"peer-info": "0.11.3"
}
},
"libp2p-crypto": {
"version": "0.10.3",
"resolved": "https://registry.npmjs.org/libp2p-crypto/-/libp2p-crypto-0.10.3.tgz",
"integrity": "sha512-E03YpbwOOQzEunR0OpWtuU8LPcBJnVZEfwCsVP17ngLH5pMhzIy3t9imEOkMT6vLnsxe25Q/HIiipNgRDxyd5g==",
"version": "0.10.4",
"resolved": "https://registry.npmjs.org/libp2p-crypto/-/libp2p-crypto-0.10.4.tgz",
"integrity": "sha512-jNEs0/LouDqMGEE9hN1yRfkeFtDrgMbEGPy5xE/y2OVWr9WFU5S/u/tlpF3aeT0b/xhy/zCtSZ/PjzviJwuv5w==",
"dev": true,
"requires": {
"asn1.js": "4.9.2",
"asn1.js": "5.0.0",
"async": "2.6.0",
"browserify-aes": "1.1.1",
"keypair": "1.0.1",
@ -6451,9 +6431,9 @@
"dev": true,
"requires": {
"async": "2.6.0",
"debug": "3.0.1",
"debug": "3.1.0",
"length-prefixed-stream": "1.5.1",
"libp2p-crypto": "0.10.3",
"libp2p-crypto": "0.10.4",
"lodash.values": "4.3.0",
"protons": "1.0.0",
"pull-pushable": "2.1.1",
@ -6467,8 +6447,8 @@
"dev": true,
"requires": {
"multiaddr": "3.0.1",
"peer-id": "0.10.2",
"peer-info": "0.11.1",
"peer-id": "0.10.3",
"peer-info": "0.11.3",
"protons": "1.0.0",
"pull-length-prefixed": "1.3.0",
"pull-stream": "3.6.1"
@ -6483,16 +6463,16 @@
"async": "2.6.0",
"base32.js": "0.1.0",
"cids": "0.5.2",
"debug": "3.0.1",
"debug": "3.1.0",
"hashlru": "2.2.0",
"heap": "0.2.6",
"interface-datastore": "0.3.1",
"k-bucket": "3.3.0",
"libp2p-crypto": "0.10.3",
"libp2p-crypto": "0.10.4",
"libp2p-record": "0.5.1",
"multihashing-async": "0.4.7",
"peer-id": "0.10.2",
"peer-info": "0.11.1",
"peer-id": "0.10.3",
"peer-info": "0.11.3",
"priorityqueue": "0.2.0",
"protons": "1.0.0",
"pull-length-prefixed": "1.3.0",
@ -6509,7 +6489,7 @@
"dev": true,
"requires": {
"async": "2.6.0",
"libp2p-crypto": "0.10.3",
"libp2p-crypto": "0.10.4",
"pull-defer": "0.2.2",
"pull-stream": "3.6.1",
"uuid": "3.1.0"
@ -6526,8 +6506,8 @@
"libp2p-tcp": "0.11.1",
"multiaddr": "3.0.1",
"multicast-dns": "6.2.1",
"peer-id": "0.10.2",
"peer-info": "0.11.1"
"peer-id": "0.10.3",
"peer-info": "0.11.3"
}
},
"libp2p-multiplex": {
@ -6550,7 +6530,7 @@
"integrity": "sha512-e+J3IsF6B1oV4l534di/5kyAIJ1wjzACdpYpHF87pdEX+CFJGgCtYa2Kup/vWiBumuEsb2VtWWVlNmZS2HV/FQ==",
"dev": true,
"requires": {
"libp2p-crypto": "0.10.3",
"libp2p-crypto": "0.10.4",
"pull-handshake": "1.1.4",
"pull-stream": "3.6.1"
}
@ -6562,11 +6542,11 @@
"dev": true,
"requires": {
"async": "2.6.0",
"debug": "3.0.1",
"debug": "3.1.0",
"lodash": "4.17.4",
"multiaddr": "3.0.1",
"peer-id": "0.10.2",
"peer-info": "0.11.1"
"peer-id": "0.10.3",
"peer-info": "0.11.3"
}
},
"libp2p-record": {
@ -6580,7 +6560,7 @@
"left-pad": "1.2.0",
"multihashes": "0.4.12",
"multihashing-async": "0.4.7",
"peer-id": "0.10.2",
"peer-id": "0.10.3",
"protons": "1.0.0"
}
},
@ -6591,11 +6571,11 @@
"dev": true,
"requires": {
"async": "2.6.0",
"debug": "3.0.1",
"debug": "3.1.0",
"interface-connection": "0.3.2",
"libp2p-crypto": "0.10.3",
"libp2p-crypto": "0.10.4",
"multihashing-async": "0.4.7",
"peer-id": "0.10.2",
"peer-id": "0.10.3",
"protons": "1.0.0",
"pull-defer": "0.2.2",
"pull-handshake": "1.1.4",
@ -6611,7 +6591,7 @@
"requires": {
"async": "2.6.0",
"browserify-zlib-next": "1.0.1",
"debug": "3.0.1",
"debug": "3.1.0",
"interface-connection": "0.3.2",
"ip-address": "5.8.8",
"libp2p-identify": "0.6.1",
@ -6619,8 +6599,8 @@
"multiaddr": "3.0.1",
"multistream-select": "0.13.5",
"once": "1.4.0",
"peer-id": "0.10.2",
"peer-info": "0.11.1",
"peer-id": "0.10.3",
"peer-info": "0.11.3",
"pull-stream": "3.6.1"
}
},
@ -6657,8 +6637,8 @@
"minimist": "1.2.0",
"multiaddr": "3.0.1",
"once": "1.4.0",
"peer-id": "0.10.2",
"peer-info": "0.11.1",
"peer-id": "0.10.3",
"peer-info": "0.11.3",
"pull-stream": "3.6.1",
"simple-peer": "8.1.1",
"socket.io": "2.0.4",
@ -6667,15 +6647,6 @@
"webrtcsupport": "github:ipfs/webrtcsupport#0669f576582c53a3a42aa5ac014fcc5966809615"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
@ -7065,13 +7036,13 @@
}
},
"merkle-patricia-tree": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/merkle-patricia-tree/-/merkle-patricia-tree-2.2.0.tgz",
"integrity": "sha1-ekeHsSYqsA/psgSrRxsAUzIwbvo=",
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/merkle-patricia-tree/-/merkle-patricia-tree-2.3.0.tgz",
"integrity": "sha512-LKd2OoIT9Re/OG38zXbd5pyHIk2IfcOUczCwkYXl5iJIbufg9nqpweh66VfPwMkUlrEvc7YVvtQdmSrB9V9TkQ==",
"dev": true,
"requires": {
"async": "1.5.2",
"ethereumjs-util": "4.5.0",
"ethereumjs-util": "5.1.2",
"level-ws": "0.0.0",
"levelup": "1.3.9",
"memdown": "1.4.1",
@ -7085,6 +7056,22 @@
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz",
"integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=",
"dev": true
},
"ethereumjs-util": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.1.2.tgz",
"integrity": "sha1-JboCFcu0wvCxCKb5avKi5i5Fkh8=",
"dev": true,
"requires": {
"babel-preset-es2015": "6.24.1",
"babelify": "7.3.0",
"bn.js": "4.11.8",
"create-hash": "1.1.3",
"ethjs-util": "0.1.4",
"keccak": "1.3.0",
"rlp": "2.0.0",
"secp256k1": "3.3.1"
}
}
}
},
@ -7232,15 +7219,6 @@
"integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==",
"dev": true
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"supports-color": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz",
@ -7670,7 +7648,7 @@
"integrity": "sha512-DiPoIojzwy2qHvvhp+jgY6FNwul9hjLd2EhYgmSJcimCIVCbArNxCgJlOiZhUClVRcDXP14ZvpJjDGc/JNXrxA==",
"requires": {
"crdts": "0.0.1",
"orbit-db-store": "2.0.3"
"orbit-db-store": "2.0.4"
}
},
"orbit-db-docstore": {
@ -7678,7 +7656,7 @@
"resolved": "https://registry.npmjs.org/orbit-db-docstore/-/orbit-db-docstore-1.0.1.tgz",
"integrity": "sha512-fxXkqtmGs2VSawayoPckzePQ7HNlrvomQFGBX2jCKeSeKkBtei8gTUHNjrK5rPg2V9Nn5hgoO6YLHSS4YkLvwg==",
"requires": {
"orbit-db-store": "2.0.3",
"orbit-db-store": "2.0.4",
"p-map": "1.2.0"
}
},
@ -7687,7 +7665,7 @@
"resolved": "https://registry.npmjs.org/orbit-db-eventstore/-/orbit-db-eventstore-1.0.0.tgz",
"integrity": "sha512-wvDPLKoqxnj1Oz+710n2CjyGNzpoYcT0ldYam2EzYzNkMBxmFOqYKiVddew6RslskzivTTV0KALiCLnjlMmaoA==",
"requires": {
"orbit-db-store": "2.0.3"
"orbit-db-store": "2.0.4"
}
},
"orbit-db-feedstore": {
@ -7713,22 +7691,22 @@
"resolved": "https://registry.npmjs.org/orbit-db-kvstore/-/orbit-db-kvstore-1.0.0.tgz",
"integrity": "sha512-c0CfFb/2l2h5CCKSD646ofv/xfK2vUoQtvQYRzbJc6brj+p4n1aOCzjoXLkpXg3/5/VZho1sYvFsqYtNSGeiuw==",
"requires": {
"orbit-db-store": "2.0.3"
"orbit-db-store": "2.0.4"
}
},
"orbit-db-pubsub": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/orbit-db-pubsub/-/orbit-db-pubsub-0.3.2.tgz",
"integrity": "sha512-bvhjfhgUYprYqwggPI1u3EOpOWjEenlKwQVOWqGzfJoYIYyyXevaKhp2HiCMRQLenbtoScUmZ3k0yxFElEGgnA==",
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/orbit-db-pubsub/-/orbit-db-pubsub-0.3.3.tgz",
"integrity": "sha512-FlOyoOo8J8dgr+fpRnedCJbYY1ou/WYIsAf+Lv338Fbl3/e6Ef8jDyX93MlyC4pt1yKVEpSLm+eTAe9KNE7mnA==",
"requires": {
"ipfs-pubsub-room": "git+https://github.com/haadcode/ipfs-pubsub-room.git#abc74650fc57a22ce0c31754b9667a6948e549d0",
"ipfs-pubsub-room": "github:haadcode/ipfs-pubsub-room#207f57f4715c9ae835d1f1ce30e9f311966d7687",
"logplease": "1.2.14"
}
},
"orbit-db-store": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/orbit-db-store/-/orbit-db-store-2.0.3.tgz",
"integrity": "sha512-uEOYkeGDruUEbTOTXeWRdSmmDZ2lvOOGxd5lGmYJSgs+llzHjYu7oRIhFLLDosUS1wdLVBO79oyWUUQeJuKQAA==",
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/orbit-db-store/-/orbit-db-store-2.0.4.tgz",
"integrity": "sha512-Sboa/BhnIOLC/iv9cRyDWhlmKF9moTxuWb42xueo9z/OKBG8VhktW+P9jemEoU6Cuih40Kh1s/Rozxm5nYutgQ==",
"requires": {
"ipfs-log": "4.0.4",
"orbit-db-cache": "0.0.7",
@ -7859,6 +7837,19 @@
"create-hash": "1.1.3",
"evp_bytestokey": "1.0.3",
"pbkdf2": "3.0.14"
},
"dependencies": {
"asn1.js": {
"version": "4.9.2",
"resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-4.9.2.tgz",
"integrity": "sha512-b/OsSjvWEo8Pi8H0zsDd2P6Uqo2TK2pH8gNLSJtNLM2Db0v2QaAZ0pBQJXVjAn4gBuugeVDr7s63ZogpUIwWDg==",
"dev": true,
"requires": {
"bn.js": "4.11.8",
"inherits": "2.0.3",
"minimalistic-assert": "1.0.0"
}
}
}
},
"parse-glob": {
@ -7967,37 +7958,37 @@
}
},
"peer-book": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/peer-book/-/peer-book-0.5.1.tgz",
"integrity": "sha512-BDbOU5lWnEczLzoiYfpje3OMVv5TEP70EQqVqqoe/1/PhkVNbjnq80hhDykc9eSKguP4hGyAArywDzd4YjZ76Q==",
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/peer-book/-/peer-book-0.5.2.tgz",
"integrity": "sha512-+BgRdGjVhPJo1AaIyBFPI/Nij1uvyBeowXT5CHGJVjVUlcONK3rl471l9t5oVf0Q31/wEtZTL68Y7l0TctFSHQ==",
"dev": true,
"requires": {
"bs58": "4.0.1",
"peer-id": "0.10.2",
"peer-info": "0.11.1"
"peer-id": "0.10.3",
"peer-info": "0.11.3"
}
},
"peer-id": {
"version": "0.10.2",
"resolved": "https://registry.npmjs.org/peer-id/-/peer-id-0.10.2.tgz",
"integrity": "sha512-E5uxAAhbLylyNE2FNWykyGqsRoiOOfprFOkZfCO7yTBFIJc2Gq+l6XKBeyWTQKR/eUizHbzZgexqEDcqFw84iw==",
"version": "0.10.3",
"resolved": "https://registry.npmjs.org/peer-id/-/peer-id-0.10.3.tgz",
"integrity": "sha512-hwMMPNBFgUkDs7GVXfXDcRIEmuQ29zyi37S+VBKa5G+e28rGRIJAbEEod2dj98cj/janDp19RaP5QKejvW5/gQ==",
"dev": true,
"requires": {
"async": "2.6.0",
"libp2p-crypto": "0.10.3",
"libp2p-crypto": "0.10.4",
"lodash": "4.17.4",
"multihashes": "0.4.12"
}
},
"peer-info": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/peer-info/-/peer-info-0.11.1.tgz",
"integrity": "sha512-CSkBYu6gkEGRCbO7hS4S/drlniMxaZ/oAC7s0XzFDzNB/fTk5pQrgpn261IP4mJCn63leI4+Nl7R2NJecS47QQ==",
"version": "0.11.3",
"resolved": "https://registry.npmjs.org/peer-info/-/peer-info-0.11.3.tgz",
"integrity": "sha512-FzNzL5PYGr7rpHFpoSMdEGwRVb7X9D88YDmTkamXd4CO05bNeHITlrwIV7ctshBhVRTvokpnI59HUSEQly5rnA==",
"dev": true,
"requires": {
"lodash.uniqby": "4.7.0",
"multiaddr": "3.0.1",
"peer-id": "0.10.2"
"peer-id": "0.10.3"
}
},
"pem-jwk": {
@ -9830,7 +9821,7 @@
"integrity": "sha1-TognpruRUUCrCTVZ1wFOPruDdFE=",
"dev": true,
"requires": {
"boxen": "1.2.2",
"boxen": "1.3.0",
"chalk": "2.3.0",
"configstore": "3.1.1",
"import-lazy": "2.1.0",
@ -9992,9 +9983,9 @@
"dev": true
},
"webpack": {
"version": "3.9.0",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-3.9.0.tgz",
"integrity": "sha512-SlBO3yUIhSohW7uCA5c0v03V32DsaXU3vDyUtHB8rubgTgfwl1nv+I+BQIScuQ6exu74wWT6brF/GDXxGLStuA==",
"version": "3.9.1",
"resolved": "https://registry.npmjs.org/webpack/-/webpack-3.9.1.tgz",
"integrity": "sha512-jONJ0l8nqgiQVkqs15O9TFWLozbFkCgVodVrBXBK/PIBFeGkaOGo30Ov57iQqYRwAWNDM5vyLPZYmAIpPa5QSw==",
"dev": true,
"requires": {
"acorn": "5.2.1",
@ -10138,12 +10129,45 @@
}
},
"widest-line": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/widest-line/-/widest-line-1.0.0.tgz",
"integrity": "sha1-DAnIXCqUaD0Nfq+O4JfVZL8OEFw=",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/widest-line/-/widest-line-2.0.0.tgz",
"integrity": "sha1-AUKk6KJD+IgsAjOqDgKBqnYVInM=",
"dev": true,
"requires": {
"string-width": "1.0.2"
"string-width": "2.1.1"
},
"dependencies": {
"ansi-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=",
"dev": true
},
"is-fullwidth-code-point": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
"dev": true
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
"integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
"dev": true,
"requires": {
"is-fullwidth-code-point": "2.0.0",
"strip-ansi": "4.0.0"
}
},
"strip-ansi": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
"dev": true,
"requires": {
"ansi-regex": "3.0.0"
}
}
}
},
"window-size": {

View File

@ -25,7 +25,7 @@
"orbit-db-feedstore": "~1.0.0",
"orbit-db-keystore": "~0.0.2",
"orbit-db-kvstore": "~1.0.0",
"orbit-db-pubsub": "~0.3.1"
"orbit-db-pubsub": "~0.3.3"
},
"devDependencies": {
"babel-core": "^6.26.0",

View File

@ -144,7 +144,7 @@ class OrbitDB {
// Send the newly connected peer our latest heads
let heads = store._oplog.heads
if (heads.length > 0) {
logger.debug(`Send latest heads:\n`, JSON.stringify(heads, null, 2))
logger.debug(`Send latest heads of '${address}':\n`, JSON.stringify(heads, null, 2))
room.sendTo(peer, new Buffer(JSON.stringify(heads)))
}
store.events.emit('peer', peer)

View File

@ -17,7 +17,7 @@ const ipfsPath2 = './orbitdb/tests/replicate-automatically/2/ipfs'
describe('orbit-db - Automatic Replication', function() {
this.timeout(config.timeout)
let ipfs1, ipfs2, orbitdb1, orbitdb2, db1, db2
let ipfs1, ipfs2, orbitdb1, orbitdb2, db1, db2, db3, db4
before(async () => {
config.daemon1.repo = ipfsPath1
@ -28,6 +28,9 @@ describe('orbit-db - Automatic Replication', function() {
rmrf.sync(dbPath2)
ipfs1 = await startIpfs(config.daemon1)
ipfs2 = await startIpfs(config.daemon2)
// Connect the peers manually to speed up test times
await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString())
await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString())
orbitdb1 = new OrbitDB(ipfs1, dbPath1)
orbitdb2 = new OrbitDB(ipfs2, dbPath2)
})
@ -56,11 +59,14 @@ describe('orbit-db - Automatic Replication', function() {
options = Object.assign({}, options, { path: dbPath1 })
db1 = await orbitdb1.eventlog('replicate-automatically-tests', options)
db3 = await orbitdb1.keyvalue('replicate-automatically-tests-kv', options)
})
afterEach(async () => {
await db1.drop()
await db2.drop()
if (db1) await db1.drop()
if (db2) await db2.drop()
if (db3) await db3.drop()
if (db4) await db4.drop()
})
it('starts replicating the database when peers connect', async () => {
@ -97,4 +103,56 @@ describe('orbit-db - Automatic Replication', function() {
})
})
})
it('automatic replication exchanges the correct heads', async () => {
const entryCount = 33
const entryArr = []
let options = {}
let timer
// Create the entries in the first database
for (let i = 0; i < entryCount; i ++)
entryArr.push(i)
await mapSeries(entryArr, (i) => db1.add('hello' + i))
// Open the second database
options = Object.assign({}, options, { path: dbPath2, sync: true })
db2 = await orbitdb2.eventlog(db1.address.toString(), options)
db4 = await orbitdb2.keyvalue(db3.address.toString(), options)
// Listen for the 'replicated' events and check that all the entries
// were replicated to the second database
return new Promise(async (resolve, reject) => {
db4.events.on('replicated', (address, hash, entry) => {
reject(new Error("Should not receive the 'replicated' event!"))
})
// Can't check this for now as db1 might've sent the heads to db2
// before we subscribe to the event
// db2.events.on('replicate.progress', (address, hash, entry) => {
// try {
// // Check that the head we received from the first peer is the latest
// assert.equal(entry.payload.value, 'hello' + (entryCount - 1))
// assert.equal(entry.clock.time, entryCount)
// } catch (e) {
// reject(e)
// }
// })
db2.events.on('replicated', (address) => {
try {
const result1 = db1.iterator({ limit: -1 }).collect()
const result2 = db2.iterator({ limit: -1 }).collect()
// Make sure we have all the entries
if (result1.length === entryCount && result2.length === entryCount) {
assert.deepEqual(result1, result2)
resolve()
}
} catch (e) {
reject(e)
}
})
})
})
})

View File

@ -16,7 +16,7 @@ module.exports = {
Discovery: {
MDNS: {
Enabled: true,
Interval: 10
Interval: 1
},
webRTCStar: {
Enabled: false
@ -40,7 +40,7 @@ module.exports = {
Discovery: {
MDNS: {
Enabled: true,
Interval: 10
Interval: 1
},
webRTCStar: {
Enabled: false
@ -64,7 +64,7 @@ module.exports = {
Discovery: {
MDNS: {
Enabled: true,
Interval: 10
Interval: 1
},
webRTCStar: {
Enabled: false