mirror of
https://github.com/fluencelabs/js-libp2p-tcp
synced 2025-04-25 21:12:32 +00:00
fix: intermittent error when asking for interfaces (#137)
Get interfaces only once per run
This commit is contained in:
parent
e9e1f56b87
commit
af9804e778
@ -29,8 +29,9 @@ function isAnyAddr (ip) {
|
|||||||
* @param {string} family One of ['IPv6', 'IPv4']
|
* @param {string} family One of ['IPv6', 'IPv4']
|
||||||
* @returns {string[]} an array of ip address strings
|
* @returns {string[]} an array of ip address strings
|
||||||
*/
|
*/
|
||||||
|
const networks = os.networkInterfaces()
|
||||||
function getNetworkAddrs (family) {
|
function getNetworkAddrs (family) {
|
||||||
return Object.values(os.networkInterfaces()).reduce((addresses, netAddrs) => {
|
return Object.values(networks).reduce((addresses, netAddrs) => {
|
||||||
netAddrs.forEach(netAddr => {
|
netAddrs.forEach(netAddr => {
|
||||||
// Add the ip of each matching network interface
|
// Add the ip of each matching network interface
|
||||||
if (netAddr.family === family) addresses.push(netAddr.address)
|
if (netAddr.family === family) addresses.push(netAddr.address)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user