Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: update types after feedback from ceramic
Browse files Browse the repository at this point in the history
Some of the types need a little correcting.

Fixes #3640
  • Loading branch information
achingbrain committed Apr 29, 2021
1 parent 7e61fbf commit 326404b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 37 deletions.
2 changes: 1 addition & 1 deletion examples/custom-ipfs-repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion packages/ipfs-core-types/src/config/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export interface AddressConfig {
RPC?: string
Delegates?: string[]
Gateway?: string
Swarm?: string[]
Swarm?: string[],
Announce?: string[],
NoAnnounce?: string[]
}

export interface APIConfig {
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 15 additions & 29 deletions packages/ipfs-core/src/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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: {
Expand All @@ -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,
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions packages/ipfs-core/src/components/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions packages/ipfs-core/src/runtime/config-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = () => ({
Swarm: [
],
Announce: [],
NoAnnounce: [],
API: '',
Gateway: '',
RPC: '',
Expand Down
1 change: 1 addition & 0 deletions packages/ipfs-core/src/runtime/config-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 326404b

Please sign in to comment.