Replies: 1 comment 4 replies
-
| 
         looks like JS?  | 
  
Beta Was this translation helpful? Give feedback.
                  
                    4 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
HI,
I am trying to solve this communication between 2 nodes but it fails at the stream format or something else.
here is the error messages and code
C:\APPS3>node start-nodes-Test1.js
Node 1 started with Peer ID: 12D3KooWSpGLzdws6AfmBfAfyx9qk5o56XJUZ6w2Rq6kGMM7HNop
Node 2 started with Peer ID: 12D3KooWC3ZgGRDhsYcHZcq5NvYxpJ2PGuYxrHFQBRKJGKdpmFWW
Node 1 Listening Addresses: [
'/ip4/127.0.0.1/tcp/3001/p2p/12D3KooWSpGLzdws6AfmBfAfyx9qk5o56XJUZ6w2Rq6kGMM7HNop'
]
Node 2 Listening Addresses: [
'/ip4/127.0.0.1/tcp/3002/p2p/12D3KooWC3ZgGRDhsYcHZcq5NvYxpJ2PGuYxrHFQBRKJGKdpmFWW'
]
Both nodes have registered the /chat/1.0.0 protocol.
Node 2 discovered peer: 12D3KooWSpGLzdws6AfmBfAfyx9qk5o56XJUZ6w2Rq6kGMM7HNop
Node 1 discovered peer: 12D3KooWC3ZgGRDhsYcHZcq5NvYxpJ2PGuYxrHFQBRKJGKdpmFWW
Attempting to dial protocol /chat/1.0.0...
Node 1 connected to peer: 12D3KooWC3ZgGRDhsYcHZcq5NvYxpJ2PGuYxrHFQBRKJGKdpmFWW
Node 2 connected to peer: 12D3KooWSpGLzdws6AfmBfAfyx9qk5o56XJUZ6w2Rq6kGMM7HNop
Node 2 received a message
Node 2 received an invalid stream object: undefined
Dial result: MplexStream {}
Stream object: MplexStream {}
Stream methods: {
write: 'undefined',
read: 'undefined',
sink: 'undefined',
source: 'undefined'
}
Invalid stream object: MplexStream {}
*** the code
import { createNode } from './create-node.js'
import { pipe } from 'it-pipe'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
async function main() {
try {
// Create two nodes
const node1 = await createNode(3001)
const node2 = await createNode(3002)
} catch (error) {
console.error('Error starting nodes:', error)
}
}
main()
*** the create-node.js
import { createLibp2p } from 'libp2p'
import { tcp } from '@libp2p/tcp'
import { mplex } from '@libp2p/mplex'
import { noise } from '@chainsafe/libp2p-noise'
import { mdns } from '@libp2p/mdns'
export async function createNode(port) {
const node = await createLibp2p({
addresses: {
listen: [
/ip4/127.0.0.1/tcp/${port}]},
transports: [tcp()],
streamMuxers: [mplex()],
connectionEncrypters: [noise()], // Renamed from connectionEncryption
peerDiscovery: [mdns()] // Enable peer discovery
})
return node
}
*** libs
C:\APPS3>npm list
[email protected] C:\APPS3
+-- @chainsafe/[email protected]
+-- @libp2p/[email protected]
+-- @libp2p/[email protected]
+-- @libp2p/[email protected]
+-- @libp2p/[email protected]
+-- @libp2p/[email protected]
+-- @libp2p/[email protected]
+-- @libp2p/[email protected]
+-- @libp2p/[email protected]
+-- @libp2p/[email protected]
+-- @libp2p/[email protected]
+-- @multiformats/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]
Beta Was this translation helpful? Give feedback.
All reactions