js-libp2p/test/core/consume-peer-record.spec.js
Alex Potsides 0a6bc0d101
feat: add UPnP NAT manager (#810)
* feat: add uPnP nat manager

Adds a really basic nat manager that attempts to use UPnP to punch
a hole through your router for any IPV4 tcp addresses you have
configured.

Adds any configured addresses to the node's observed addresses list
and adds observed addresses to `libp2p.multiaddrs` so we exchange
them with peers when performing `identify` and people can dial you.

Adds configuration options under `config.nat`

Hole punching is async to not affect start up time.

Co-authored-by: Vasco Santos <vasco.santos@moxy.studio>
2021-01-27 14:55:26 +01:00

47 lines
945 B
JavaScript

'use strict'
/* eslint-env mocha */
const Transport = require('libp2p-websockets')
const { NOISE: Crypto } = require('libp2p-noise')
const Libp2p = require('../../src')
const { createPeerId } = require('../utils/creators/peer')
describe('Consume peer record', () => {
let libp2p
beforeEach(async () => {
const [peerId] = await createPeerId()
const config = {
peerId,
modules: {
transport: [Transport],
connEncryption: [Crypto]
}
}
libp2p = await Libp2p.create(config)
})
afterEach(async () => {
await libp2p.stop()
})
it('should consume peer record when observed addrs are added', async () => {
let done
libp2p.peerStore.addressBook.consumePeerRecord = () => {
done()
}
const p = new Promise(resolve => {
done = resolve
})
libp2p.addressManager.addObservedAddr('/ip4/123.123.123.123/tcp/3983')
await p
libp2p.stop()
})
})