Skip to content
Snippets Groups Projects
Commit 11a1b027 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] #1084 WS2P: UPnP code under non-UPnP environment makes Duniter crash

parent b87e12a5
No related branches found
No related tags found
No related merge requests found
...@@ -107,10 +107,12 @@ export class WS2PAPI extends stream.Transform { ...@@ -107,10 +107,12 @@ export class WS2PAPI extends stream.Transform {
this.upnpAPI.stopRegular(); this.upnpAPI.stopRegular();
} }
try { try {
this.upnpAPI = await new WS2PUpnp(this.logger) this.upnpAPI = new WS2PUpnp(this.logger)
const { host, port } = await this.upnpAPI.startRegular() const { host, port, available } = await this.upnpAPI.startRegular()
if (available) {
await this.cluster.listen(host, port) await this.cluster.listen(host, port)
await this.server.PeeringService.generateSelfPeer(this.server.conf) await this.server.PeeringService.generateSelfPeer(this.server.conf)
}
} catch (e) { } catch (e) {
this.logger.warn(e); this.logger.warn(e);
} }
......
...@@ -6,12 +6,13 @@ import {CertificationDTO} from "../../../lib/dto/CertificationDTO" ...@@ -6,12 +6,13 @@ import {CertificationDTO} from "../../../lib/dto/CertificationDTO"
import {MembershipDTO} from "../../../lib/dto/MembershipDTO" import {MembershipDTO} from "../../../lib/dto/MembershipDTO"
import {TransactionDTO} from "../../../lib/dto/TransactionDTO" import {TransactionDTO} from "../../../lib/dto/TransactionDTO"
import {PeerDTO} from "../../../lib/dto/PeerDTO" import {PeerDTO} from "../../../lib/dto/PeerDTO"
import {WS2PConstants} from "./constants"
const ws = require('ws') const ws = require('ws')
const nuuid = require('node-uuid'); const nuuid = require('node-uuid');
const logger = require('../../../lib/logger').NewLogger('ws2p') const logger = require('../../../lib/logger').NewLogger('ws2p')
const MAXIMUM_ERRORS_COUNT = 5 const MAXIMUM_ERRORS_COUNT = 5
const REQUEST_TIMEOUT_VALUE = 1000 * 5 // 10 seconds const REQUEST_TIMEOUT_VALUE = WS2PConstants.REQUEST_TIMEOUT
enum WS2P_ERR { enum WS2P_ERR {
REJECTED_PUBKEY_OR_INCORRECT_ASK_SIGNATURE_FROM_REMOTE, REJECTED_PUBKEY_OR_INCORRECT_ASK_SIGNATURE_FROM_REMOTE,
......
...@@ -21,10 +21,10 @@ export class WS2PUpnp { ...@@ -21,10 +21,10 @@ export class WS2PUpnp {
try { try {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
this.client.externalIp((err:any, res:any) => { this.client.externalIp((err:any, res:any) => {
if (err) { if (err || !res) {
resolve(true) reject()
} else { } else {
resolve(false) resolve()
} }
}) })
}) })
...@@ -67,11 +67,14 @@ export class WS2PUpnp { ...@@ -67,11 +67,14 @@ export class WS2PUpnp {
async startRegular() { async startRegular() {
this.stopRegular(); this.stopRegular();
if (await this.checkUPnPisAvailable()) { const available = await this.checkUPnPisAvailable()
if (available) {
// Update UPnP IGD every INTERVAL seconds // Update UPnP IGD every INTERVAL seconds
this.interval = setInterval(() => this.openPort(), 1000 * WS2PConstants.WS2P_UPNP_INTERVAL) this.interval = setInterval(() => this.openPort(), 1000 * WS2PConstants.WS2P_UPNP_INTERVAL)
const { host, port } = await this.openPort()
return { host, port, available }
} }
return this.openPort() return { host: '', port: 0, available: false }
} }
stopRegular() { stopRegular() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment