Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

228
Vistas
Node.JS IPFS identify the most recent message received from a peer

I'm building a P2P messaging platform using Node.JS, IPFS (the web3 decentralized blockchain module), and ipfs-http-client.

I'm trying to identify and print only the most recent message sent to an IPFS topic by a user with a peerId as specified in the variable peerId.

The code below seems to print all the messages received in the topic.

What is the best way to identify the most recent message sent to the topic by a specified peer?

I'm trying to use seqno or date to identify the most recent message but having trouble understanding how.

Is there a better way to do this?

Thanks in advance!


const IPFS = require('ipfs')
const IpfsHttpClient = require('ipfs-http-client').create;
const uint8ArrayToString = require("uint8arrays/to-string").toString;

let ipfs
let topic=``
let peerId=``

async function nodeConnect (node_url) {

  ipfs = IpfsHttpClient(node_url)

}

...
...

async function subscribe (topic) {

  await nodeConnect('/ip4/.../tcp/5001')

  await ipfs.pubsub.subscribe(topic, msg => {

    const from = msg.from 
    const seqno = uint8ArrayToString(msg.seqno, 'base16')

    if (from === peerId) return console.log(`Ignoring message ${seqno} from self`)

    console.log(`Message ${seqno} from ${from}:`)

    try {

      console.log(JSON.stringify(uint8ArrayToString(msg.data), null, 2))

    } catch (_) {

      console.log(uint8ArrayToString(msg.data, 'base16'))

    }
  })

}

...
...

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda