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

Commit 284427d

Browse files
committed
feat: announce addresses via config
1 parent 288a259 commit 284427d

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

docs/CONFIG.md

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The js-ipfs config file is a JSON document located in the root directory of the
1010
- [`Delegates`](#delegates)
1111
- [`Gateway`](#gateway)
1212
- [`Swarm`](#swarm)
13+
- [`Announce`](#announce)
1314
- [`Bootstrap`](#bootstrap)
1415
- [`Datastore`](#datastore)
1516
- [`Spec`](#spec)
@@ -111,6 +112,15 @@ Default:
111112
]
112113
```
113114

115+
### `Announce`
116+
117+
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.
118+
119+
Default:
120+
```json
121+
[]
122+
```
123+
114124
## `Bootstrap`
115125

116126
Bootstrap is an array of [Multiaddr](https://github.com/multiformats/multiaddr/) of trusted nodes to connect to in order to

packages/ipfs-core/src/components/libp2p.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ function getLibp2pOptions ({ options, config, datastore, keys, keychainConfig, p
101101
}
102102
},
103103
addresses: {
104-
listen: multiaddrs
104+
listen: multiaddrs,
105+
announce: get(options, 'addresses.announce',
106+
get(config, 'Addresses.Announce', []))
105107
},
106108
connectionManager: get(options, 'connectionManager', {
107109
maxConnections: get(options, 'config.Swarm.ConnMgr.HighWater',

packages/ipfs-core/src/runtime/config-browser.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = () => ({
44
Addresses: {
55
Swarm: [
66
],
7+
Announce: [],
78
API: '',
89
Gateway: '',
910
Delegates: [

packages/ipfs-core/src/runtime/config-nodejs.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = () => ({
66
'/ip4/0.0.0.0/tcp/4002',
77
'/ip4/127.0.0.1/tcp/4003/ws'
88
],
9+
Announce: [],
910
API: '/ip4/127.0.0.1/tcp/5002',
1011
Gateway: '/ip4/127.0.0.1/tcp/9090',
1112
Delegates: [

packages/ipfs-core/test/libp2p.spec.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ describe('libp2p customization', function () {
158158
})
159159

160160
it('should allow for overriding via options', async () => {
161+
const annAddr = '/dns4/test.ipfs.io/tcp/443/wss'
162+
161163
libp2p = libp2pComponent({
162164
peerId,
163165
repo: { datastore },
@@ -169,7 +171,10 @@ describe('libp2p customization', function () {
169171
transport: [DummyTransport],
170172
peerDiscovery: [DummyDiscovery]
171173
},
172-
config: { relay: { enabled: false } }
174+
config: { relay: { enabled: false } },
175+
addresses: {
176+
announce: [annAddr]
177+
}
173178
}
174179
}
175180
})
@@ -183,10 +188,33 @@ describe('libp2p customization', function () {
183188
const discoveries = Array.from(libp2p._discovery.values())
184189
expect(discoveries).to.have.length(1)
185190
expect(discoveries[0] instanceof DummyDiscovery).to.be.true()
191+
192+
expect(libp2p.multiaddrs.map(m => m.toString())).to.include(annAddr)
186193
})
187194
})
188195

189196
describe('config', () => {
197+
it('should be able to specify Announce addresses', async () => {
198+
const annAddr = '/dns4/test.ipfs.io/tcp/443/wss'
199+
200+
libp2p = libp2pComponent({
201+
peerId,
202+
repo: { datastore },
203+
print: console.log, // eslint-disable-line no-console
204+
config: {
205+
...testConfig,
206+
Addresses: {
207+
...testConfig.Addresses,
208+
Announce: [annAddr]
209+
}
210+
}
211+
})
212+
213+
await libp2p.start()
214+
215+
expect(libp2p.multiaddrs.map(m => m.toString())).to.include(annAddr)
216+
})
217+
190218
it('should select gossipsub as pubsub router', async () => {
191219
libp2p = libp2pComponent({
192220
peerId,

0 commit comments

Comments
 (0)