@@ -13,7 +13,7 @@ const PubsubRouters = require('../runtime/libp2p-pubsub-routers-nodejs')
1313 * @typedef {import('peer-id') } PeerId
1414 * @typedef {import('../types').Options } IPFSOptions
1515 * @typedef {import('libp2p') } LibP2P
16- * @typedef {import('libp2p').Libp2pOptions & import('libp2p').constructorOptions } Options
16+ * @typedef {import('libp2p').Libp2pOptions & import('libp2p').CreateOptions } Libp2pOptions
1717 * @typedef {import('ipfs-core-types/src/config').Config } IPFSConfig
1818 * @typedef {import('multiaddr').Multiaddr } Multiaddr
1919 */
@@ -66,6 +66,7 @@ module.exports = ({
6666 * @param {KeychainConfig } input.keychainConfig
6767 * @param {PeerId } input.peerId
6868 * @param {Multiaddr[] } input.multiaddrs
69+ * @returns {Libp2pOptions }
6970 */
7071function getLibp2pOptions ( { options, config, datastore, keys, keychainConfig, peerId, multiaddrs } ) {
7172 const getPubsubRouter = ( ) => {
@@ -93,25 +94,20 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p
9394 config : {
9495 peerDiscovery : {
9596 mdns : {
96- enabled : get ( options , 'config.Discovery.MDNS.Enabled' ,
97- get ( config , 'Discovery.MDNS.Enabled' , true ) )
97+ enabled : get ( options , 'config.Discovery.MDNS.Enabled' , get ( config , 'Discovery.MDNS.Enabled' , true ) )
9898 } ,
9999 webRTCStar : {
100- enabled : get ( options , 'config.Discovery.webRTCStar.Enabled' ,
101- get ( config , 'Discovery.webRTCStar.Enabled' , true ) )
100+ enabled : get ( options , 'config.Discovery.webRTCStar.Enabled' , get ( config , 'Discovery.webRTCStar.Enabled' , true ) )
102101 } ,
103102 bootstrap : {
104103 list : get ( options , 'config.Bootstrap' , get ( config , 'Bootstrap' , [ ] ) )
105104 }
106105 } ,
107106 relay : {
108- enabled : get ( options , 'relay.enabled' ,
109- get ( config , 'relay.enabled' , true ) ) ,
107+ enabled : get ( options , 'relay.enabled' , get ( config , 'relay.enabled' , true ) ) ,
110108 hop : {
111- enabled : get ( options , 'relay.hop.enabled' ,
112- get ( config , 'relay.hop.enabled' , false ) ) ,
113- active : get ( options , 'relay.hop.active' ,
114- get ( config , 'relay.hop.active' , false ) )
109+ enabled : get ( options , 'relay.hop.enabled' , get ( config , 'relay.hop.enabled' , false ) ) ,
110+ active : get ( options , 'relay.hop.active' , get ( config , 'relay.hop.active' , false ) )
115111 }
116112 } ,
117113 dht : {
@@ -120,30 +116,20 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p
120116 kBucketSize : get ( options , 'dht.kBucketSize' , 20 )
121117 } ,
122118 pubsub : {
123- enabled : get ( options , 'config.Pubsub.Enabled' ,
124- get ( config , 'Pubsub.Enabled' , true ) )
119+ enabled : get ( options , 'config.Pubsub.Enabled' , get ( config , 'Pubsub.Enabled' , true ) )
125120 } ,
126121 nat : {
127- enabled : get ( options , 'libp2p.config.nat.enabled' , ! get ( config , 'Swarm.DisableNatPortMap' , false ) ) ,
128- ttl : get ( options , 'libp2p.config.nat.ttl' , 7200 ) ,
129- keepAlive : get ( options , 'libp2p.config.nat.keepAlive' , true ) ,
130- gateway : get ( options , 'libp2p.config.nat.gateway' ) ,
131- externalIp : get ( options , 'libp2p.config.nat.externalIp' ) ,
132- pmp : {
133- enabled : get ( options , 'libp2p.config.nat.pmp.enabled' , false )
134- }
122+ enabled : ! get ( config , 'Swarm.DisableNatPortMap' , false )
135123 }
136124 } ,
137125 addresses : {
138126 listen : multiaddrs . map ( ma => ma . toString ( ) ) ,
139- announce : get ( options , 'addresses.announce' ,
140- get ( config , 'Addresses.Announce ' , [ ] ) )
127+ announce : get ( options , 'addresses.announce' , get ( config , 'Addresses.Announce' , [ ] ) ) ,
128+ noAnnounce : get ( options , 'addresses.noAnnounce' , get ( config , 'Addresses.NoAnnounce ' , [ ] ) )
141129 } ,
142130 connectionManager : get ( options , 'connectionManager' , {
143- maxConnections : get ( options , 'config.Swarm.ConnMgr.HighWater' ,
144- get ( config , 'Swarm.ConnMgr.HighWater' ) ) ,
145- minConnections : get ( options , 'config.Swarm.ConnMgr.LowWater' ,
146- get ( config , 'Swarm.ConnMgr.LowWater' ) )
131+ maxConnections : get ( options , 'config.Swarm.ConnMgr.HighWater' , get ( config , 'Swarm.ConnMgr.HighWater' ) ) ,
132+ minConnections : get ( options , 'config.Swarm.ConnMgr.LowWater' , get ( config , 'Swarm.ConnMgr.LowWater' ) )
147133 } ) ,
148134 keychain : {
149135 datastore : keys ,
@@ -155,10 +141,11 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p
155141 // Note: libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified
156142 const getEnvLibp2pOptions = require ( '../runtime/libp2p-nodejs' )
157143
158- let constructorOptions = get ( options , 'libp2p' , { } )
144+ /** @type {import('libp2p').Libp2pOptions | undefined } */
145+ let constructorOptions = get ( options , 'libp2p' , undefined )
159146
160147 if ( typeof constructorOptions === 'function' ) {
161- constructorOptions = { }
148+ constructorOptions = undefined
162149 }
163150
164151 // Merge defaults with Node.js/browser/other environments options and configuration
0 commit comments