Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Transfering DAG object between two computers #881

Closed
negamaxi opened this issue Jun 16, 2017 · 14 comments
Closed

Transfering DAG object between two computers #881

negamaxi opened this issue Jun 16, 2017 · 14 comments
Labels
kind/bug A bug in existing code (including security flaws) kind/support A question or request for support P2 Medium: Good to have, but can wait until someone steps up

Comments

@negamaxi
Copy link
Contributor

I have two laptops, both running js-ipfs nodes. On the first one I put javascript object with:

const obj = { a: 'b' }
const cid = await node.dag.put(obj)

Then I convert cid toBaseEncodedString(), send via messenger to my second laptop and trying to get content with:

const data = await node.dag.get(cidString)
console.log(data.value)

...but console.log never happens and no errors. Multiaddr of my first laptop appears in node.swarm.addrs() of the second one like that

[ <Multiaddr 04c0a86406060fa2 - /ip4/192.168.100.6/tcp/4002> ]

what I believe means both nodes see each other. Any advice on how to make it work? Thanks!

@daviddias
Copy link
Member

That's a strange behavior. I see you are using async/await, I assume you have wrapped the API to expose that?

Check the bitswap wantlist. node.bitswap.wantlist() to see if the cid is present.

@negamaxi
Copy link
Contributor Author

This code I run on first laptop:

const IPFS = require('ipfs')
const DAGOptions = { format: 'dag-cbor', hashAlg: 'sha2-256' }

const node = new IPFS()
node.on('ready', async () => {
  const cid = await node.dag.put({ a: 'b' }, DAGOptions)
  console.log(cid.toBaseEncodedString())
  const { value } = await node.dag.get(cid)
  console.log(value)
  let knownPeers = []
  setInterval(async () => {
    const addrs = await node.swarm.addrs()
    const newPeers = []
    addrs.forEach((addr) => {
      const id = addr.id.toB58String()
      if (!knownPeers.includes(id)) {
        newPeers.push(id)
      }
    })
    if (newPeers.length > 0) {
      console.log(newPeers)
      knownPeers = [...knownPeers, ...newPeers]
    }
  }, 1000)
})
console output

WARNING: Your platform does not have native WebRTC support, it won' use any WebRTC transport
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/ipfs/QmeQQdVjvKdo3Q3v2SincZhghnqUGckSF23r9ajxsq4LrJ
Swarm listening on /ip4/127.0.0.1/tcp/4002/ipfs/QmeQQdVjvKdo3Q3v2SincZhghnqUGckSF23r9ajxsq4LrJ
Swarm listening on /ip4/192.168.100.7/tcp/4002/ipfs/QmeQQdVjvKdo3Q3v2SincZhghnqUGckSF23r9ajxsq4LrJ
zdpuAw6c3ViCx5A7K4nukvmxh3ZtTHnyknmxCLQmGa6JDmDMn
{ a: 'b' }
[ 'QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
 'QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
 'QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
 'QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
 'QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
 'QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
 'QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
 'QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
 'QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx' ]
[ 'Qmc9bVU9yQ38C7LaeJMZ9o36tXuHVJWNY2mGZG4w8wzJBE' ]
[ 'QmeQQdVjvKdo3Q3v2SincZhghnqUGckSF23r9ajxsq4LrJ' ]


This code I run on second laptop:

const IPFS = require('ipfs')
const node = new IPFS()

node.on('ready', async () => {
  node.dag.get('zdpuAw6c3ViCx5A7K4nukvmxh3ZtTHnyknmxCLQmGa6JDmDMn', (err, result) => {
    if (err) {
      console.log(err)
    } else {
      console.log(result.value)
    }
  })
  console.log(node.bitswap.wantlist())
  setTimeout(() => {
    console.log(node.bitswap.wantlist())
  }, 1000)
  let knownPeers = []
  setInterval(async () => {
    const addrs = await node.swarm.addrs()
    const newPeers = []
    addrs.forEach((addr) => {
      const id = addr.id.toB58String()
      if (!knownPeers.includes(id)) {
        newPeers.push(id)
      }
    })
    if (newPeers.length > 0) {
      console.log('NEW PEERS =>')
      console.log(newPeers)
      knownPeers = [...knownPeers, ...newPeers]
    }
  }, 1000)
})
console output

WARNING: Your platform does not have native WebRTC support, it won' use any WebRTC transport
Swarm listening on /ip4/127.0.0.1/tcp/4003/ws/ipfs/Qmc9bVU9yQ38C7LaeJMZ9o36tXuHVJWNY2mGZG4w8wzJBE
Swarm listening on /ip4/127.0.0.1/tcp/4002/ipfs/Qmc9bVU9yQ38C7LaeJMZ9o36tXuHVJWNY2mGZG4w8wzJBE
Swarm listening on /ip4/192.168.100.6/tcp/4002/ipfs/Qmc9bVU9yQ38C7LaeJMZ9o36tXuHVJWNY2mGZG4w8wzJBE
[]
[ WantListEntry {
    _refCounter: 1,
    cid: 
     CID {
       codec: 'dag-cbor',
       version: 1,
       multihash: <Buffer 12 20 9e 9d 55 07 d3 29 07 ef 1f 11 23 0c 6c 37 bd f6 13 fd 0d fd b7 b6 c8 9b fe f9 64 81 23 fc b2 65> },
    priority: 2147483647 } ]
NEW PEERS =>
[ 'QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
  'QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z',
  'QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM',
  'QmSoLueR4xBeUbY9WZ9xGUUxunbKWcrNFTDAadQJmocnWm',
  'QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu',
  'QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
  'QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd',
  'QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3',
  'QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx' ]
NEW PEERS =>
[ 'QmeQQdVjvKdo3Q3v2SincZhghnqUGckSF23r9ajxsq4LrJ',
  'Qmc9bVU9yQ38C7LaeJMZ9o36tXuHVJWNY2mGZG4w8wzJBE' ]


Get request appears in wantlist not immediately, I asume it's okay? By the way, any ideas where those first 9 nodes came from?

@daviddias daviddias added the status/deferred Conscious decision to pause or backlog label Jul 3, 2017
@daviddias
Copy link
Member

Are you use that both of your laptops are connected? The first 9 nodes are the bootstrappers nodes.

@daviddias daviddias added the kind/support A question or request for support label Jul 7, 2017
@negamaxi
Copy link
Contributor Author

negamaxi commented Jul 7, 2017

@diasdavid Qme.. address of the first laptop's node appears in node.swarm.addrs() of the second one and vice versa. Doesn't it mean they see each other?

/ip4/127.0.0.1/tcp/4003/ws/ipfs/QmeQQdVjvKdo3Q3v2SincZhghnqUGckSF23r9ajxsq4LrJ
NEW PEERS =>
[ 'QmeQQdVjvKdo3Q3v2SincZhghnqUGckSF23r9ajxsq4LrJ',
  'Qmc9bVU9yQ38C7LaeJMZ9o36tXuHVJWNY2mGZG4w8wzJBE' ]

@daviddias daviddias added kind/bug A bug in existing code (including security flaws) P2 Medium: Good to have, but can wait until someone steps up labels Jul 26, 2017
@daviddias
Copy link
Member

@negamaxi any update on this issue? Still seeing an issue?

@negamaxi
Copy link
Contributor Author

negamaxi commented Sep 1, 2017

@diasdavid I'll check once I get a new laptop.

@daviddias
Copy link
Member

Hi @negamaxi, were you able to check this?

@negamaxi
Copy link
Contributor Author

Hi, still not. Faced another issue #1016.

@daviddias daviddias added status/ready Ready to be worked and removed status/deferred Conscious decision to pause or backlog labels Oct 17, 2017
@daviddias
Copy link
Member

@negamaxi still an issue? Would love to make sure this is fixed if there is indeed a real problem. Could you add a failing test to our bitswap batch?

@negamaxi
Copy link
Contributor Author

negamaxi commented Feb 21, 2018

@diasdavid as for now it's not an issue for me as we moved to go-ipfs + js-ipfs-api with custom DAG implementation that works as expected. Anyway just tried with js-ipfs 0.27.7:

// pc-publisher
node.on('ready', async () => {
  await node.dag.put({ a: 'b' }, dagParams)
})
// pc-receiver
node.on('ready', () => {
  setInterval(async () => {
    try {
      const value = await node.dag.get('zdpuAw6c3ViCx5A7K4nukvmxh3ZtTHnyknmxCLQmGa6JDmDMn')
      console.log(value)
    } catch (e) {
      console.error(e)
    }
  }, 1000)
})

And still no luck, although publisher id appears in receivers nodelist in about 5 seconds.

I'm not too experienced in writing tests but will be glad to take a try. Just point me which repo I should contribute to.

@negamaxi
Copy link
Contributor Author

@daviddias
Copy link
Member

@negamaxi exactly.

@negamaxi
Copy link
Contributor Author

negamaxi commented Mar 3, 2018

@diasdavid as ipfsd-ctl relies on js-ipfs-api that currently missing dag interface I wasn't able to use IPFSFactory like other tests do. Instead I use two js-ipfs instances and transfer objects between them. Anyway those tests passed. https://github.com/negamaxi/js-ipfs/commit/7b2f5863ea1e935cd4e8d523e8c535482ab3d536

@daviddias
Copy link
Member

daviddias commented Mar 3, 2018

Excellent @negamaxi. Solved then :)

@ghost ghost removed the status/ready Ready to be worked label Mar 3, 2018
MicrowaveDev pushed a commit to galtproject/js-ipfs that referenced this issue May 22, 2020
Anything that isn't a string needs to be passed with `--json`.

fixes ipfs#881

Depends on:

* [x] ipfs-inactive/interface-js-ipfs-core#470

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug A bug in existing code (including security flaws) kind/support A question or request for support P2 Medium: Good to have, but can wait until someone steps up
Projects
None yet
Development

No branches or pull requests

2 participants