Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connecting across browser, to server, to an IPFS API node.js instance #496

Closed
aphelionz opened this issue Nov 10, 2018 · 3 comments
Closed

Comments

@aphelionz
Copy link
Member

aphelionz commented Nov 10, 2018

Advanced implementation question - I have:

[browser node (js-ipfs)] <---> [server node (go-ipfs)] <----> [node.js orbitdb controller (js-ipfs-api)]

The following test works in the browser node, with data that node.js controller created.:

var dbaddr = "/orbitdb/Qm............/testDB"
var db = await orbitdb.open(dbaddr);
await db.load();
setTimeout(function() {
  var entries = db.iterator({ limit: -1 }).collect();
  assert.equal(entries.length, 5, "tlTestDB read from server");
  done();
}, 2000)

However, trying to move data in the opposite direction doesn't work.

In the browser, after ensuring peers are connected.

var url = `https://myapi.com/test-db/?peer=${peerID}&addr=${db.id}`;
var res = await fetch(url);
var text = await res.text()
assert.equal(text, "Cloud Test"); // text = "" or undefined

And on the server, that endpoint does the following:

// Is the peer actually connecting??
await td.ipfs.swarm.connect(req.query.peer)
var peers = await td.ipfs.swarm.peers();
console.log(peers.map(p => p.peer._idB58String).filter(a => a === req.query.peer.split("/")[3])); 

// If the peer is connected, can it connect to the DB?
var testDB = await td.orbitdb.open(req.query.addr);
console.log(testDB.type);

// And can it fetch the title?
await testDB.load();
res.end(testDB.get("title")); // returns undefined

Pubsub is turned on on all nodes, are are hop / circuit / relay, etc.
relay: { enabled: true, hop: { enabled: true, active: true } }

What's curious is that console.log(testDB.type) returns the right type of db, keyvalue in this case, without me telling the server anything about the database.

@aphelionz
Copy link
Member Author

aphelionz commented Nov 15, 2018

Cross posted here: ipfs/js-ipfs#1714

@m00nwtchr
Copy link
Member

m00nwtchr commented Nov 29, 2018

The server knows the type of db because it's stored in the db manifest iirc

@aphelionz
Copy link
Member Author

aphelionz commented Mar 8, 2019

This should be solved now via the techniques described in #579

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants