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

feat: announce addresses via config #3409

Merged
merged 1 commit into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The js-ipfs config file is a JSON document located in the root directory of the
- [`Delegates`](#delegates)
- [`Gateway`](#gateway)
- [`Swarm`](#swarm)
- [`Announce`](#announce)
- [`Bootstrap`](#bootstrap)
- [`Datastore`](#datastore)
- [`Spec`](#spec)
Expand Down Expand Up @@ -111,6 +112,15 @@ Default:
]
```

### `Announce`

Array of [Multiaddr](https://github.com/multiformats/multiaddr/) describing which addresses to [announce](https://github.com/libp2p/js-libp2p/tree/master/src/address-manager#announce-addresses) over the network.

Default:
```json
[]
```

## `Bootstrap`

Bootstrap is an array of [Multiaddr](https://github.com/multiformats/multiaddr/) of trusted nodes to connect to in order to
Expand Down
4 changes: 3 additions & 1 deletion packages/ipfs-core/src/components/libp2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p
}
},
addresses: {
listen: multiaddrs
listen: multiaddrs,
announce: get(options, 'addresses.announce',
get(config, 'Addresses.Announce', []))
},
connectionManager: get(options, 'connectionManager', {
maxConnections: get(options, 'config.Swarm.ConnMgr.HighWater',
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 @@ -4,6 +4,7 @@ module.exports = () => ({
Addresses: {
Swarm: [
],
Announce: [],
API: '',
Gateway: '',
Delegates: [
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 @@ -6,6 +6,7 @@ module.exports = () => ({
'/ip4/0.0.0.0/tcp/4002',
'/ip4/127.0.0.1/tcp/4003/ws'
],
Announce: [],
API: '/ip4/127.0.0.1/tcp/5002',
Gateway: '/ip4/127.0.0.1/tcp/9090',
Delegates: [
Expand Down
30 changes: 29 additions & 1 deletion packages/ipfs-core/test/libp2p.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ describe('libp2p customization', function () {
})

it('should allow for overriding via options', async () => {
const annAddr = '/dns4/test.ipfs.io/tcp/443/wss'

libp2p = libp2pComponent({
peerId,
repo: { datastore },
Expand All @@ -169,7 +171,10 @@ describe('libp2p customization', function () {
transport: [DummyTransport],
peerDiscovery: [DummyDiscovery]
},
config: { relay: { enabled: false } }
config: { relay: { enabled: false } },
addresses: {
announce: [annAddr]
}
}
}
})
Expand All @@ -183,10 +188,33 @@ describe('libp2p customization', function () {
const discoveries = Array.from(libp2p._discovery.values())
expect(discoveries).to.have.length(1)
expect(discoveries[0] instanceof DummyDiscovery).to.be.true()

expect(libp2p.multiaddrs.map(m => m.toString())).to.include(annAddr)
})
})

describe('config', () => {
it('should be able to specify Announce addresses', async () => {
const annAddr = '/dns4/test.ipfs.io/tcp/443/wss'

libp2p = libp2pComponent({
peerId,
repo: { datastore },
print: console.log, // eslint-disable-line no-console
config: {
...testConfig,
Addresses: {
...testConfig.Addresses,
Announce: [annAddr]
}
}
})

await libp2p.start()

expect(libp2p.multiaddrs.map(m => m.toString())).to.include(annAddr)
})

it('should select gossipsub as pubsub router', async () => {
libp2p = libp2pComponent({
peerId,
Expand Down