Skip to content

Commit

Permalink
fix(libp2p): update peer store with supported protocols after unhandle (
Browse files Browse the repository at this point in the history
#2013)

When unhandling a protocol, update the peer store entry for the
current peer with the correct set of protocols.
  • Loading branch information
achingbrain committed Sep 1, 2023
1 parent 13f5b48 commit 63041af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/libp2p/src/registrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class DefaultRegistrar implements Registrar {

// Update self protocols in the peer store
await this.components.peerStore.patch(this.components.peerId, {
protocols: protocolList
protocols: this.getProtocols()
})
}

Expand Down
4 changes: 4 additions & 0 deletions packages/libp2p/test/registrar/registrar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ describe('registrar', () => {
await libp2p.unhandle(['/echo/1.0.0'])
expect(registrar.getProtocols()).to.not.have.any.keys(['/echo/1.0.0'])
expect(registrar.getHandler('/echo/1.0.1')).to.have.property('handler', echoHandler)

await expect(libp2p.peerStore.get(libp2p.peerId)).to.eventually.have.deep.property('protocols', [
'/echo/1.0.1'
])
})
})
})

0 comments on commit 63041af

Please sign in to comment.