ipfs-shipyard / js-libp2p-react-native

A demo app running js-libp2p in a React Native app
7 stars 3 forks source link

react-native-tcp-socket dial problems #2

Open achingbrain opened 5 months ago

achingbrain commented 5 months ago

libp2p:connection-manager:dial-queue:error dial failed to /ip4/195.242.89.232/tcp/10265/p2p/QmSfuJdgrFzuCCXL4rBfgMpKbQcdR9Q5g3mXiDuKiPKQy3 +0ms [Error: Exception in HostFunction: Malformed calls from JS: field sizes are different.

Debug data:

[
  [34,34,36,66,66,66,66,66,66,34],
  [0,1,1,11,11,11,11,11,0,0],
  [
    [6643,2000,1705490345996,false],
    [6643],
     ["{\"type\":\"log\",\"level\":\"debug\",\"mode\":\"BRIDGE\",\"data\": [\"libp2p:tcp dialing /ip4/195.242.89.232/tcp/10265/p2p/QmSfuJdgrFzuCCXL4rBfgMpKbQcdR9Q5g3mXiDuKiPKQy3 +239ms\"]}",1],
     ["data"],
     ["error"],
     ["close"],
     ["connect"],
     ["written"],
     [6650,100,1705490346236,false]
  ],
  1217
]

From: https://stackoverflow.com/questions/55084493/malformed-calls-from-js-field-sizes-are-different

Step 1: Add the following code snippet anywhere in your code:

if (global.__fbBatchedBridge) {
  const origMessageQueue = global.__fbBatchedBridge;
  const modules = origMessageQueue._remoteModuleTable;
  const methods = origMessageQueue._remoteMethodTable;
  global.findModuleByModuleAndMethodIds = (moduleId, methodId) => {
    console.log(`The problematic line code is in: ${modules[moduleId]}.${methods[moduleId][methodId]}`)
  }
}

Step 2: All you have to do now is set a breakpoint anywhere in your app, and try the pairs of module/method id's as parameters of the global.findModuleByModuleAndMethodIds function like so:

global.findModuleByModuleAndMethodIds(74, 19);
global.findModuleByModuleAndMethodIds(24, 1);

Step 3: Investigate each of those calls, and look for wrong/weird parameters, you pass to those native functions.

Output

> findModuleByModuleAndMethodIds(34, 0)
The problematic line code is in: Timing.createTimer
> findModuleByModuleAndMethodIds(34, 1)
The problematic line code is in: Timing.deleteTimer
> findModuleByModuleAndMethodIds(36, 1)
The problematic line code is in: WebSocketModule.send
> findModuleByModuleAndMethodIds(66, 11)
The problematic line code is in: TcpSockets.addListener
> findModuleByModuleAndMethodIds(66, 0)
The problematic line code is in: TcpSockets.connect

Given that the bridge data contains:

     ["data"],
     ["error"],
     ["close"],
     ["connect"],
     ["written"],

... and these are event listeners, and that we're trying to dial a TCP multiaddr, TcpSockets.addListener is probably where the error is since there should be a callback function as a second arg.

sleep9 commented 4 months ago

I am getting the same results when trying to dial via a tcp transport. Could it be the filtering?

ibp2p:connection-manager:dial-queue:trace addresses for ${node-id} **after filtering** +0ms ["/ip4/${server-ip}/tcp/59835/p2p/${node-id}"] DEBUG libp2p:tcp dialing /ip4/${server-ip}/tcp/59835/p2p/${node-id} +0ms