Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda