Reduce blacklist cooldown?

Is there a way to reduce the cooldown time once a peer is blacklisted? It seems really long right now, and for my use case it’s worth trading higher network activity for better responsiveness to peers coming online.

The default for the denylist is currently at 5 minutes, and backs off exponentially after each failed attempt. You should be able to configure this in libp2p via the switch configuration.

const libp2p = new Libp2p({
  switch: {
    denyTTL: 5 * 1000 // start with a 5 second denial
  },
  ...
})

You can see the other available options at https://github.com/libp2p/js-libp2p/blob/master/src/switch/README.md#create-a-libp2p-switch.

We will be moving to a denylist based on multiaddrs instead of peers, so in the future this should be less aggressive.

That’s good to know, thank you! Is there a way to make it not increase exponentially? The problem I’m having is that if someone comes online after an hour of me having my app open, libp2p will refuse to dial them for a long time because it has already built up this huge delayTTL.

I’m not sure what this would take, but since I’m running js-ipfs (0.37.0) in a webpage, a partial solution could also be to clear the blacklist between page refreshes, which doesn’t seem to happen currently.

Also, what’s the best way to modify these parameters if I’m using js-ipfs? I know there’s options.libp2p, but it looks like this sort of thing can’t be modified without an entire custom libp2p bundle, which seems like overkill.

You shouldn’t need to redo the whole bundle. If you pass the object, it should merge the defaults.

const options = {
  libp2p: {
    switch: {
      denyTTL: 2 * 60 * 1e3, // 2 minute base
      ...
    }
  }
}

Unfortunately not yet, but you can clear the denylist manually for a peer. ipfs.libp2p._switch.dialer.clearDenylist(peerInfo). You have to access the switch to do so, but in the future the dialer should be accessible directly through libp2p.

1 Like

That is really helpful, thank you so much!

For anyone else trying to do this, here’s the final code snippet I’m using to clear the whole blacklist (with js-ipfs version 0.37.0):

const addrs = await ipfs.swarm.addrs();
// eslint-disable-next-line no-underscore-dangle
addrs.map(peerInfo => ipfs.libp2p._switch.dialer.clearBlacklist(peerInfo));

Sorry to revive an old thread, but it looks like this doesn’t work any more in version 0.41.2 (I’m only now upgrading from 0.38). What’s the current way to clear the deny list? (or change cooldown behavior in general?)

With the async refactor in 0.41 that behavior has been removed for now. The switch has also been removed in favor of a simpler dialer. There should be no cooldown in between dials as the dial logic has greatly improved. Once the PeerStore v2 is implemented we will revisit the backoff logic, but on a multiaddr level instead of at a peer level to help mitigate unnecessary backoff behavior.

Oh, great! Thanks for the quick reply!