|
|
@ -107,10 +107,11 @@ class LocalLokiServer extends EventEmitter {
|
|
|
|
const privatePort = this.server.address().port;
|
|
|
|
const privatePort = this.server.address().port;
|
|
|
|
const portStart = 22100;
|
|
|
|
const portStart = 22100;
|
|
|
|
const portEnd = 22200;
|
|
|
|
const portEnd = 22200;
|
|
|
|
const publicPortsInUse = await new Promise((resolve) => {
|
|
|
|
const publicPortsInUse = await new Promise((resolve, reject) => {
|
|
|
|
this.upnpClient.getMappings({ local: true }, (err, results) => {
|
|
|
|
this.upnpClient.getMappings({ local: true }, (err, results) => {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
resolve([]);
|
|
|
|
// We assume an error here means upnp not enabled
|
|
|
|
|
|
|
|
reject(new textsecure.HolePunchingError('Could not get mapping from upnp. Upnp not available?', err));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
resolve(results.map(entry => entry.public.port));
|
|
|
|
resolve(results.map(entry => entry.public.port));
|
|
|
@ -140,10 +141,11 @@ class LocalLokiServer extends EventEmitter {
|
|
|
|
this.publicPort = publicPort;
|
|
|
|
this.publicPort = publicPort;
|
|
|
|
return publicPort;
|
|
|
|
return publicPort;
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
// continue
|
|
|
|
throw new textsecure.HolePunchingError('Could not punch hole. Disabled upnp?', e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new textsecure.HolePunchingError(`Could not punch hole. Public ports: ${portStart}-${portEnd}`);
|
|
|
|
const e = new Error();
|
|
|
|
|
|
|
|
throw new textsecure.HolePunchingError(`Could not punch hole: no available port. Public ports: ${portStart}-${portEnd}`, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Async wrapper for http server close
|
|
|
|
// Async wrapper for http server close
|
|
|
|
close() {
|
|
|
|
close() {
|
|
|
|