@@ -46,13 +46,13 @@ Let's configure the relevant modules:
4646``` js
4747import { noise } from ' @chainsafe/libp2p-noise'
4848import { yamux } from ' @chainsafe/libp2p-yamux'
49- import { webSockets } from ' @libp2p/websockets'
50- import { createLibp2p } from ' libp2p'
5149import { autoTLS } from ' @libp2p/auto-tls'
50+ import { loadOrCreateSelfKey } from ' @libp2p/config'
5251import { identify , identifyPush } from ' @libp2p/identify'
5352import { keychain } from ' @libp2p/keychain'
53+ import { webSockets } from ' @libp2p/websockets'
5454import { LevelDatastore } from ' datastore-level'
55- import { loadOrCreateSelfKey } from ' @ libp2p/config '
55+ import { createLibp2p } from ' libp2p'
5656
5757const datastore = new LevelDatastore (' ./db' )
5858await datastore .open ()
@@ -91,16 +91,13 @@ const libp2p = await createLibp2p({
9191> set the ` acmeDirectory ` to a staging address, though be aware that any
9292> certificates generated will be self-signed:
9393>
94- > ``` TypeScript
95- > const libp2p = await createLibp2p ({
96- > // other config
97- > services: {
98- > autoTLS: autoTLS ({
99- > acmeDirectory: ' https://acme-staging-v02.api.letsencrypt.org/directory'
100- > }),
101- > // other config
102- > }
103- > })
94+ > ``` diff
95+ > services: {
96+ > - autoTLS: autoTLS()
97+ > + autoTLS: autoTLS({
98+ > + acmeDirectory: 'https://acme-staging-v02.api.letsencrypt.org/directory'
99+ > + }),
100+ > identify: identify(),
104101> ```
105102
106103# # Getting a publicly routable address
@@ -122,16 +119,18 @@ config key:
122119> auto-confirmation - see the next section on confirming dialable addresses for
123120> more
124121
125- ` ` ` js
126- const libp2p = await createLibp2p ({
127- addresses: {
128- appendAnnounce: [
129- ' /ip4/123.123.123.123/tcp/1234/ws'
130- ],
131- // other config
132- },
133- // other config
134- })
122+ ```diff
123+ addresses: {
124+ listen: [
125+ '/ip4/0.0.0.0/tcp/0/ws',
126+ '/ip6/::/tcp/0/ws'
127+ - ]
128+ + ],
129+ + appendAnnounce: [
130+ + '/ip4/123.123.123.123/tcp/1234/ws'
131+ + ],
132+ },
133+ transports: [
135134```
136135
137136### Automatic configuration via UPnP
@@ -148,15 +147,16 @@ automatically configure port forwarding for IPv4 and IPv6 networks:
148147> ISP provided routers sometimes do not and most ship with UPnP disabled by
149148> default - please check your router documentation for more information
150149
151- ``` TypeScript
152- import { uPnPNAT } from ' @libp2p/upnp-nat'
153-
154- const libp2p = await createLibp2p ({
155- services: {
156- upnp: uPnPNAT ()
157- // other config
158- }
159- })
150+ ``` diff
151+ import { keychain } from '@libp2p/keychain'
152+ + import { uPnPNAT } from '@libp2p/upnp-nat'
153+ import { webSockets } from '@libp2p/websockets'
154+ ```
155+ ``` diff
156+ services: {
157+ autoTLS: autoTLS(),
158+ + upnp: uPnPNAT(),
159+ identify: identify(),
160160```
161161
162162### Confirming dialable addresses
@@ -176,22 +176,19 @@ confirmed to be dialable.
176176We can skip this and explicitly trust ` libp2p.direct ` and our router by
177177auto-confirming the DNS mapping and the public IP address:
178178
179- ``` TypeScript
180- import { uPnPNAT } from ' @libp2p/upnp-nat'
181-
182- const libp2p = await createLibp2p ({
183- services: {
184- autoTLS: autoTLS ({
185- // automatically mark *.<peerID>.libp2p.direct as routable
186- autoConfirmAddress: true
187- }),
188- upnp: uPnPNAT ({
189- // automatically mark any detected socket address as routable
190- autoConfirmAddress: true
191- })
192- // other config
193- }
194- })
179+ ``` diff
180+ services: {
181+ - autoTLS: autoTLS(),
182+ + autoTLS: autoTLS({
183+ + // automatically mark *.<peerID>.libp2p.direct as routable
184+ + autoConfirmAddress: true
185+ + }),
186+ - upnp: uPnPNAT(),
187+ + upnp: uPnPNAT({
188+ + // automatically mark any detected socket address as routable
189+ + autoConfirmAddress: true
190+ + }),
191+ identify: identify(),
195192```
196193
197194To not trust these actors and instead require confirmation from multiple peers
@@ -220,36 +217,42 @@ Finally we need to also use the [@libp2p/bootstrap](https://www.npmjs.com/packag
220217module to connect to an initial set of peers that will let us start to fill our
221218routing table and perform queries:
222219
223- ``` js
224- import { autoNAT } from ' @libp2p/autonat'
225- import { bootstrap } from ' @libp2p/bootstrap'
226- import { kadDHT , removePrivateAddressesMapper } from ' @libp2p/kad-dht'
227- import { tcp } from ' @libp2p/tcp'
220+ ``` diff
221+ import { autoTLS } from '@libp2p/auto-tls'
222+ + import { bootstrap } from '@libp2p/bootstrap'
223+ import { loadOrCreateSelfKey } from '@libp2p/config'
224+ import { identify, identifyPush } from '@libp2p/identify'
225+ + import { kadDHT, removePrivateAddressesMapper } from '@libp2p/kad-dht'
226+ import { keychain } from '@libp2p/keychain'
227+ + import { tcp } from '@libp2p/tcp'
228+ import { uPnPNAT } from '@libp2p/upnp-nat'
229+ ```
228230
229- const libp2p = await createLibp2p ({
230- // other config
231- transports: [
232- // other config
233- tcp ()
234- ],
235- services: {
236- autoNAT: autoNAT (),
237- aminoDHT: kadDHT ({
238- protocol: ' /ipfs/kad/1.0.0' ,
239- peerInfoMapper: removePrivateAddressesMapper
240- }),
241- bootstrap: bootstrap ({
242- list: [
243- ' /dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN' ,
244- ' /dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb' ,
245- ' /dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt' ,
246- ' /dnsaddr/va1.bootstrap.libp2p.io/p2p/12D3KooWKnDdG3iXw9eTFijk3EWSunZcFi54Zka4wmtqtt6rPxc8' ,
247- ' /ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ'
248- ]
249- })
250- // other config
251- }
252- })
231+ ``` diff
232+ transports: [
233+ + tcp()
234+ webSockets()
235+ ],
236+ ```
237+
238+ ``` diff
239+ services: {
240+ autoNAT: autoNAT(),
241+ + aminoDHT: kadDHT({
242+ + protocol: '/ipfs/kad/1.0.0',
243+ + peerInfoMapper: removePrivateAddressesMapper
244+ + }),
245+ + bootstrap: bootstrap({
246+ + list: [
247+ + '/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
248+ + '/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
249+ + '/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt',
250+ + '/dnsaddr/va1.bootstrap.libp2p.io/p2p/12D3KooWKnDdG3iXw9eTFijk3EWSunZcFi54Zka4wmtqtt6rPxc8',
251+ + '/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ'
252+ + ]
253+ + }),
254+ upnp: uPnPNAT(),
255+ identify: identify(),
253256```
254257
255258If you are running on your own network which has better support for varied
0 commit comments