Unverified Commit 4e06d3d0 authored by Aral Balkan's avatar Aral Balkan
Browse files

Tests passing for hypercore, hyperdb, and hyperdrive

parent 837df3f8
......@@ -12,7 +12,6 @@ class DatEphemeralExtMsg extends EventEmitter {
getWatcher (dat) {
var key = toStr(dat.key)
console.log(`Watching key: ${key}`)
return {key, watcher: this.datWatchers[key]}
}
......@@ -37,10 +36,6 @@ class DatEphemeralExtMsg extends EventEmitter {
var {watcher} = this.getWatcher(dat)
if (watcher) {
var peer = watcher.getPeer(remoteId)
if (peer) {
console.log('Peer', peer.feed.id.toString('hex'))
// console.log('remoteId', remoteId)
}
if (peer) {
return remoteSupports(peer, 'ephemeral')
}
......@@ -113,24 +108,19 @@ class DatWatcher {
}
get hypercore () {
// if dat is a hyperdrive, use the local hypercore
// if dat is a hyperdrive, use the metadata hypercore,
// if it’s hyperdb, use the source hypercore,
// otherwise assume dat is a hypercore already
if (this.dat.metadata) {
console.log('About to return metadata')
return this.dat.metadata
} else if (this.dat.source) {
// This is not the origin node, return the source
console.log('About to return source hypercore', this.dat.source.key.toString('hex'))
return this.dat.source
} else {
console.log('About to return direct hypercore')
return this.dat
}
// return this.dat.local ? this.dat.local : this.dat
}
getPeer (remoteId) {
// console.log(`getPeer: looking up`, remoteId)
remoteId = toRemoteId(remoteId)
return this.hypercore.peers.find(p => isSameId(remoteId, toRemoteId(p)))
}
......@@ -189,16 +179,12 @@ function getPeerProtocolStream (peer) {
function getPeerRemoteId (peer) {
var protocolStream = getPeerProtocolStream(peer)
console.log('Is protocolstream?', !!protocolStream)
if (!protocolStream) return null
console.log('Returning', protocolStream.remoteId.toString('hex'))
return protocolStream.remoteId
}
function remoteSupports (peer, ext) {
var protocolStream = getPeerProtocolStream(peer)
// console.log('Protocol stream', protocolStream)
// console.log(ext)
if (!protocolStream) return false
return protocolStream.remoteSupports(ext)
}
......
......@@ -37,10 +37,11 @@
"dev": true
},
"bitfield-rle": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/bitfield-rle/-/bitfield-rle-2.1.0.tgz",
"integrity": "sha1-rinpOCp7pImN6fSLsj/TOMT73Pg=",
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/bitfield-rle/-/bitfield-rle-2.2.1.tgz",
"integrity": "sha512-wrDhHe7LUkqaytxgbsFXoemzHRv6e8FrVNWWsQCgUfmuVYW6ke44hoGc9VdpjgfIsJ/ejmCFA8wDtDqACNAvyw==",
"requires": {
"buffer-alloc-unsafe": "^1.1.0",
"varint": "^4.0.0"
},
"dependencies": {
......@@ -92,11 +93,6 @@
"resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz",
"integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg=="
},
"buffer-equals": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/buffer-equals/-/buffer-equals-1.0.4.tgz",
"integrity": "sha1-A1O1T9B/2VZBcGca5vZrnPENJ/U="
},
"buffer-fill": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz",
......@@ -138,6 +134,11 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"count-trailing-zeros": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/count-trailing-zeros/-/count-trailing-zeros-1.0.1.tgz",
"integrity": "sha1-q6bFgzvkENRbHso+bVg4RM5oLHc="
},
"deep-equal": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
......@@ -205,6 +206,14 @@
"is-symbol": "^1.0.1"
}
},
"fast-bitfield": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/fast-bitfield/-/fast-bitfield-1.2.2.tgz",
"integrity": "sha512-t8HYqkuE3YEqNcyWlAfh55479aTxO+GpYwvQvJppYqyBfSmRdNIhzY2m09FKN/MENTzq4wH6heHOIvsPyMAwvQ==",
"requires": {
"count-trailing-zeros": "^1.0.1"
}
},
"flat-tree": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/flat-tree/-/flat-tree-1.6.0.tgz",
......@@ -285,25 +294,29 @@
}
},
"hypercore": {
"version": "6.15.0",
"resolved": "https://registry.npmjs.org/hypercore/-/hypercore-6.15.0.tgz",
"integrity": "sha512-H/CyPXt7QYFRRnplmX0O8sAoic/HCJLOtcfZNBl4yXukPhZyiiI6D56xjLTyK3FoMnNOHOviemo7lGsno1nRsA==",
"version": "6.24.0",
"resolved": "https://registry.npmjs.org/hypercore/-/hypercore-6.24.0.tgz",
"integrity": "sha512-mjZl7+UvGKcRAIR33yWxEutahjxE2sG6INJAIQww1btNEOQCmQY0XoA2+zYnYgxRQK2z3MRjRfuHyTZrD4UQOA==",
"requires": {
"array-lru": "^1.1.0",
"atomic-batcher": "^1.0.2",
"bitfield-rle": "^2.0.0",
"bitfield-rle": "^2.2.1",
"buffer-alloc": "^1.2.0",
"buffer-alloc-unsafe": "^1.0.0",
"buffer-equals": "^1.0.4",
"buffer-from": "^1.0.0",
"bulk-write-stream": "^1.1.3",
"codecs": "^1.2.0",
"fast-bitfield": "^1.2.2",
"flat-tree": "^1.6.0",
"from2": "^2.3.0",
"hypercore-crypto": "^1.0.0",
"hypercore-protocol": "^6.4.1",
"inherits": "^2.0.3",
"inspect-custom-symbol": "^1.1.0",
"last-one-wins": "^1.0.4",
"memory-pager": "^1.0.2",
"merkle-tree-stream": "^3.0.3",
"pretty-hash": "^1.0.1",
"process-nextick-args": "^1.0.7",
"random-access-file": "^2.0.1",
"sodium-universal": "^2.0.0",
......@@ -314,6 +327,17 @@
"unordered-set": "^2.0.0"
}
},
"hypercore-crypto": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/hypercore-crypto/-/hypercore-crypto-1.0.0.tgz",
"integrity": "sha512-xFwOnNlOt8L+SovC7dTNchKaNYJb5l8rKZZwpWQnCme1r7CU4Hlhp1RDqPES6b0OpS7DkTo9iU0GltQGkpsjMw==",
"requires": {
"buffer-alloc-unsafe": "^1.1.0",
"buffer-from": "^1.1.0",
"sodium-universal": "^2.0.0",
"uint64be": "^2.0.2"
}
},
"hypercore-protocol": {
"version": "6.6.4",
"resolved": "https://registry.npmjs.org/hypercore-protocol/-/hypercore-protocol-6.6.4.tgz",
......@@ -394,6 +418,11 @@
"integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==",
"optional": true
},
"inspect-custom-symbol": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/inspect-custom-symbol/-/inspect-custom-symbol-1.1.0.tgz",
"integrity": "sha512-vtI2YXBRZBkU6DlfHfd0GtZENfiEiTacAXUd0ZY6HA+X7aPznpFfPmzSC+tHKXAkz9KDSdI4AYfwAMXR5t+isg=="
},
"is-callable": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.3.tgz",
......@@ -444,9 +473,9 @@
"integrity": "sha1-wb/Qy8tGeQ7JFWuNGu6Py4bNoio="
},
"memory-pager": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.1.0.tgz",
"integrity": "sha512-Mf9OHV/Y7h6YWDxTzX/b4ZZ4oh9NSXblQL8dtPCOomOtZciEHxePR78+uHFLLlsk01A6jVHhHsQZZ/WcIPpnzg=="
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
"integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg=="
},
"merkle-tree-stream": {
"version": "3.0.3",
......@@ -552,6 +581,11 @@
"integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=",
"dev": true
},
"pretty-hash": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pretty-hash/-/pretty-hash-1.0.1.tgz",
"integrity": "sha1-FuBXkYje9WvbVliSvNBaXWUySAc="
},
"process-nextick-args": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
......
var tape = require('tape')
var database = require('hyperdb')
var database = require('hyperdrive')
var ram = require('random-access-memory')
var {DatEphemeralExtMsg} = require('./')
......@@ -16,33 +16,48 @@ tape('exchange ephemeral messages', function (t) {
var clone
var cloneFeed
// Isomorphic interface to support hypercore, hyperdb, and hyperdrive
var self = this
// Isomorphic interface to support hypercore, hyperdb, and hyperdrive.
// The three packages have slightly different APIs that makes this necessary.
// TODO: open issue for unifying the interfaces.
var srcFeed = src.source || src.metadata || src
var putFunction = isHyperdrive ? 'writeFile' : 'put'
var putFunction = isHyperdrive ? 'writeFile' : isHyperDB ? 'put' : 'append'
firstCallback = (err) => {
t.error(err, 'no error')
src[putFunction].apply(src, secondArgs)
}
secondCallback = (err) => {
t.error(err, 'no error')
src[putFunction].apply(src, thirdArgs)
}
thirdCallback = (err) => {
t.error(err, 'no error')
if (isHyperdrive) {
t.same(src.version, 3, 'version correct')
}
// generate clone instance
clone = database(ram, src.key)
cloneFeed = clone.source || clone.metadata || clone
clone.on('ready', startReplication)
}
var firstArgs = (isHyperdrive || isHyperDB) ? ['/first.txt', 'number 1', firstCallback] : ['first', firstCallback]
var secondArgs = (isHyperdrive || isHyperDB) ? ['/second.txt', 'number 2', secondCallback] : ['second', secondCallback]
var thirdArgs = (isHyperdrive || isHyperDB) ? ['/third.txt', 'number 3', thirdCallback] : ['first', thirdCallback]
src.on('ready', function () {
// generate source archive
t.ok(srcFeed.writable)
src[putFunction]('/first.txt', 'number 1', function (err) {
t.error(err, 'no error')
src[putFunction]('/second.txt', 'number 2', function (err) {
t.error(err, 'no error')
src[putFunction]('/third.txt', 'number 3', function (err) {
t.error(err, 'no error')
// t.same(src.version, 3, 'version correct')
// generate clone instance
clone = database(ram, src.key)
cloneFeed = clone.source || clone.metadata || clone
clone.on('ready', startReplication)
})
})
})
src[putFunction].apply(src, firstArgs)
})
function startReplication () {
console.log('Starting replication')
// wire up archives
srcEphemeral.watchDat(src)
cloneEphemeral.watchDat(clone)
......@@ -52,7 +67,6 @@ tape('exchange ephemeral messages', function (t) {
srcEphemeral.on('message', onMessage1)
cloneEphemeral.on('message', onMessage1)
function onMessage1 (archive, peer, msg) {
console.log('MESSAGE')
if (archive === src) {
// received clone's data
t.same(msg.contentType, 'application/json', 'received clone data')
......@@ -86,10 +100,9 @@ tape('exchange ephemeral messages', function (t) {
stream1.on('handshake', gotHandshake)
stream2.on('handshake', gotHandshake)
function gotHandshake () {
if (++handshakeCount !== 2) return
console.log('Handshake count', handshakeCount)
// has support
t.ok(srcEphemeral.hasSupport(src, srcFeed.peers[0]), 'src has support')
t.ok(cloneEphemeral.hasSupport(clone, cloneFeed.peers[0]), 'clone has support')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment