• Preparing search index...
  • The search index is not available
@libp2p/multistream-select - v3.1.9
  • @libp2p/multistream-select - v3.1.9
  • select

Function select

  • select(stream: Duplex<AsyncGenerator<Uint8Array, any, unknown>, Source<Uint8Array>, unknown>, protocols: string | string[], options: ByteArrayInit): Promise<ProtocolStream<Uint8Array>>
  • Negotiate a protocol to use from a list of protocols.

    Returns

    A stream for the selected protocol and the protocol that was selected from the list of protocols provided to select.

    Example

    import { pipe } from 'it-pipe'
    import * as mss from '@libp2p/multistream-select'
    import { Mplex } from '@libp2p/mplex'

    const muxer = new Mplex()
    const muxedStream = muxer.newStream()

    // mss.select(protocol(s))
    // Select from one of the passed protocols (in priority order)
    // Returns selected stream and protocol
    const { stream: dhtStream, protocol } = await mss.select(muxedStream, [
    // This might just be different versions of DHT, but could be different impls
    '/ipfs-dht/2.0.0', // Most of the time this will probably just be one item.
    '/ipfs-dht/1.0.0'
    ])

    // Typically this stream will be passed back to the caller of libp2p.dialProtocol
    //
    // ...it might then do something like this:
    // try {
    // await pipe(
    // [uint8ArrayFromString('Some DHT data')]
    // dhtStream,
    // async source => {
    // for await (const chunk of source)
    // // DHT response data
    // }
    // )
    // } catch (err) {
    // // Error in stream
    // }

    Parameters

    • stream: Duplex<AsyncGenerator<Uint8Array, any, unknown>, Source<Uint8Array>, unknown>

      A duplex iterable stream to dial on

    • protocols: string | string[]

      A list of protocols (or single protocol) to negotiate with. Protocols are attempted in order until a match is made.

    • options: ByteArrayInit

      An options object containing an AbortSignal and an optional boolean writeBytes - if this is true, Uint8Arrays will be written into duplex, otherwise Uint8ArrayLists will

    Returns Promise<ProtocolStream<Uint8Array>>

    • Defined in select.ts:59
  • select(stream: Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList, any, unknown>, Source<Uint8Array | Uint8ArrayList>, unknown>, protocols: string | string[], options?: ByteListInit): Promise<ProtocolStream<Uint8ArrayList, Uint8ArrayList | Uint8Array>>
  • Parameters

    • stream: Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList, any, unknown>, Source<Uint8Array | Uint8ArrayList>, unknown>
    • protocols: string | string[]
    • Optional options: ByteListInit

    Returns Promise<ProtocolStream<Uint8ArrayList, Uint8ArrayList | Uint8Array>>

    • Defined in select.ts:60

Settings

Member Visibility

Theme

Modules

  • @libp2p/multistream-select - v3.1.9
    • ByteArrayInit
    • ByteListInit
    • MultistreamSelectInit
    • ProtocolStream
    • PROTOCOL_ID
    • handle
    • lazySelect
    • select