mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 05:51:37 +00:00
refactor: async identify and identify push (#473)
* chore: add missing dep * feat: import from identify push branch https://github.com/libp2p/js-libp2p-identify/tree/feat/identify-push * feat: add the connection to stream handlers * refactor: identify to async/await * chore: fix lint * test: add identify tests * refactor: add identify to the dialer flow * feat: connect identify to the registrar * fix: resolve review feedback * fix: perform identify push when our protocols change
This commit is contained in:
@ -182,10 +182,14 @@ class Upgrader {
|
||||
// Run anytime a remote stream is created
|
||||
onStream: async muxedStream => {
|
||||
const mss = new Multistream.Listener(muxedStream)
|
||||
const { stream, protocol } = await mss.handle(Array.from(this.protocols.keys()))
|
||||
log('%s: incoming stream opened on %s', direction, protocol)
|
||||
connection.addStream(stream, protocol)
|
||||
this._onStream({ stream, protocol })
|
||||
try {
|
||||
const { stream, protocol } = await mss.handle(Array.from(this.protocols.keys()))
|
||||
log('%s: incoming stream opened on %s', direction, protocol)
|
||||
connection.addStream(stream, protocol)
|
||||
this._onStream({ connection, stream, protocol })
|
||||
} catch (err) {
|
||||
log.error(err)
|
||||
}
|
||||
},
|
||||
// Run anytime a stream closes
|
||||
onStreamEnd: muxedStream => {
|
||||
@ -246,12 +250,13 @@ class Upgrader {
|
||||
* Routes incoming streams to the correct handler
|
||||
* @private
|
||||
* @param {object} options
|
||||
* @param {Connection} options.connection The connection the stream belongs to
|
||||
* @param {Stream} options.stream
|
||||
* @param {string} protocol
|
||||
* @param {string} options.protocol
|
||||
*/
|
||||
_onStream ({ stream, protocol }) {
|
||||
_onStream ({ connection, stream, protocol }) {
|
||||
const handler = this.protocols.get(protocol)
|
||||
handler({ stream, protocol })
|
||||
handler({ connection, stream, protocol })
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user