mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-30 06:11:05 +00:00
* 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>
47 lines
945 B
JavaScript
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()
|
|
})
|
|
})
|