fix(network): fix stun error on startup if no network available
Fixed #7
This commit is contained in:
10
src/background/checkInternet.js
Normal file
10
src/background/checkInternet.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// https://stackoverflow.com/questions/15270902/check-for-internet-connectivity-in-nodejs
|
||||||
|
module.exports = function checkInternet(cb) {
|
||||||
|
require('dns').lookup('google.com',function(err) {
|
||||||
|
if (err && err.code == "ENOTFOUND") {
|
||||||
|
cb(false);
|
||||||
|
} else {
|
||||||
|
cb(true);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
@ -15,7 +15,7 @@ let config = {
|
|||||||
sitemapMaxSize: 25000,
|
sitemapMaxSize: 25000,
|
||||||
|
|
||||||
sphinx: {
|
sphinx: {
|
||||||
host : 'localhost',
|
host : '127.0.0.1',
|
||||||
port : 9306,
|
port : 9306,
|
||||||
connectionLimit: 30
|
connectionLimit: 30
|
||||||
},
|
},
|
||||||
|
@ -26,6 +26,8 @@ const balanceDebug = _debug('main:balance');
|
|||||||
const fakeTorrentsDebug = _debug('main:fakeTorrents');
|
const fakeTorrentsDebug = _debug('main:fakeTorrents');
|
||||||
const quotaDebug = _debug('main:quota');
|
const quotaDebug = _debug('main:quota');
|
||||||
|
|
||||||
|
const checkInternet = require('./checkInternet')
|
||||||
|
|
||||||
const {torrentTypeDetect} = require('../app/content');
|
const {torrentTypeDetect} = require('../app/content');
|
||||||
|
|
||||||
const torrentClient = require('./torrentClient')
|
const torrentClient = require('./torrentClient')
|
||||||
@ -1062,6 +1064,9 @@ client.on('complete', function (metadata, infohash, rinfo) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
checkInternet((connected) => {
|
||||||
|
if(!connected)
|
||||||
|
return
|
||||||
|
|
||||||
const { STUN_BINDING_REQUEST, STUN_ATTR_XOR_MAPPED_ADDRESS } = stun.constants
|
const { STUN_BINDING_REQUEST, STUN_ATTR_XOR_MAPPED_ADDRESS } = stun.constants
|
||||||
const stunServer = stun.createServer()
|
const stunServer = stun.createServer()
|
||||||
@ -1074,6 +1079,7 @@ stunServer.once('bindingResponse', stunMsg => {
|
|||||||
p2p.ignoreAddresses.push(address)
|
p2p.ignoreAddresses.push(address)
|
||||||
})
|
})
|
||||||
stunServer.send(stunRequest, 19302, 'stun.l.google.com')
|
stunServer.send(stunRequest, 19302, 'stun.l.google.com')
|
||||||
|
})
|
||||||
|
|
||||||
let upnp
|
let upnp
|
||||||
if(config.upnp)
|
if(config.upnp)
|
||||||
|
Reference in New Issue
Block a user