diff --git a/examples/custom-ipfs-repo/package.json b/examples/custom-ipfs-repo/package.json index 6ddb416f46..b941303b6d 100644 --- a/examples/custom-ipfs-repo/package.json +++ b/examples/custom-ipfs-repo/package.json @@ -12,7 +12,7 @@ "dependencies": { "datastore-fs": "4.0.0", "ipfs": "^0.54.4", - "ipfs-repo": "^9.1.1", + "ipfs-repo": "^9.1.3", "it-all": "^1.0.4" }, "devDependencies": { diff --git a/packages/ipfs-cli/package.json b/packages/ipfs-cli/package.json index bf51e626ca..c4eafac171 100644 --- a/packages/ipfs-cli/package.json +++ b/packages/ipfs-cli/package.json @@ -42,7 +42,7 @@ "ipfs-core-utils": "^0.7.2", "ipfs-daemon": "^0.5.4", "ipfs-http-client": "^49.0.4", - "ipfs-repo": "^9.1.1", + "ipfs-repo": "^9.1.3", "ipfs-utils": "^6.0.4", "ipld-dag-cbor": "^1.0.0", "ipld-dag-pb": "^0.22.1", diff --git a/packages/ipfs-core-types/src/config/index.d.ts b/packages/ipfs-core-types/src/config/index.d.ts index 0c21ea3936..941b3033a8 100644 --- a/packages/ipfs-core-types/src/config/index.d.ts +++ b/packages/ipfs-core-types/src/config/index.d.ts @@ -51,7 +51,9 @@ export interface AddressConfig { RPC?: string Delegates?: string[] Gateway?: string - Swarm?: string[] + Swarm?: string[], + Announce?: string[], + NoAnnounce?: string[] } export interface APIConfig { diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index 02bc42cda6..60d3d2c5b7 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -74,7 +74,7 @@ "ipfs-block-service": "^0.19.0", "ipfs-core-types": "^0.3.1", "ipfs-core-utils": "^0.7.2", - "ipfs-repo": "^9.1.1", + "ipfs-repo": "^9.1.3", "ipfs-unixfs": "^4.0.3", "ipfs-unixfs-exporter": "^5.0.3", "ipfs-unixfs-importer": "^7.0.3", diff --git a/packages/ipfs-core/src/components/libp2p.js b/packages/ipfs-core/src/components/libp2p.js index 2fa457bf8c..899cdaa220 100644 --- a/packages/ipfs-core/src/components/libp2p.js +++ b/packages/ipfs-core/src/components/libp2p.js @@ -13,7 +13,7 @@ const PubsubRouters = require('../runtime/libp2p-pubsub-routers-nodejs') * @typedef {import('peer-id')} PeerId * @typedef {import('../types').Options} IPFSOptions * @typedef {import('libp2p')} LibP2P - * @typedef {import('libp2p').Libp2pOptions & import('libp2p').constructorOptions} Options + * @typedef {import('libp2p').Libp2pOptions & import('libp2p').constructorOptions} Libp2pOptions * @typedef {import('ipfs-core-types/src/config').Config} IPFSConfig * @typedef {import('multiaddr').Multiaddr} Multiaddr */ @@ -93,25 +93,20 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p config: { peerDiscovery: { mdns: { - enabled: get(options, 'config.Discovery.MDNS.Enabled', - get(config, 'Discovery.MDNS.Enabled', true)) + enabled: get(options, 'config.Discovery.MDNS.Enabled', get(config, 'Discovery.MDNS.Enabled', true)) }, webRTCStar: { - enabled: get(options, 'config.Discovery.webRTCStar.Enabled', - get(config, 'Discovery.webRTCStar.Enabled', true)) + enabled: get(options, 'config.Discovery.webRTCStar.Enabled', get(config, 'Discovery.webRTCStar.Enabled', true)) }, bootstrap: { list: get(options, 'config.Bootstrap', get(config, 'Bootstrap', [])) } }, relay: { - enabled: get(options, 'relay.enabled', - get(config, 'relay.enabled', true)), + enabled: get(options, 'relay.enabled', get(config, 'relay.enabled', true)), hop: { - enabled: get(options, 'relay.hop.enabled', - get(config, 'relay.hop.enabled', false)), - active: get(options, 'relay.hop.active', - get(config, 'relay.hop.active', false)) + enabled: get(options, 'relay.hop.enabled', get(config, 'relay.hop.enabled', false)), + active: get(options, 'relay.hop.active', get(config, 'relay.hop.active', false)) } }, dht: { @@ -120,30 +115,20 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p kBucketSize: get(options, 'dht.kBucketSize', 20) }, pubsub: { - enabled: get(options, 'config.Pubsub.Enabled', - get(config, 'Pubsub.Enabled', true)) + enabled: get(options, 'config.Pubsub.Enabled', get(config, 'Pubsub.Enabled', true)) }, nat: { - enabled: get(options, 'libp2p.config.nat.enabled', !get(config, 'Swarm.DisableNatPortMap', false)), - ttl: get(options, 'libp2p.config.nat.ttl', 7200), - keepAlive: get(options, 'libp2p.config.nat.keepAlive', true), - gateway: get(options, 'libp2p.config.nat.gateway'), - externalIp: get(options, 'libp2p.config.nat.externalIp'), - pmp: { - enabled: get(options, 'libp2p.config.nat.pmp.enabled', false) - } + enabled: !get(config, 'Swarm.DisableNatPortMap', false) } }, addresses: { listen: multiaddrs.map(ma => ma.toString()), - announce: get(options, 'addresses.announce', - get(config, 'Addresses.Announce', [])) + announce: get(options, 'addresses.announce', get(config, 'Addresses.Announce', [])), + noAnnounce: get(options, 'addresses.noAnnounce', get(config, 'Addresses.NoAnnounce', [])) }, connectionManager: get(options, 'connectionManager', { - maxConnections: get(options, 'config.Swarm.ConnMgr.HighWater', - get(config, 'Swarm.ConnMgr.HighWater')), - minConnections: get(options, 'config.Swarm.ConnMgr.LowWater', - get(config, 'Swarm.ConnMgr.LowWater')) + maxConnections: get(options, 'config.Swarm.ConnMgr.HighWater', get(config, 'Swarm.ConnMgr.HighWater')), + minConnections: get(options, 'config.Swarm.ConnMgr.LowWater', get(config, 'Swarm.ConnMgr.LowWater')) }), keychain: { datastore: keys, @@ -155,10 +140,11 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p // Note: libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified const getEnvLibp2pOptions = require('../runtime/libp2p-nodejs') - let constructorOptions = get(options, 'libp2p', {}) + /** @type {import('libp2p').Libp2pOptions | undefined} */ + let constructorOptions = get(options, 'libp2p', undefined) if (typeof constructorOptions === 'function') { - constructorOptions = {} + constructorOptions = undefined } // Merge defaults with Node.js/browser/other environments options and configuration diff --git a/packages/ipfs-core/src/components/network.js b/packages/ipfs-core/src/components/network.js index 5f8d05dd9d..1516fb9fc4 100644 --- a/packages/ipfs-core/src/components/network.js +++ b/packages/ipfs-core/src/components/network.js @@ -48,15 +48,14 @@ class Network { await repo.open() } + /** @type {IPFSConfig} */ const config = await repo.config.getAll() const libp2p = await createLibP2P({ options, repo, peerId, - // @ts-ignore - TODO move config types into ipfs-repo multiaddrs: readAddrs(peerId, config), - // @ts-ignore - TODO move config types into ipfs-repo config, keychainConfig: undefined }) @@ -90,10 +89,8 @@ class Network { module.exports = Network /** - * * @param {PeerId} peerId * @param {IPFSConfig} config - * @returns {Multiaddr[]} */ const readAddrs = (peerId, config) => { const peerIdStr = peerId.toB58String() diff --git a/packages/ipfs-core/src/runtime/config-browser.js b/packages/ipfs-core/src/runtime/config-browser.js index 249871bf51..08d65589be 100644 --- a/packages/ipfs-core/src/runtime/config-browser.js +++ b/packages/ipfs-core/src/runtime/config-browser.js @@ -5,6 +5,7 @@ module.exports = () => ({ Swarm: [ ], Announce: [], + NoAnnounce: [], API: '', Gateway: '', RPC: '', diff --git a/packages/ipfs-core/src/runtime/config-nodejs.js b/packages/ipfs-core/src/runtime/config-nodejs.js index 1ef765647c..3d9aba88f6 100644 --- a/packages/ipfs-core/src/runtime/config-nodejs.js +++ b/packages/ipfs-core/src/runtime/config-nodejs.js @@ -7,6 +7,7 @@ module.exports = () => ({ '/ip4/127.0.0.1/tcp/4003/ws' ], Announce: [], + NoAnnounce: [], API: '/ip4/127.0.0.1/tcp/5002', Gateway: '/ip4/127.0.0.1/tcp/9090', RPC: '/ip4/127.0.0.1/tcp/5003',