mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
fix: add successful stream peer to protobook (#1341)
* fix: add successful stream peer to protobook If a protocol stream has been successfully negotiated and is to be psased to the application, the peerstore should ensure that the peer is registerd with that protocol. * fix: upgrader test fix
This commit is contained in:
parent
f439d9b589
commit
8880eefa8f
@ -376,6 +376,10 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|||||||
|
|
||||||
muxedStream.stat.protocol = protocol
|
muxedStream.stat.protocol = protocol
|
||||||
|
|
||||||
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
||||||
|
// the peerstore should ensure that the peer is registered with that protocol
|
||||||
|
this.components.getPeerStore().protoBook.add(remotePeer, [protocol]).catch(err => log.error(err))
|
||||||
|
|
||||||
connection.addStream(muxedStream)
|
connection.addStream(muxedStream)
|
||||||
this._onStream({ connection, stream: { ...muxedStream, ...stream }, protocol })
|
this._onStream({ connection, stream: { ...muxedStream, ...stream }, protocol })
|
||||||
})
|
})
|
||||||
@ -438,6 +442,10 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
|
|||||||
|
|
||||||
muxedStream.stat.protocol = protocol
|
muxedStream.stat.protocol = protocol
|
||||||
|
|
||||||
|
// If a protocol stream has been successfully negotiated and is to be passed to the application,
|
||||||
|
// the peerstore should ensure that the peer is registered with that protocol
|
||||||
|
this.components.getPeerStore().protoBook.add(remotePeer, [protocol]).catch(err => log.error(err))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...muxedStream,
|
...muxedStream,
|
||||||
...stream,
|
...stream,
|
||||||
|
@ -30,6 +30,8 @@ import { TimeoutController } from 'timeout-abort-controller'
|
|||||||
import delay from 'delay'
|
import delay from 'delay'
|
||||||
import drain from 'it-drain'
|
import drain from 'it-drain'
|
||||||
import { Uint8ArrayList } from 'uint8arraylist'
|
import { Uint8ArrayList } from 'uint8arraylist'
|
||||||
|
import { PersistentPeerStore } from '@libp2p/peer-store'
|
||||||
|
import { MemoryDatastore } from 'datastore-core'
|
||||||
|
|
||||||
const addrs = [
|
const addrs = [
|
||||||
new Multiaddr('/ip4/127.0.0.1/tcp/0'),
|
new Multiaddr('/ip4/127.0.0.1/tcp/0'),
|
||||||
@ -57,7 +59,9 @@ describe('Upgrader', () => {
|
|||||||
localComponents = new Components({
|
localComponents = new Components({
|
||||||
peerId: localPeer,
|
peerId: localPeer,
|
||||||
connectionGater: mockConnectionGater(),
|
connectionGater: mockConnectionGater(),
|
||||||
registrar: mockRegistrar()
|
registrar: mockRegistrar(),
|
||||||
|
peerStore: new PersistentPeerStore(),
|
||||||
|
datastore: new MemoryDatastore()
|
||||||
})
|
})
|
||||||
localMuxerFactory = new Mplex()
|
localMuxerFactory = new Mplex()
|
||||||
localUpgrader = new DefaultUpgrader(localComponents, {
|
localUpgrader = new DefaultUpgrader(localComponents, {
|
||||||
@ -73,7 +77,9 @@ describe('Upgrader', () => {
|
|||||||
remoteComponents = new Components({
|
remoteComponents = new Components({
|
||||||
peerId: remotePeer,
|
peerId: remotePeer,
|
||||||
connectionGater: mockConnectionGater(),
|
connectionGater: mockConnectionGater(),
|
||||||
registrar: mockRegistrar()
|
registrar: mockRegistrar(),
|
||||||
|
peerStore: new PersistentPeerStore(),
|
||||||
|
datastore: new MemoryDatastore()
|
||||||
})
|
})
|
||||||
remoteUpgrader = new DefaultUpgrader(remoteComponents, {
|
remoteUpgrader = new DefaultUpgrader(remoteComponents, {
|
||||||
connectionEncryption: [
|
connectionEncryption: [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user