Permissionless-Software-Foundation / ipfs-coord

A JS npm library for helping IPFS peers coordinate, find a common interest, and stay connected around that interest.
MIT License
13 stars 3 forks source link

encryptMsg(peer, msg) should check peer object #75

Open christroutner opened 2 years ago

christroutner commented 2 years ago

From Sam: I've been playing with the web3 infra and been running into an issue when choosing the localhost:5005 as resetServer. It works fine with the "free-bch.fullstack..." URL but im getting a timeout error when choosing my copy of the waller-service. Im monitoring the ipfs-bch-wallet-consumer locally and ipfs-bch-wallet-service via ssh.

This is the message that appears in the ipfs-bch-wallet-service live logs as I send a request:

status: Message ID e344720b-3754-46c8-9634-591d239f4a0e contains RPC request with ID e9756c5f-7f86-44fe-b1b1-b4e9115fa6ab
Error in encryption.js/encryptMsg()
Error in generateAckMsg()
Error in sendAck()
Error in handleIncomingData():  TypeError: Cannot read properties of undefined (reading 'data')
    at EncryptionAdapter.encryptMsg (/home/safeuser/ipfs-bch-wallet-service/node_modules/ipfs-coord/lib/adapters/encryption-adapter.js:65:27)
...and the timeout response from psf-wallet-service connected to ipfs-bch-wallet-consumer when running 
./bin/run  wallet-balances -n sam:
restServer: http://localhost:5005
Initializing minimal-slp-wallet routers with this interface: consumer-api
Error in router.js/getUtxos()
Error in utxos.js/initUtxoStore()
Error in create()
Error in getBalances()
Error in run():  Error: request timed out
    at AdapterRouter.getUtxos (/home/sambo/PSF/psf-bch-wallet/node_modules/minimal-slp-wallet/lib/adapters/router.js:92:47)

It looks like the error is originating from ipfs-coord, here:

https://github.com/Permissionless-Software-Foundation/ipfs-coord/blob/a44140bf22338c8d8b8c504e70197c716a39d3e7/lib/adapters/encryption-adapter.js#L59-L81

This line: https://github.com/Permissionless-Software-Foundation/ipfs-coord/blob/a44140bf22338c8d8b8c504e70197c716a39d3e7/lib/adapters/encryption-adapter.js#L65

christroutner commented 2 years ago

One thing that would make this issue better, is if the encryptMsg() function did input validation on the peer object. At the least, it should throw an error if the peer object does not have a data property.