My node client/server is working and I am getting pubsub discovery messages via the circut relay server.
However when I try this on ios, the circuit relay node is discovered but will not connect. I get the following output from debug.enable('libp2p:,:trace')
I think there might be something going wrong with the react-native module used for tcp.
libp2p:tcp dialing /ip4/${my_server_ip}/tcp/59835/p2p/12D3KooWDYhZLWM7XagHSf9HSZT338UN9LesS1ckQRhdnnQSSkk6 +0ms
libp2p:connection-manager:dial-queue:error dial failed to /ip4/${my_server_ip}/tcp/59835/p2p/12D3KooWDYhZLWM7XagHSf9HSZT338UN9LesS1ckQRhdnnQSSkk6 +0ms [Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.
[[66,66,66,66,66,34],[11,11,11,11,0,0],[["error"],["close"],["connect"],["written"],[553,100,1706985960568,false]],160]]
The following is the node.js server code.
`
import { createLibp2p } from 'libp2p';
import { tcp } from '@libp2p/tcp'
import { mplex } from '@libp2p/mplex'
import { yamux } from '@chainsafe/libp2p-yamux'
import { noise } from '@chainsafe/libp2p-noise'
import { circuitRelayServer} from "@libp2p/circuit-relay-v2"
import { kadDHT } from '@libp2p/kad-dht'
import { identify } from '@libp2p/identify'
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { peerIdFromKeys } from '@libp2p/peer-id';
import bip39 from 'bip39'
import {generateKeyPairFromSeed} from '@libp2p/crypto/keys'
import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery'
My node client/server is working and I am getting pubsub discovery messages via the circut relay server. However when I try this on ios, the circuit relay node is discovered but will not connect. I get the following output from debug.enable('libp2p:,:trace')
I think there might be something going wrong with the react-native module used for tcp.
libp2p:tcp dialing /ip4/${my_server_ip}/tcp/59835/p2p/12D3KooWDYhZLWM7XagHSf9HSZT338UN9LesS1ckQRhdnnQSSkk6 +0ms libp2p:connection-manager:dial-queue:error dial failed to /ip4/${my_server_ip}/tcp/59835/p2p/12D3KooWDYhZLWM7XagHSf9HSZT338UN9LesS1ckQRhdnnQSSkk6 +0ms [Error: Exception in HostFunction: Malformed calls from JS: field sizes are different. [[66,66,66,66,66,34],[11,11,11,11,0,0],[["error"],["close"],["connect"],["written"],[553,100,1706985960568,false]],160]]
The following is the node.js server code. ` import { createLibp2p } from 'libp2p'; import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { circuitRelayServer} from "@libp2p/circuit-relay-v2" import { kadDHT } from '@libp2p/kad-dht' import { identify } from '@libp2p/identify' import { gossipsub } from '@chainsafe/libp2p-gossipsub' import { peerIdFromKeys } from '@libp2p/peer-id'; import bip39 from 'bip39' import {generateKeyPairFromSeed} from '@libp2p/crypto/keys' import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery'
const generateRandomKeyPair = async (mnemonic = null) => {
}
const createRelayNode = async (peerId)=>{ return await createLibp2p({ peerId, addresses: { listen: ['/ip4/0.0.0.0/tcp/59835'], }, transports: [ tcp() ], streamMuxers: [ yamux(),mplex() ], connectionManager: { }, connectionEncryption: [ noise() ],
} const main = async () => {
} main(); ` The following is a working node circuit relay client code.
` 'use strict' import { Buffer } from 'buffer'; import { bootstrap } from '@libp2p/bootstrap' import { createLibp2p } from 'libp2p'; import { tcp } from '@libp2p/tcp' import { mplex } from '@libp2p/mplex' import { yamux } from '@chainsafe/libp2p-yamux' import { noise } from '@chainsafe/libp2p-noise' import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'; import { kadDHT } from '@libp2p/kad-dht' import { identify } from '@libp2p/identify' import { gossipsub } from '@chainsafe/libp2p-gossipsub' import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery'
const createNode = async (relay:string)=>{ return createLibp2p({ addresses: { listen: ['/ip4/0.0.0.0/tcp/0'] }, transports: [tcp(), circuitRelayTransport({ discoverRelays: 1 })], streamMuxers: [ yamux(),mplex() ], connectionManager: {
}
const main = async () => {
} main(); `
The following is the App client code. ` import './globals.js' import { StatusBar } from 'expo-status-bar' import { StyleSheet, Text, View } from 'react-native' import { useState, useEffect } from 'react' import { createLibp2p } from 'libp2p' import { bootstrap } from '@libp2p/bootstrap' import { noise } from '@chainsafe/libp2p-noise' import { yamux } from '@chainsafe/libp2p-yamux' import { mplex } from '@libp2p/mplex' import { identify } from '@libp2p/identify' import { circuitRelayTransport } from '@libp2p/circuit-relay-v2' import { tcp } from '@libp2p/tcp' import debug from 'debug' import { gossipsub } from '@chainsafe/libp2p-gossipsub' // https://github.com/ChainSafe/js-libp2p-gossipsub import { pubsubPeerDiscovery } from '@libp2p/pubsub-peer-discovery'
debug.enable('libp2p:,:trace')
const useConstructor = (callBack = () => {}) => { const [hasBeenCalled, setHasBeenCalled] = useState(false); if (hasBeenCalled) return; callBack(); setHasBeenCalled(true); }
export default function App () {
async function createNode(relay) { return createLibp2p({ transports: [ tcp(), circuitRelayTransport({ discoverRelays: 1 }), ], connectionManager: {
useConstructor(async () => {
});
} `