我试图在浏览器中使用hyperdb,并通过webrtc和signalhub进行蜂拥而至。代码是非常严格的向前,但在超级数据库复制中存在一些问题,因为超级核中的sameKey签入导致连接中断。我在想..。我没有正确地处理我的发现键和id键,所以对等方知道它们应该是同步的。下面是一些示例代码,它有点混乱,但相关的比特是hyperdb初始化和webrtc/signalhub之类的(我认为).顶部的关键是另一个对等点的发现键:
const crypto = require('crypto'),
sha = crypto.createHash('sha1'),
hyperdb = require('hyperdb'),
hyperdiscovery = require('hyperdiscovery'),
cms = require('random-access-idb')('cms'),
webrtc = require('webrtc-swarm'),
signalhub = require('signalhub'),
hyperdrive = require('hyperdrive'),
pump = require('pump');
// Discovery key of other peer/signalhub channel
var key = "cbffda913dabfe73cbd45f64466ffda845383965e66b2aef5f3b716ee6c06528";
const db = hyperdb(filename => {
return cms(filename);
}, { valueEncoding: 'utf-8' });
var DEFAULT_SIGNALHUBS = 'https://signalhub-jccqtwhdwc.now.sh';
db.on('ready', function () {
const swarm = webrtc(signalhub(key, DEFAULT_SIGNALHUBS));
swarm.on('peer', function (conn) {
console.log("PEER!!!!!!!");
const peer = db.replicate({
upload: true,
download: true
});
pump(conn, peer, conn)
});
});发布于 2018-07-13 18:09:33
我在这里举了一个例子:https://github.com/joehand/hyperdb-web-example/blob/master/index.js
我认为您得到了这个错误,因为您没有用键初始化db:
var db = hyperdb(storage, key)一旦你这样做了,你就能得到发现钥匙。通常,您不需要在周围复制发现密钥,因为它总是从公钥生成的。
如果这样做不起作用,请只包括相关代码或一个最小的示例,这样就更容易调试=)。谢谢!
https://stackoverflow.com/questions/51326344
复制相似问题