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

Pubsub not connecting to node on same machine, even using ws-star #2009

Closed
reasv opened this issue Apr 28, 2019 · 2 comments
Closed

Pubsub not connecting to node on same machine, even using ws-star #2009

reasv opened this issue Apr 28, 2019 · 2 comments

Comments

@reasv
Copy link
Contributor

reasv commented Apr 28, 2019

  • Version: 0.35.0
  • Platform: Windows 10
  • Subsystem: PubSub

Type: Bug

Severity: High

Description:

I cannot get PubSub to work with js-ipfs, even with recommended settings.

Whether they run in the browser in different tabs, or through node.js inside my ava tests, the IPFS nodes I spawn will simply not send messages to each other, even when they're subscribed to the same topic, running on the same machine, and connected to the ws-star node.
Nodes will only receive their own messages.

This might not be related, but I've also noticed that IPNS names published by one node will not be resolved by another, even on the same machine.
Only if I spawn a node using the same repo as the node that created the IPNS name, does the name resolve.

Publishing files however appears to work perfectly, in browser or outside.

Steps to reproduce the error:

I originally found this issue in the browser, but here is some simplified code from my tests (using ava) which reproduces the problem:
ipfs-utils.js:

import ipfsNode from 'ipfs'
const Buffer = require('buffer').Buffer
var ipfs = null

export async function init(repo = 'ipfs-repo') {
  ipfs = new ipfsNode(
    { repo: repo,
      EXPERIMENTAL: { pubsub: true, ipnsPubsub: true },
      config: {
        Addresses: {
          Swarm: [
            '/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star'
          ]
        }
      }
    })
  return new Promise(function(resolve, reject) {
    ipfs.on('ready', () => {
      resolve(ipfs)
    })
  })
}

Test:

import { mount } from '@vue/test-utils'
import test from 'ava'
import {init, makeBuffer} from '../../util/ipfs-utils.js'

test.serial('Pubsub', async(t) =>{
  const ipfs = await init('repo/'+Date.now())
  const ipfs_1 = await init('repo/1'+Date.now())
  const topic = 'Topic'+Date.now()

  await ipfs.pubsub.subscribe(topic, (msg) => console.log(msg))
  console.log(`IPFS_0: subscribed to ${topic}`)
  await ipfs_1.pubsub.subscribe(topic, (msg) => console.log(msg))
  console.log(`IPFS_1: subscribed to ${topic}`)
  await ipfs.pubsub.publish(topic, makeBuffer({time: Date.now()}))
  var peers_0 = await ipfs.pubsub.peers(topic)
  var peers_1 = await ipfs_1.pubsub.peers(topic)
  console.log(peers_0, peers_1)
  t.is(peers_0.length > 0, true, "Peers are connected to 0")
  t.is(peers_1.length > 0, true, "Peers are connected to 1")
  t.pass()
})

Test fails because peers_0 is an empty list.
The first node receives its own message. but the second doesn't receive it.

@reasv
Copy link
Contributor Author

reasv commented Apr 28, 2019

As for the IPNS issue, I've also created a test to replicate that:

test.serial('IPNS', async(t) => {
  const ipfs = await init('repo/'+Date.now())
  const ipfs_1 = await init('repo/1'+Date.now())

  const cid = "/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG"
  const record = await ipfs.name.publish(cid)

  const res_0 = await ipfs.name.resolve(record.name)
  const res_1 = await ipfs_1.name.resolve(record.name)

  t.is(res_0.path, cid, "Name resolves on same node")
  t.is(res_1.path, cid, "Name resolves on other node")
  t.pass()
})

This fails because the second resolve raises an exception:

Rejected promise returned by test. Reason:

  Error {
    code: 'ERR_NO_RECORD_FOUND',
    message: 'record requested was not found for QmXyTFHzdDDaLZPshCpWsLVw1PpVTvVY9RRKyWg12pnEex (/ipns/ �&�9�f\\H╚4�H��$/���_���L���) in the network',
  }

@alanshaw
Copy link
Member

alanshaw commented May 3, 2019

To receive messages over pubsub your nodes either need to be connected directly to each other or connected to another node that is also subscribed to the topic.

Please either wait for the two nodes to discover one another over the rendezvous (use swarm.peers to check) or connect them directly with swarm.connect and then send your pubsub message.

If you're still having issues then please comment here again and i'll re-open.

Note - There's a pubsub interop issue that is currently being fixed, this might also be a contributing factor.

@alanshaw alanshaw closed this as completed May 3, 2019
@momack2 momack2 added this to Done in ipfs/js-ipfs May 10, 2019
@momack2 momack2 added this to Done in ipfs/js-waffle May 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

2 participants