Skip to content

Commit

Permalink
fix: fixes related to PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
maschad committed Nov 29, 2023
1 parent b7afb67 commit b0f60e7
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 55 deletions.
3 changes: 1 addition & 2 deletions packages/libp2p/src/address-manager/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { type ObjectSchema, object, array, string, mixed } from 'yup'
import { validateMultiaddr } from '../config/helpers.js'
import type { AddressManagerInit } from '.'
import type { Multiaddr } from '@multiformats/multiaddr'

export function debounce (func: () => void, wait: number): () => void {
Expand All @@ -17,7 +16,7 @@ export function debounce (func: () => void, wait: number): () => void {
}
}

export function validateAddressManagerConfig (opts: AddressManagerInit): ObjectSchema<Record<string, unknown>> {
export function validateAddressManagerConfig (): ObjectSchema<Record<string, unknown>> {
return object({
listen: array().of(string()).test('is multiaddr', validateMultiaddr).default([]),
announce: array().of(string()).test('is multiaddr', validateMultiaddr).default([]),
Expand Down
7 changes: 3 additions & 4 deletions packages/libp2p/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import mergeOptions from 'merge-options'
import { object } from 'yup'
import { validateAddressManagerConfig } from '../address-manager/utils.js'
import { validateConnectionManagerConfig } from '../connection-manager/utils.js'
import type { AddressManagerInit } from '../address-manager'
import type { ConnectionManagerInit } from '../connection-manager/index.js'
import type { Libp2pInit } from '../index.js'
import type { ServiceMap, RecursivePartial } from '@libp2p/interface'

const DefaultConfig: Partial<Libp2pInit> = {
const defaultConfig: Partial<Libp2pInit> = {
connectionManager: {
resolvers: {
dnsaddr: dnsaddrResolver
Expand All @@ -24,13 +23,13 @@ const DefaultConfig: Partial<Libp2pInit> = {

export function validateConfig<T extends ServiceMap = Record<string, unknown>> (opts: RecursivePartial<Libp2pInit<T>>): Libp2pInit<T> {
const libp2pConfig = object({
addresses: validateAddressManagerConfig(opts?.addresses as AddressManagerInit),
addresses: validateAddressManagerConfig(),
connectionManager: validateConnectionManagerConfig(opts?.connectionManager as ConnectionManagerInit)
})

const parsedOpts = libp2pConfig.validateSync(opts)

const resultingOptions: Libp2pInit<T> = mergeOptions(DefaultConfig, parsedOpts)
const resultingOptions: Libp2pInit<T> = mergeOptions(defaultConfig, parsedOpts)

return resultingOptions
}
5 changes: 5 additions & 0 deletions packages/libp2p/src/config/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import { multiaddr } from '@multiformats/multiaddr'
import { codes } from '../errors.js'

export const validateMultiaddr = (value: Array<string | undefined> | undefined): boolean => {
if (value == null || value === undefined) {
return false
}

value?.forEach((addr) => {
try {
multiaddr(addr)
} catch (err) {
throw new CodeError(`invalid multiaddr: ${addr}`, codes.ERR_INVALID_MULTIADDR)
}
})

return true
}
6 changes: 3 additions & 3 deletions packages/libp2p/src/connection-manager/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ export const validateConnectionManagerConfig = (opts: ConnectionManagerInit): Ob
autoDialConcurrency: number().integer().min(0).default(AUTO_DIAL_CONCURRENCY),
autoDialPriority: number().integer().min(0).default(AUTO_DIAL_PRIORITY),
maxParallelDials: number().integer().min(0).default(MAX_PARALLEL_DIALS),
maxPeerAddrsToDialed: number().min(0).integer().default(MAX_PEER_ADDRS_TO_DIAL),
maxPeerAddrsToDialed: number().integer().min(0).default(MAX_PEER_ADDRS_TO_DIAL),
dialTimeout: number().integer().min(0).default(DIAL_TIMEOUT),
inboundUpgradeTimeout: number().integer().min(0).default(INBOUND_UPGRADE_TIMEOUT),
allow: array().of(string()).test('is multiaddr', validateMultiaddr).optional(),
deny: array().of(string()).test('is multiaddr', validateMultiaddr).optional(),
allow: array().of(string()).test('is multiaddr', validateMultiaddr).default([]),
deny: array().of(string()).test('is multiaddr', validateMultiaddr).default([]),
inboundConnectionThreshold: number().integer().min(0).default(INBOUND_CONNECTION_THRESHOLD),
maxIncomingPendingConnections: number().integer().min(0).default(MAX_INCOMING_PENDING_CONNECTIONS)
})
Expand Down
12 changes: 12 additions & 0 deletions packages/protocol-dcutr/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#rpc-messages
export const MAX_DCUTR_MESSAGE_SIZE = 1024 * 4
// ensure the dial has a high priority to jump to the head of the dial queue
export const DCUTR_DIAL_PRIORITY = 100

export const DEFAULT_MAX_INBOUND_STREAMS = 1

export const DEFAULT_MAX_OUTBOUND_STREAMS = 1

export const DEFAULT_TIMEOUT = 5000

export const DEFAULT_RETRIES = 3
14 changes: 5 additions & 9 deletions packages/protocol-dcutr/src/dcutr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@ import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
import delay from 'delay'
import { pbStream } from 'it-protobuf-stream'
import { number, object } from 'yup'
import { DCUTR_DIAL_PRIORITY, DEFAULT_MAX_INBOUND_STREAMS, DEFAULT_MAX_OUTBOUND_STREAMS, DEFAULT_RETRIES, DEFAULT_TIMEOUT, MAX_DCUTR_MESSAGE_SIZE } from './constants.js'
import { HolePunch } from './pb/message.js'
import { isPublicAndDialable } from './utils.js'
import { multicodec } from './index.js'
import type { DCUtRServiceComponents, DCUtRServiceInit } from './index.js'
import type { Logger, Connection, Stream, PeerStore, Startable } from '@libp2p/interface'
import type { AddressManager, ConnectionManager, Registrar, TransportManager } from '@libp2p/interface-internal'

// https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#rpc-messages
const MAX_DCUTR_MESSAGE_SIZE = 1024 * 4
// ensure the dial has a high priority to jump to the head of the dial queue
const DCUTR_DIAL_PRIORITY = 100

const configValidator = object({
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/holepunch/holepuncher.go#L27
timeout: number().integer().default(5000).min(0),
timeout: number().integer().min(0).default(DEFAULT_TIMEOUT),
// https://github.com/libp2p/go-libp2p/blob/8d2e54e1637041d5cf4fac1e531287560bd1f4ac/p2p/protocol/holepunch/holepuncher.go#L28
retries: number().integer().default(3).min(0),
maxInboundStreams: number().integer().default(1).min(0),
maxOutboundStreams: number().integer().default(1).min(0)
retries: number().integer().min(0).default(DEFAULT_RETRIES),
maxInboundStreams: number().integer().min(0).default(DEFAULT_MAX_INBOUND_STREAMS),
maxOutboundStreams: number().integer().min(0).default(DEFAULT_MAX_OUTBOUND_STREAMS)
})

export class DefaultDCUtRService implements Startable {
Expand Down
1 change: 1 addition & 0 deletions packages/protocol-fetch/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const PROTOCOL_NAME = 'fetch'
export const MAX_INBOUND_STREAMS = 1
export const MAX_OUTBOUND_STREAMS = 1
export const TIMEOUT = 10000
export const PROTOCOL_PREFIX = 'libp2p'
10 changes: 6 additions & 4 deletions packages/protocol-fetch/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CodeError, ERR_INVALID_MESSAGE, ERR_INVALID_PARAMETERS, ERR_TIMEOUT, se
import { pbStream } from 'it-protobuf-stream'
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
import { toString as uint8arrayToString } from 'uint8arrays/to-string'
import { object, number } from 'yup'
import { MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, PROTOCOL_NAME, PROTOCOL_VERSION, TIMEOUT } from './constants.js'
import { object, number, string } from 'yup'
import { MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, PROTOCOL_NAME, PROTOCOL_PREFIX, PROTOCOL_VERSION, TIMEOUT } from './constants.js'
import { FetchRequest, FetchResponse } from './pb/proto.js'
import type { Fetch as FetchInterface, FetchComponents, FetchInit, LookupFunction } from './index.js'
import type { AbortOptions, Logger, Stream, PeerId, Startable } from '@libp2p/interface'
Expand All @@ -19,8 +19,10 @@ import type { IncomingStreamData } from '@libp2p/interface-internal'
const configValidator = object({
timeout: number().integer().default(TIMEOUT),
maxInboundStreams: number().integer().min(0).default(MAX_INBOUND_STREAMS),
maxOutboundStreams: number().integer().min(0).default(MAX_OUTBOUND_STREAMS)
maxOutboundStreams: number().integer().min(0).default(MAX_OUTBOUND_STREAMS),
protocolPrefix: string().default(PROTOCOL_PREFIX)
})

export class Fetch implements Startable, FetchInterface {
public readonly protocol: string
private readonly components: FetchComponents
Expand All @@ -40,7 +42,7 @@ export class Fetch implements Startable, FetchInterface {

const config = configValidator.validateSync(init)

this.protocol = `/${init.protocolPrefix ?? 'libp2p'}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`
this.protocol = `/${config.protocolPrefix}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`
this.timeout = config.timeout
this.maxInboundStreams = config.maxInboundStreams
this.maxOutboundStreams = config.maxOutboundStreams
Expand Down
8 changes: 4 additions & 4 deletions packages/protocol-identify/src/identify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import {
MAX_OUTBOUND_STREAMS,
MAX_IDENTIFY_MESSAGE_SIZE,
TIMEOUT,
RUN_ON_CONNECTION_OPEN,
RUN_ON_CONNECTION_OPEN as DEFAULT_RUN_ON_CONNECTION_OPEN,
PROTOCOL_PREFIX,
RUN_ON_TRANSIENT_CONNECTION,
RUN_ON_TRANSIENT_CONNECTION as DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS,
MAX_PUSH_INCOMING_STREAMS,
MAX_PUSH_OUTGOING_STREAMS,
MAX_OBSERVED_ADDRESSES
Expand All @@ -41,8 +41,8 @@ const configValidator = object({
maxPushOutgoingStreams: number().integer().min(0).default(MAX_PUSH_OUTGOING_STREAMS),
maxOutboundStreams: number().integer().min(0).default(MAX_OUTBOUND_STREAMS),
maxObservedAddresses: number().integer().min(0).default(MAX_OBSERVED_ADDRESSES),
runOnConnectionOpen: boolean().default(RUN_ON_CONNECTION_OPEN),
runOnTransientConnection: boolean().default(RUN_ON_TRANSIENT_CONNECTION)
runOnConnectionOpen: boolean().default(DEFAULT_RUN_ON_CONNECTION_OPEN),
runOnTransientConnection: boolean().default(DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS)
})

export class Identify implements Startable, IdentifyInterface {
Expand Down
1 change: 1 addition & 0 deletions packages/protocol-ping/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export const TIMEOUT = 10000
// opening stream A even though the dialing peer is opening stream B and closing stream A).
export const MAX_INBOUND_STREAMS = 2
export const MAX_OUTBOUND_STREAMS = 1
export const DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS = true

export const ERR_WRONG_PING_ACK = 'ERR_WRONG_PING_ACK'
4 changes: 2 additions & 2 deletions packages/protocol-ping/src/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import first from 'it-first'
import { pipe } from 'it-pipe'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { boolean, number, object, string } from 'yup'
import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, ERR_WRONG_PING_ACK } from './constants.js'
import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, ERR_WRONG_PING_ACK, DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS } from './constants.js'
import type { PingServiceComponents, PingServiceInit, PingService as PingServiceInterface } from './index.js'
import type { AbortOptions, Logger, Stream, PeerId, Startable } from '@libp2p/interface'
import type { IncomingStreamData } from '@libp2p/interface-internal'
Expand All @@ -15,7 +15,7 @@ const configValidator = object({
timeout: number().integer().min(0).default(TIMEOUT),
maxInboundStreams: number().integer().min(0).default(MAX_INBOUND_STREAMS),
maxOutboundStreams: number().integer().min(0).default(MAX_OUTBOUND_STREAMS),
runOnTransientConnection: boolean().default(true)
runOnTransientConnection: boolean().default(DEFAULT_RUN_ON_TRANSIENT_CONNECTIONS)
})

export class PingService implements Startable, PingServiceInterface {
Expand Down
8 changes: 8 additions & 0 deletions packages/transport-circuit-relay-v2/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export const RELAY_SOURCE_TAG = 'circuit-relay-source'

export const RELAY_TAG = 'circuit-relay-relay'

export const DEFAULT_DEFAULT_APPLY_LIMIT = true

export const DEFAULT_RESERVATION_COMPLETION_TIMEOUT = 10000

export const DEFAULT_MAX_RESERVATION_QUEUE_LENGTH = 100

export const DEFAULT_DISCOVER_RELAYS = 0

// circuit v2 connection limits
// https://github.com/libp2p/go-libp2p/blob/master/p2p/protocol/circuitv2/relay/resources.go#L61-L66

Expand Down
16 changes: 3 additions & 13 deletions packages/transport-circuit-relay-v2/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import { RecordEnvelope } from '@libp2p/peer-record'
import { type Multiaddr, multiaddr } from '@multiformats/multiaddr'
import { pbStream, type ProtobufStream } from 'it-protobuf-stream'
import pDefer from 'p-defer'
import { object, number, boolean } from 'yup'
import { object, number } from 'yup'
import {
CIRCUIT_PROTO_CODE,
DEFAULT_DURATION_LIMIT,
DEFAULT_HOP_TIMEOUT,
DEFAULT_MAX_INBOUND_STREAMS,
DEFAULT_MAX_OUTBOUND_STREAMS,
DEFAULT_MAX_RESERVATION_CLEAR_INTERVAL,
DEFAULT_MAX_RESERVATION_STORE_SIZE,
DEFAULT_MAX_RESERVATION_TTL,
MAX_CONNECTIONS,
RELAY_SOURCE_TAG,
RELAY_V2_HOP_CODEC,
Expand All @@ -22,7 +18,7 @@ import {
import { HopMessage, type Reservation, Status, StopMessage } from '../pb/index.js'
import { createLimitedRelay } from '../utils.js'
import { AdvertService, type AdvertServiceComponents, type AdvertServiceInit } from './advert-service.js'
import { ReservationStore, type ReservationStoreInit } from './reservation-store.js'
import { ReservationStore, reservationStoreConfigValidator, type ReservationStoreInit } from './reservation-store.js'
import { ReservationVoucherRecord } from './reservation-voucher.js'
import type { CircuitRelayService, RelayReservation } from '../index.js'
import type { ComponentLogger, Logger, Connection, Stream, ConnectionGater, PeerId, PeerStore, Startable } from '@libp2p/interface'
Expand Down Expand Up @@ -95,13 +91,7 @@ export interface RelayServerEvents {

const configValidator = object({
hopTimeout: number().integer().min(0).default(DEFAULT_HOP_TIMEOUT),
reservations: object({
maxReservations: number().integer().min(0).default(DEFAULT_MAX_RESERVATION_STORE_SIZE),
reservationClearInterval: number().integer().min(0).default(DEFAULT_MAX_RESERVATION_CLEAR_INTERVAL),
applyDefaultLimit: boolean().default(false),
reservationTtl: number().integer().min(0).default(DEFAULT_MAX_RESERVATION_TTL),
defaultDurationLimit: number().integer().min(0).default(DEFAULT_DURATION_LIMIT)
}),
reservations: reservationStoreConfigValidator,
maxInboundHopStreams: number().integer().min(0).default(DEFAULT_MAX_INBOUND_STREAMS),
maxOutboundHopStreams: number().integer().min(0).default(DEFAULT_MAX_OUTBOUND_STREAMS),
maxOutboundStopStreams: number().integer().min(0).default(MAX_CONNECTIONS)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PeerMap } from '@libp2p/peer-collections'
import { object, mixed, number, boolean } from 'yup'
import { DEFAULT_DATA_LIMIT, DEFAULT_DURATION_LIMIT, DEFAULT_MAX_RESERVATION_CLEAR_INTERVAL, DEFAULT_MAX_RESERVATION_STORE_SIZE, DEFAULT_MAX_RESERVATION_TTL } from '../constants.js'
import { DEFAULT_DATA_LIMIT, DEFAULT_DEFAULT_APPLY_LIMIT, DEFAULT_DURATION_LIMIT, DEFAULT_MAX_RESERVATION_CLEAR_INTERVAL, DEFAULT_MAX_RESERVATION_STORE_SIZE, DEFAULT_MAX_RESERVATION_TTL } from '../constants.js'
import { type Limit, Status } from '../pb/index.js'
import type { RelayReservation } from '../index.js'
import type { RecursivePartial, PeerId, Startable } from '@libp2p/interface'
Expand Down Expand Up @@ -37,13 +37,13 @@ export interface ReservationStoreInit {

export type ReservationStoreOptions = RecursivePartial<ReservationStoreInit>

const configValidator = object({
export const reservationStoreConfigValidator = object({
maxReservations: number().min(0).integer().default(DEFAULT_MAX_RESERVATION_STORE_SIZE),
reservationClearInterval: number().integer().min(0).default(DEFAULT_MAX_RESERVATION_CLEAR_INTERVAL),
applyDefaultLimit: boolean().default(true),
applyDefaultLimit: boolean().default(DEFAULT_DEFAULT_APPLY_LIMIT),
reservationTtl: number().integer().min(0).default(DEFAULT_MAX_RESERVATION_TTL),
defaultDurationLimit: number().integer().min(0).default(DEFAULT_DURATION_LIMIT),
defaultDataLimit: mixed().test('is-bigint', 'Invalid bigint', value => typeof value === 'bigint').default(DEFAULT_DATA_LIMIT)
defaultDataLimit: mixed<bigint>().test('is-bigint', 'Invalid bigint', value => typeof value === 'bigint').default(DEFAULT_DATA_LIMIT)
})
export class ReservationStore implements Startable {
public readonly reservations = new PeerMap<RelayReservation>()
Expand All @@ -57,14 +57,14 @@ export class ReservationStore implements Startable {
private readonly defaultDataLimit: bigint

constructor (options: ReservationStoreOptions = {}) {
const config = configValidator.validateSync(options)
const config = reservationStoreConfigValidator.validateSync(options)

this.maxReservations = config.maxReservations
this.reservationClearInterval = config.reservationClearInterval
this.applyDefaultLimit = config.applyDefaultLimit
this.reservationTtl = config.reservationTtl
this.defaultDurationLimit = config.defaultDurationLimit
this.defaultDataLimit = config.defaultDataLimit as bigint
this.defaultDataLimit = config.defaultDataLimit
}

isStarted (): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { multiaddr } from '@multiformats/multiaddr'
import { pbStream } from 'it-protobuf-stream'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { number, object } from 'yup'
import { DEFAULT_RESERVATION_CONCURRENCY, RELAY_TAG, RELAY_V2_HOP_CODEC } from '../constants.js'
import { DEFAULT_DISCOVER_RELAYS, DEFAULT_MAX_RESERVATION_QUEUE_LENGTH, DEFAULT_RESERVATION_COMPLETION_TIMEOUT, DEFAULT_RESERVATION_CONCURRENCY, RELAY_TAG, RELAY_V2_HOP_CODEC } from '../constants.js'
import { HopMessage, Status } from '../pb/index.js'
import { getExpirationMilliseconds } from '../utils.js'
import type { Reservation } from '../pb/index.js'
Expand Down Expand Up @@ -71,9 +71,9 @@ export interface ReservationStoreEvents {
}

const configValidator = object({
discoverRelays: number().integer().min(0).default(0),
maxReservationQueueLength: number().integer().min(0).default(100),
reservationCompletionTimeout: number().integer().min(0).default(10000),
discoverRelays: number().integer().min(0).default(DEFAULT_DISCOVER_RELAYS),
maxReservationQueueLength: number().integer().min(0).default(DEFAULT_MAX_RESERVATION_QUEUE_LENGTH),
reservationCompletionTimeout: number().integer().min(0).default(DEFAULT_RESERVATION_COMPLETION_TIMEOUT),
reservationConcurrency: number().integer().min(0).default(DEFAULT_RESERVATION_CONCURRENCY)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as mafmt from '@multiformats/mafmt'
import { multiaddr } from '@multiformats/multiaddr'
import { pbStream } from 'it-protobuf-stream'
import { object, number } from 'yup'
import { CIRCUIT_PROTO_CODE, DEFAULT_STOP_TIMEOUT, ERR_HOP_REQUEST_FAILED, ERR_RELAYED_DIAL, MAX_CONNECTIONS, RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from '../constants.js'
import { CIRCUIT_PROTO_CODE, DEFAULT_DISCOVER_RELAYS, DEFAULT_STOP_TIMEOUT, ERR_HOP_REQUEST_FAILED, ERR_RELAYED_DIAL, MAX_CONNECTIONS, RELAY_V2_HOP_CODEC, RELAY_V2_STOP_CODEC } from '../constants.js'
import { StopMessage, HopMessage, Status } from '../pb/index.js'
import { RelayDiscovery } from './discovery.js'
import { createListener } from './listener.js'
Expand Down Expand Up @@ -40,7 +40,7 @@ interface ConnectOptions {
}

const configValidator = object({
discoverRelays: number().min(0).integer().default(0),
discoverRelays: number().min(0).integer().default(DEFAULT_DISCOVER_RELAYS),
maxInboundStopStreams: number().min(0).integer().default(MAX_CONNECTIONS),
maxOutboundStopStreams: number().min(0).integer().default(MAX_CONNECTIONS),
stopTimeout: number().min(0).integer().default(DEFAULT_STOP_TIMEOUT)
Expand Down
6 changes: 4 additions & 2 deletions packages/upnp-nat/src/upnp-nat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import type { Logger, Startable } from '@libp2p/interface'

const DEFAULT_TTL = 7200

const DEFAULT_KEEP_ALIVE = true

function highPort (min = 1024, max = 65535): number {
return Math.floor(Math.random() * (max - min + 1) + min)
}
Expand All @@ -21,7 +23,7 @@ const configValidator = object({
localAddress: string().matches(validIPRegex, 'Invalid IP address'),
description: string(),
ttl: number().integer().min(0).default(DEFAULT_TTL),
keepAlive: boolean().default(true),
keepAlive: boolean().default(DEFAULT_KEEP_ALIVE),
gateway: string().optional()
})

Expand All @@ -31,7 +33,7 @@ export class UPnPNAT implements Startable {
private readonly localAddress?: string
private readonly description: string
private readonly ttl: number
private readonly keepAlive?: boolean
private readonly keepAlive: boolean
private readonly gateway?: string
private started: boolean
private client?: NatAPI
Expand Down

0 comments on commit b0f60e7

Please sign in to comment.