@@ -2,8 +2,8 @@ import { CodeError, ERR_INVALID_MESSAGE, ERR_INVALID_PARAMETERS, ERR_TIMEOUT, se
2
2
import { pbStream } from 'it-protobuf-stream'
3
3
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
4
4
import { toString as uint8arrayToString } from 'uint8arrays/to-string'
5
- import { object , number } from 'yup'
6
- import { MAX_INBOUND_STREAMS , MAX_OUTBOUND_STREAMS , PROTOCOL_NAME , PROTOCOL_VERSION , TIMEOUT } from './constants.js'
5
+ import { object , number , string } from 'yup'
6
+ import { MAX_INBOUND_STREAMS , MAX_OUTBOUND_STREAMS , PROTOCOL_NAME , PROTOCOL_PREFIX , PROTOCOL_VERSION , TIMEOUT } from './constants.js'
7
7
import { FetchRequest , FetchResponse } from './pb/proto.js'
8
8
import type { Fetch as FetchInterface , FetchComponents , FetchInit , LookupFunction } from './index.js'
9
9
import type { AbortOptions , Logger , Stream , PeerId , Startable } from '@libp2p/interface'
@@ -19,8 +19,10 @@ import type { IncomingStreamData } from '@libp2p/interface-internal'
19
19
const configValidator = object ( {
20
20
timeout : number ( ) . integer ( ) . default ( TIMEOUT ) ,
21
21
maxInboundStreams : number ( ) . integer ( ) . min ( 0 ) . default ( MAX_INBOUND_STREAMS ) ,
22
- maxOutboundStreams : number ( ) . integer ( ) . min ( 0 ) . default ( MAX_OUTBOUND_STREAMS )
22
+ maxOutboundStreams : number ( ) . integer ( ) . min ( 0 ) . default ( MAX_OUTBOUND_STREAMS ) ,
23
+ protocolPrefix : string ( ) . default ( PROTOCOL_PREFIX )
23
24
} )
25
+
24
26
export class Fetch implements Startable , FetchInterface {
25
27
public readonly protocol : string
26
28
private readonly components : FetchComponents
@@ -40,7 +42,7 @@ export class Fetch implements Startable, FetchInterface {
40
42
41
43
const config = configValidator . validateSync ( init )
42
44
43
- this . protocol = `/${ init . protocolPrefix ?? 'libp2p' } /${ PROTOCOL_NAME } /${ PROTOCOL_VERSION } `
45
+ this . protocol = `/${ config . protocolPrefix } /${ PROTOCOL_NAME } /${ PROTOCOL_VERSION } `
44
46
this . timeout = config . timeout
45
47
this . maxInboundStreams = config . maxInboundStreams
46
48
this . maxOutboundStreams = config . maxOutboundStreams
0 commit comments