libp2p / js-libp2p-relay-server

An out of the box libp2p relay server implementing v1 of circuit relay protocol
MIT License
12 stars 4 forks source link

ProtocolError: missing required 'publicKey' #9

Closed on-meetsys closed 1 year ago

on-meetsys commented 1 year ago

I need a relay server for my project, to allow p2p clients to discover themselves if they are behind NAT or firewalls (my project works perfectly with mdns() on a local network). I have therefore installed a js-libp2p-relay-server on a server (8000 and 15003 ports opened), and I start libp2p nodes on clients with the setup described on js-libp2p-pubsub-peer-discovery page. The nodes run the most recent libp2p : "^0.42.1-9a6022b7" I bootstrap the nodes with the multiaddresses given during the js-libp2p-relay-server start.

const bootstraps = [
  '/ip4/xx.xx.xx.xx/tcp/15003/ws/p2p/QmfUs6rvbPuJMmrcyD3TrpXjmJJVLd8hkphASa4KHt1dvz',
  '/ip4/xx.xx.xx.xx/tcp/8000/p2p/QmfUs6rvbPuJMmrcyD3TrpXjmJJVLd8hkphASa4KHt1dvz',
];
myPeerId = await createEd25519PeerId(); // createRSAPeerId();
const p2pOptions: Libp2pOptions = {
    peerId: myPeerId,
    addresses: {
      listen: [
        '/ip4/0.0.0.0/tcp/0',
        '/ip4/0.0.0.0/tcp/64001/ws',
      ],
    },
    transports: [
      tcp(),
      webSockets(),
    ],
    peerDiscovery: [
      mdns(),
      pubsubPeerDiscovery(),
      bootstrap({
        list: bootstraps, 
      })
    ],
    streamMuxers: [mplex()],
    connectionEncryption: [noise()],
    pubsub: gossipsub({
      allowPublishToZeroPeers: true,
    }),
    relay: {
      enabled: true,
      hop: {
        enabled: true,
        active: true,
      },
    },

Then, I have the following error on the relay-server :

libp2p:gossipsub rpc from QmdL7fmd4xssmxsoA6cgDbQpdSMes61Vzk4bMS1YkdhuUP +10s
  libp2p:discovery:pubsub message reçu {
  topicIDs: [ '_peer-discovery._p2p._pubsub' ],
  from: 'QmdL7fmd4xssmxsoA6cgDbQpdSMes61Vzk4bMS1YkdhuUP',
  data: <Buffer 0a ab 02 08 00 12 a6 02 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 00 be 06 76 a1 48 a2 bc 18 56 ... 444 more bytes>,
  seqno: <Buffer 18 6e f4 d6 4e d1 51 f8>,
  signature: <Buffer 54 7b 7c f7 e9 0a 39 6b 5c 68 1c 18 db 5a f9 0d 8d b0 1b 62 bc 8e aa a0 65 da 4b b3 4c 40 60 52 9c 9d be 31 bb e0 6e f8 7a 45 03 06 73 8f 14 4a c0 da ... 206 more bytes>,
  key: <Buffer 08 00 12 a6 02 30 82 01 22 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 82 01 0f 00 30 82 01 0a 02 82 01 01 00 be 06 76 a1 48 a2 bc 18 56 6d 9d 60 ... 249 more bytes>,
  receivedFrom: 'QmdL7fmd4xssmxsoA6cgDbQpdSMes61Vzk4bMS1YkdhuUP'
} +10s
  libp2p:discovery:pubsub:error ProtocolError: missing required 'publicKey'
  libp2p:discovery:pubsub:error     at Object.CustomError [as ProtocolError] (/home/meetsys/I2KNV3-nodes/js-libp2p-relay-server/node_modules/protobufjs/src/util/minimal.js:266:20)
  libp2p:discovery:pubsub:error     at Function.decode (/home/meetsys/I2KNV3-nodes/js-libp2p-relay-server/node_modules/libp2p-pubsub-peer-discovery/src/peer.js:106:25)
  libp2p:discovery:pubsub:error     at PubsubPeerDiscovery._onMessage (/home/meetsys/I2KNV3-nodes/js-libp2p-relay-server/node_modules/libp2p-pubsub-peer-discovery/src/index.js:123:28)
  libp2p:discovery:pubsub:error     at Gossipsub.<anonymous> (/home/meetsys/I2KNV3-nodes/js-libp2p-relay-server/node_modules/libp2p-pubsub-peer-discovery/src/index.js:69:57)
  libp2p:discovery:pubsub:error     at Gossipsub.emit (node:events:527:28)
  libp2p:discovery:pubsub:error     at /home/meetsys/I2KNV3-nodes/js-libp2p-relay-server/node_modules/libp2p-interfaces/src/pubsub/index.js:492:14
  libp2p:discovery:pubsub:error     at Array.forEach (<anonymous>)
  libp2p:discovery:pubsub:error     at Gossipsub._emitMessage (/home/meetsys/I2KNV3-nodes/js-libp2p-relay-server/node_modules/libp2p-interfaces/src/pubsub/index.js:490:22)
  libp2p:discovery:pubsub:error     at Gossipsub._processRpcMessage (/home/meetsys/I2KNV3-nodes/js-libp2p-relay-server/node_modules/libp2p-interfaces/src/pubsub/index.js:479:10)
  libp2p:discovery:pubsub:error     at processTicksAndRejections (node:internal/process/task_queues:96:5) +10s

this error only occurs when there is the webSockets() transports. If not, there is no error, but the relay-servers sees nobody (no node discovery...). If I force the client to connect to the relay-server, with :


  libp2pnode.addEventListener('peer:discovery', (evt) => {
    const { detail: peer } = evt;
    log('libp2p.onPeerDiscovery', peer.id.toString());

    // peer.multiaddrs.forEach((multiaddr) => libp2pnode.dial(multiaddr));
    try {
      libp2pnode.dial(peer.id);
    } catch (error) {
      log('libp2p.onPeerDiscovery error', error);
    }
  });

on the client side, then the relay-server seems to be unreachable :

  i2kn:api:libp2p libp2p.onPeerDiscovery QmfUs6rvbPuJMmrcyD3TrpXjmJJVLd8hkphASa4KHt1dvz +2ms
(node:58281) UnhandledPromiseRejectionWarning: Error: The dial request has no valid addresses
    at DefaultDialer.dial (file:///Users/admin/Code/meetsys/i2Kn_V3/node_modules/libp2p/dist/src/connection-manager/dialer/index.js:101:27)
    at async DefaultConnectionManager.openConnection (file:///Users/admin/Code/meetsys/i2Kn_V3/node_modules/libp2p/dist/src/connection-manager/index.js:311:32)
    at async Libp2pNode.dial (file:///Users/admin/Code/meetsys/i2Kn_V3/node_modules/libp2p/dist/src/libp2p.js:257:16)
(Use `Electron --trace-warnings ...` to show where the warning was created)
(node:58281) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:58281) UnhandledPromiseRejectionWarning: Error: The dial request has no valid addresses
    at DefaultDialer.dial (file:///Users/admin/Code/meetsys/i2Kn_V3/node_modules/libp2p/dist/src/connection-manager/dialer/index.js:101:27)
    at async DefaultConnectionManager.openConnection (file:///Users/admin/Code/meetsys/i2Kn_V3/node_modules/libp2p/dist/src/connection-manager/index.js:311:32)
    at async Libp2pNode.dial (file:///Users/admin/Code/meetsys/i2Kn_V3/node_modules/libp2p/dist/src/libp2p.js:257:16)
(node:58281) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

May be this is due to the fact that this js-libp2p-relay-server is 3 years old and uses an older libp2p lib "^0.32.3" ?

But I've not found any other project to build a relay for the pubsubPeerDiscovery() discovery process. Should I fork js-libp2p-relay-server to upgrade libs ? Or do I use a bad setup ? Or is it a bug ?

Thanks

achingbrain commented 1 year ago

This module is not being actively developed any more and is very out of date.

Looking at the error, it's failing to decode the protobuf as it's being sent a message that's missing the publicKey field. In v4 of libp2p-pubsub-peer-discovery this was marked as required though also proto3 which is weird because required is not in the proto3 spec. In later versions it's a singular field so this error would not occur.

I would start by upgrading all of the deps here to the latest versions, though our maintenance time is limited so you may be better of forking for now.

achingbrain commented 1 year ago

I'm going to close this issue because this repo is not maintained any more.