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

List of topics unavailable at for server connection #117

Open
zenineasa opened this issue Aug 25, 2022 · 2 comments
Open

List of topics unavailable at for server connection #117

zenineasa opened this issue Aug 25, 2022 · 2 comments

Comments

@zenineasa
Copy link

When a swarm joins a topic as a server, the topic is not available at 'peerInfo.topics'. I have modified a testpoint to showcase the same.

const test = require('brittle')
const { timeout } = require('nonsynchronous')
const createTestnet = require('@hyperswarm/testnet')

const Hyperswarm = require('..')

const CONNECTION_TIMEOUT = 100
const BACKOFFS = [
  100,
  200,
  300
]

test('one server, two clients - topic multiplexing', async (t) => {
    const { bootstrap } = await createTestnet(3, t.teardown)

    const swarm1 = new Hyperswarm({ bootstrap, backoffs: BACKOFFS, jitter: 0 })
    const swarm2 = new Hyperswarm({ bootstrap, backoffs: BACKOFFS, jitter: 0 })

    let clientConnections = 0
    let peerInfoClient = null
    swarm2.on('connection', (conn, info) => {
      clientConnections++
      peerInfoClient = info
      conn.on('error', noop)
    })

    let peerInfoServer = null
    swarm1.on('connection', (conn, info) => {
      peerInfoServer = info
      conn.on('error', noop)
    })

    swarm1.on('connection', (conn) => conn.on('error', noop))

    const topic1 = Buffer.alloc(32).fill('hello world')
    const topic2 = Buffer.alloc(32).fill('hi world')

    await swarm1.join(topic1, { client: false, server: true }).flushed()
    await swarm1.join(topic2, { client: false, server: true }).flushed()
    swarm2.join(topic1, { client: true, server: false })
    swarm2.join(topic2, { client: true, server: false })

    await timeout(250) // 250 ms will be enough for all connections to trigger

    t.is(clientConnections, 1)
    t.is(peerInfoClient.topics.length, 2)
    t.is(peerInfoServer.topics.length, 2) // ERROR: This is not true!!!!

    await swarm1.destroy()
    await swarm2.destroy()
  })

function noop () {}
@MKPLKN
Copy link

MKPLKN commented Sep 22, 2023

Expected behavior.

From README.md:

peerInfo.topics
An Array of topics that this Peer is associated with -- topics will only be updated when the Peer is in client mode.

@cjmont
Copy link

cjmont commented Oct 3, 2023

It seems like you've encountered an issue where peerInfoServer.topics.length is not equal to 2 as expected in your test case. This might be due to a variety of reasons, such as a bug in the library, a race condition, or some other unexpected behavior.

Here are a few steps you might take to debug and resolve the issue:

1. Debugging:

  • Logging: Add console logs or use a debugger to trace the flow of execution and see if there's something off in the sequence of operations.
  • Check the Library: Ensure that you are using the latest version of the library and check if there are any known issues related to this in the library's repository.

2. Check Asynchronous Operations:

  • Ensure that all asynchronous operations are being awaited properly and that the state is as expected at each point.
  • Check if the peerInfoServer.topics is being updated asynchronously and if you might be checking its length before it has been updated.

3. Check the Library's API and Documentation:

  • Ensure that your usage of the library's API is correct and that there are no additional steps or configurations needed to ensure that topics are updated as expected.
  • Check if the library has any known issues or updates that might affect this behavior.

4. Isolate the Issue:

  • Try to create the simplest possible scenario that reproduces the issue. This might involve creating a new test case with minimal setup and operations.
  • If possible, try to reproduce the issue outside of the test environment to ensure that it's not related to the test setup or brittle.

5. Check the Network:

  • Ensure that there are no network issues that might be affecting the ability of the peers to communicate and update their state.
  • Check if there are any errors or issues reported by the library related to network operations.

6. Manual Verification:

  • If possible, manually verify the state of the peerInfoServer object at various points to ensure that it is being updated as expected.

7. Check for Race Conditions:

  • Ensure that there are no race conditions where the peerInfoServer.topics might be being updated in parallel or overridden by other operations.

8. Check Error Handling:

  • Ensure that there are no errors being swallowed or ignored that might be affecting the flow of execution.

9. Check the Library's Source Code:

  • If all else fails, you might check the library's source code to understand how it manages topics and peer info, and if there are any conditions or configurations that might affect this.

If you've tried all of the above and are still encountering the issue, it might be worth reaching out to the library's maintainers or community for assistance, or even filing a bug report if you believe that the issue is due to a bug in the library.

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

3 participants