Commit ec1189e2 authored by Éloïs's avatar Éloïs
Browse files

Merge branch 'fix/gitlab/1270' into '1.6'

Migrate to NodeJS 9

Closes #1270, #1269, and #1268

See merge request nodes/typescript/duniter!1245
parents 4dbfcf3e 42b21e09
......@@ -407,14 +407,14 @@ export class MetaDAL extends AbstractSQLite<DBMeta> {
'COMMIT;')
}
private async executeMigration(migration: any[], conf:ConfDTO) {
private async executeMigration(migration: (string|((conf:ConfDTO)=>void)), conf:ConfDTO) {
try {
if (typeof migration == "string") {
// Simple SQL script to pass
await this.exec(migration);
} else if (typeof migration == "function") {
} else {
// JS function to execute
await migration(conf);
......
......@@ -230,7 +230,7 @@ export class BMAPI extends stream.Transform {
}
if (this.server.conf.upnp) {
try {
this.upnpAPI = await upnp(this.server.conf.port, this.server.conf.remoteport, this.logger);
this.upnpAPI = await upnp(this.server.conf.port, this.server.conf.remoteport, this.logger, this.server.conf);
this.upnpAPI.startRegular();
const gateway = await this.upnpAPI.findGateway();
if (gateway) {
......
......@@ -332,7 +332,7 @@ function listInterfaces() {
}
async function upnpConf (noupnp:boolean, logger:any) {
const client = require('nnupnp').createClient();
const client = require('nat-upnp').createClient();
// Look for 2 random ports
const publicPort = await getAvailablePort(client)
const privatePort = publicPort
......
import {BMAConstants} from "./constants"
const upnp = require('nnupnp');
import {ConfDTO} from "../../../lib/dto/ConfDTO"
const upnp = require('nat-upnp');
const Q = require('q');
export const Upnp = async function (localPort:number, remotePort:number, logger:any) {
export const Upnp = async function (localPort:number, remotePort:number, logger:any, conf:ConfDTO) {
"use strict";
logger.info('UPnP: configuring...');
const api = new UpnpApi(localPort, remotePort, logger)
const api = new UpnpApi(localPort, remotePort, logger, conf)
try {
await api.openPort()
} catch (e) {
......@@ -32,19 +34,21 @@ export class UpnpApi {
constructor(
private localPort:number,
private remotePort:number,
private logger:any
private logger:any,
private conf:ConfDTO
) {}
openPort() {
"use strict";
return Q.Promise((resolve:any, reject:any) => {
const suffix = this.conf.pair.pub.substr(0, 6)
this.logger.trace('UPnP: mapping external port %s to local %s...', this.remotePort, this.localPort);
const client = upnp.createClient();
client.portMapping({
'public': this.remotePort,
'private': this.localPort,
'ttl': BMAConstants.UPNP_TTL,
'description': 'duniter:bma:upnp'
'description': 'duniter:bma:' + suffix
}, (err:any) => {
client.close();
if (err) {
......
......@@ -759,7 +759,7 @@ class P2PDownloader {
// Continue
return chosens;
}, []);
let candidates = await Promise.all(promises)
let candidates:any[] = await Promise.all(promises)
candidates.forEach((c:any) => {
c.tta = c.tta || 0; // By default we say a node is super slow to answer
c.ttas = c.ttas || []; // Memorize the answer delays
......
"use strict";
import { WS2PConstants } from './lib/constants';
import {WS2PConstants} from './lib/constants';
import {ConfDTO, WS2PConfDTO} from "../../lib/dto/ConfDTO"
import {Server} from "../../../server"
import * as stream from 'stream';
import {WS2PCluster} from "./lib/WS2PCluster"
import {WS2PUpnp} from "./lib/ws2p-upnp"
import {CommonConstants} from "../../lib/common-libs/constants"
const constants = require("../../lib/constants");
const nuuid = require('node-uuid')
......@@ -109,7 +110,7 @@ export const WS2PDependency = {
},
service: {
input: (server:Server, conf:WS2PConfDTO, logger:any) => {
input: (server:Server, conf:ConfDTO, logger:any) => {
const api = new WS2PAPI(server, conf, logger)
server.ws2pCluster = api.getCluster()
server.addEndpointsDefinitions(async () => api.getEndpoint())
......@@ -176,7 +177,7 @@ export class WS2PAPI extends stream.Transform {
constructor(
private server:Server,
private conf:WS2PConfDTO,
private conf:ConfDTO,
private logger:any) {
super({ objectMode: true })
this.cluster = WS2PCluster.plugOn(server)
......@@ -212,7 +213,7 @@ export class WS2PAPI extends stream.Transform {
this.upnpAPI.stopRegular();
}
try {
this.upnpAPI = new WS2PUpnp(this.logger)
this.upnpAPI = new WS2PUpnp(this.logger, this.conf)
const { host, port, available } = await this.upnpAPI.startRegular()
if (available) {
// Defaults UPnP to true if not defined and available
......
import {WS2PConstants} from "./constants"
const upnp = require('nnupnp');
import {ConfDTO} from "../../../lib/dto/ConfDTO"
const upnp = require('nat-upnp');
export interface UPnPBinding {
remotehost:string
......@@ -13,9 +15,7 @@ export class WS2PUpnp {
private interval:NodeJS.Timer|null
private client = upnp.createClient()
constructor(
private logger:any
) {}
constructor(private logger:any, private conf:ConfDTO) {}
async checkUPnPisAvailable() {
try {
......@@ -38,6 +38,12 @@ export class WS2PUpnp {
return this.currentConfig
}
getUpnpDescription() {
const uuid = (this.conf.ws2p && this.conf.ws2p.uuid) || "no-uuid-yet"
const suffix = this.conf.pair.pub.substr(0, 6) + ":" + uuid
return 'duniter:ws2p:' + suffix
}
/**
* Always open the same port during an execution of Duniter.
* @returns { host:string, port:number }
......@@ -45,7 +51,7 @@ export class WS2PUpnp {
openPort() {
return new Promise<{ host:string, port:number }>(async (resolve:any, reject:any) => {
if (!this.currentConfig) {
this.currentConfig = await WS2PUpnp.getAvailablePort(this.client)
this.currentConfig = await this.getAvailablePort(this.client)
}
this.logger.trace('WS2P: mapping external port %s to local %s using UPnP...', this.currentConfig.port, [this.currentConfig.host, this.currentConfig.port].join(':'))
const client = upnp.createClient()
......@@ -53,7 +59,7 @@ export class WS2PUpnp {
'public': this.currentConfig.port,
'private': this.currentConfig.port,
'ttl': WS2PConstants.WS2P_UPNP_TTL,
'description': 'duniter:ws2p:upnp'
'description': this.getUpnpDescription()
}, (err:any) => {
client.close()
if (err) {
......@@ -101,7 +107,7 @@ export class WS2PUpnp {
})
}
static async getAvailablePort(client:any) {
private async getAvailablePort(client:any) {
const localIP = await WS2PUpnp.getLocalIP(client)
const remoteIP = await WS2PUpnp.getRemoteIP(client)
const mappings:{
......@@ -111,10 +117,10 @@ export class WS2PUpnp {
public: {
port:number
}
description:string
}[] = await WS2PUpnp.getUPnPMappings(client)
const externalPortsUsed = mappings.map((m) => {
return m.public.port
})
const thisDesc = this.getUpnpDescription()
const externalPortsUsed = mappings.filter((m) => m.description !== thisDesc).map((m) => m.public.port)
let availablePort = WS2PConstants.WS2P_PORTS_START
while (externalPortsUsed.indexOf(availablePort) !== -1
&& availablePort <= WS2PConstants.WS2P_PORTS_END) {
......
......@@ -35,8 +35,8 @@ duniter() {
VERSION=`$NODE -v`
if [[ $VERSION != v8* ]]; then
echo "$NODE v8 is required";
if [[ $VERSION != v8* ]] && [[ $VERSION != v9* ]]; then
echo "$NODE v8 or v9 is required";
else
# Calls duniter JS command
......
......@@ -2,7 +2,7 @@
"name": "duniter",
"version": "1.6.17",
"engines": {
"node": ">=8.2.1 <9",
"node": ">=8.2.1 <10",
"npm": ">=3.10"
},
"engineStrict": true,
......@@ -79,8 +79,8 @@
"moment": "2.19.3",
"morgan": "1.8.1",
"multimeter": "0.1.1",
"naclb": "1.3.9",
"nnupnp": "1.0.2",
"naclb": "1.3.10",
"nat-upnp": "^1.1.1",
"node-pre-gyp": "0.6.34",
"node-uuid": "1.4.8",
"optimist": "0.6.1",
......@@ -88,18 +88,18 @@
"querablep": "^0.1.0",
"request": "2.81.0",
"request-promise": "4.2.0",
"scryptb": "6.0.4",
"scryptb": "6.0.5",
"seedrandom": "^2.4.3",
"sha1": "1.1.1",
"socks-proxy-agent": "^3.0.1",
"sqlite3": "3.1.4",
"sqlite3": "3.1.13",
"tail": "^1.2.1",
"tweetnacl": "0.14.3",
"underscore": "1.8.3",
"unzip": "0.1.11",
"unzip2": "0.2.5",
"winston": "2.3.1",
"wotb": "0.6.x",
"wotb": "^0.6.4",
"ws": "1.1.5"
},
"devDependencies": {
......
......@@ -6,7 +6,7 @@ export NVM_DIR="$HOME/.nvm"
# Prepare
NODE_VERSION=8.9.1
NODE_VERSION=9.4.0
ARCH="`uname -m | sed -e \"s/86_//\"`"
NVER="v$NODE_VERSION"
DUNITER_TAG=$1
......
{
'variables': {
'asan%': 0,
'werror': '', # Turn off -Werror in V8 build.
'visibility%': 'hidden', # V8's visibility setting
'target_arch%': 'ia32', # set v8's target architecture
'host_arch%': 'ia32', # set v8's host architecture
'want_separate_host_toolset%': 0, # V8 should not build target and host
'library%': 'static_library', # allow override to 'shared_library' for DLL/.so builds
'component%': 'static_library', # NB. these names match with what V8 expects
'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way
'python%': 'python',
'node_shared%': 'true',
'force_dynamic_crt%': 0,
'node_use_v8_platform%': 'true',
'node_use_bundled_v8%': 'true',
'node_module_version%': '',
'mac_product_name': 'nwjs',
'node_tag%': '',
'uv_library%': 'static_library',
'openssl_fips': '',
# Default to -O0 for debug builds.
'v8_optimized_debug%': 0,
# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
'v8_host_byteorder': '<!(python -c "import sys; print sys.byteorder")',
'v8_use_external_startup_data': 1,
'v8_enable_i18n_support%': 1,
#'icu_use_data_file_flag%': 1,
'win_fastlink': 0,
# Don't use ICU data file (icudtl.dat) from V8, we use our own.
'icu_use_data_file_flag%': 0,
'conditions': [
['OS == "win"', {
'os_posix': 0,
'v8_postmortem_support%': 'false',
'OBJ_DIR': '<(PRODUCT_DIR)/obj',
'V8_BASE': '<(PRODUCT_DIR)/lib/v8_libbase.lib',
}, {
'os_posix': 1,
'v8_postmortem_support%': 'true',
'clang_dir': '<!(cd <(DEPTH) && pwd -P)/third_party/llvm-build/Release+Asserts',
}],
['OS=="linux" and target_arch=="ia32"', {
'sysroot': '<!(cd <(DEPTH) && pwd -P)/build/linux/debian_jessie_i386-sysroot',
}],
['OS=="linux" and target_arch=="x64"', {
'sysroot': '<!(cd <(DEPTH) && pwd -P)/build/linux/debian_jessie_amd64-sysroot',
}],
['OS== "mac"', {
'conditions': [
['GENERATOR=="ninja"', {
'OBJ_DIR': '<(PRODUCT_DIR)/obj',
'V8_BASE': '<(PRODUCT_DIR)/obj/deps/v8/src/libv8_base.a',
}, {
'OBJ_DIR%': '<(PRODUCT_DIR)/obj.target',
'V8_BASE%': '<(PRODUCT_DIR)/obj.target/deps/v8/src/libv8_base.a',
}],
],
}],
['openssl_fips != ""', {
'OPENSSL_PRODUCT': 'libcrypto.a',
}, {
'OPENSSL_PRODUCT': 'libopenssl.a',
}],
['OS=="mac"', {
'clang%': 1,
}, {
'clang%': 0,
}],
],
},
'conditions': [
[ 'clang==1 and OS != "mac"', {
'make_global_settings': [
['CC', '<(clang_dir)/bin/clang'],
['CXX', '<(clang_dir)/bin/clang++'],
['CC.host', '$(CC)'],
['CXX.host', '$(CXX)'],
],
}],
],
'target_defaults': {
'default_configuration': 'Release',
'variables': {
'conditions': [
['OS=="win" and component=="shared_library"', {
# See http://msdn.microsoft.com/en-us/library/aa652367.aspx
'win_release_RuntimeLibrary%': '2', # 2 = /MD (nondebug DLL)
'win_debug_RuntimeLibrary%': '3', # 3 = /MDd (debug DLL)
}, {
# See http://msdn.microsoft.com/en-us/library/aa652367.aspx
'win_release_RuntimeLibrary%': '0', # 0 = /MT (nondebug static)
'win_debug_RuntimeLibrary%': '1', # 1 = /MTd (debug static)
}],
],
},
'configurations': {
'Common_Base': {
'abstract': 1,
'msvs_settings':{
'VCCLCompilerTool': {
'AdditionalOptions': [
'/bigobj',
# Tell the compiler to crash on failures. This is undocumented
# and unsupported but very handy.
'/d2FastFail',
],
},
'VCLinkerTool': {
# Add the default import libs.
'AdditionalDependencies': [
'kernel32.lib',
'gdi32.lib',
'winspool.lib',
'comdlg32.lib',
'advapi32.lib',
'shell32.lib',
'ole32.lib',
'oleaut32.lib',
'user32.lib',
'uuid.lib',
'odbc32.lib',
'odbccp32.lib',
'delayimp.lib',
'credui.lib',
'dbghelp.lib',
'shlwapi.lib',
'winmm.lib',
],
'AdditionalOptions': [
# Suggested by Microsoft Devrel to avoid
# LINK : fatal error LNK1248: image size (80000000) exceeds maximum allowable size (80000000)
# which started happening more regularly after VS2013 Update 4.
# Needs to be a bit lower for VS2015, or else errors out.
'/maxilksize:0x7ff00000',
# Tell the linker to crash on failures.
'/fastfail',
],
},
},
'conditions': [
['OS=="win" and win_fastlink==1 and MSVS_VERSION != "2013"', {
'msvs_settings': {
'VCLinkerTool': {
# /PROFILE is incompatible with /debug:fastlink
'Profile': 'false',
'AdditionalOptions': [
# Tell VS 2015+ to create a PDB that references debug
# information in .obj and .lib files instead of copying
# it all.
'/DEBUG:FASTLINK',
],
},
},
}],
['OS=="win" and MSVS_VERSION == "2015"', {
'msvs_settings': {
'VCCLCompilerTool': {
'AdditionalOptions': [
# Work around crbug.com/526851, bug in VS 2015 RTM compiler.
'/Zc:sizedDealloc-',
# Disable thread-safe statics to avoid overhead and because
# they are disabled on other platforms. See crbug.com/587210
# and -fno-threadsafe-statics.
'/Zc:threadSafeInit-',
],
},
},
}],
],
},
'Debug_Base': {
'abstract': 1,
'variables': {
'v8_enable_handle_zapping': 1,
},
'defines': [ 'DEBUG', '_DEBUG', 'V8_ENABLE_CHECKS' ],
'cflags': [ '-g', '-O0' ],
'conditions': [
['target_arch=="x64"', {
'msvs_configuration_platform': 'x64',
}],
['OS=="aix"', {
'cflags': [ '-gxcoff' ],
'ldflags': [ '-Wl,-bbigtoc' ],
}],
['OS == "android"', {
'cflags': [ '-fPIE' ],
'ldflags': [ '-fPIE', '-pie' ]
}],
],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary': '<(win_debug_RuntimeLibrary)', # static debug
'Optimization': 0, # /Od, no optimization
'MinimalRebuild': 'false',
'OmitFramePointers': 'false',
'BasicRuntimeChecks': 3, # /RTC1
},
'VCLinkerTool': {
'LinkIncremental': 2, # enable incremental linking
},
},
'xcode_settings': {
'GCC_OPTIMIZATION_LEVEL': '0', # stop gyp from defaulting to -Os
},
},
'Release_Base': {
'abstract': 1,
'variables': {
'v8_enable_handle_zapping': 0,
},
'cflags': [ '-O3' ],
'conditions': [
['target_arch=="x64"', {
'msvs_configuration_platform': 'x64',
}],
['OS=="solaris"', {
# pull in V8's postmortem metadata
'ldflags': [ '-Wl,-z,allextract' ]
}],
['OS!="mac" and OS!="win"', {
'cflags': [ '-fno-omit-frame-pointer' ],
}],
['OS == "android"', {
'cflags': [ '-fPIE' ],
'ldflags': [ '-fPIE', '-pie' ]
}],
],
'msvs_settings': {
'VCCLCompilerTool': {
'RuntimeLibrary': '<(win_release_RuntimeLibrary)', # static release
'Optimization': 3, # /Ox, full optimization
'FavorSizeOrSpeed': 1, # /Ot, favour speed over size
'InlineFunctionExpansion': 2, # /Ob2, inline anything eligible
'WholeProgramOptimization': 'true', # /GL, whole program optimization, needed for LTCG
'OmitFramePointers': 'true',
'EnableFunctionLevelLinking': 'true',
'EnableIntrinsicFunctions': 'true',
'RuntimeTypeInfo': 'false',
'AdditionalOptions': [
'/MP', # compile across multiple CPUs
],
},
'VCLibrarianTool': {
'AdditionalOptions': [
'/LTCG', # link time code generation
],
},
'VCLinkerTool': {
'LinkTimeCodeGeneration': 1, # link-time code generation
'OptimizeReferences': 2, # /OPT:REF
'EnableCOMDATFolding': 2, # /OPT:ICF
'LinkIncremental': 1, # disable incremental linking
},
},
},
'Debug': {
'inherit_from': ['Common_Base', 'Debug_Base'],
},
'Release': {
'inherit_from': ['Common_Base', 'Release_Base'],
},
'conditions': [
[ 'OS=="win"', {
'Debug_x64': { 'inherit_from': ['Debug'] },
'Release_x64': { 'inherit_from': ['Release'], },
}],
],
},
# Forcibly disable -Werror. We support a wide range of compilers, it's
# simply not feasible to squelch all warnings, never mind that the
# libraries in deps/ are not under our control.
'cflags!': ['-Werror'],
'msvs_settings': {
'VCCLCompilerTool': {
'StringPooling': 'true', # pool string literals
'DebugInformationFormat': 3, # Generate a PDB
'WarningLevel': 3,
'BufferSecurityCheck': 'true',
'ExceptionHandling': 0, # /EHsc
'SuppressStartupBanner': 'true',
# Disable "warning C4267: conversion from 'size_t' to 'int',
# possible loss of data". Many originate from our dependencies
# and their sheer number drowns out other, more legitimate warnings.
'DisableSpecificWarnings': ['4267'],
'WarnAsError': 'false',
},
'VCLibrarianTool': {
},
'VCLinkerTool': {
'conditions': [
['target_arch=="ia32"', {
'TargetMachine' : 1, # /MACHINE:X86
'target_conditions': [
['_type=="executable"', {
'AdditionalOptions': [ '/SubSystem:Console,"5.01"' ],
}],
],
}],
['target_arch=="x64"', {
'TargetMachine' : 17, # /MACHINE:AMD64
'target_conditions': [
['_type=="executable"', {
'AdditionalOptions': [ '/SubSystem:Console,"5.02"' ],
}],
],
}],
],
'GenerateDebugInformation': 'true',
'GenerateMapFile': 'true', # /MAP
'MapExports': 'true', # /MAPINFO:EXPORTS
'RandomizedBaseAddress': 2, # enable ASLR
'DataExecutionPrevention': 2, # enable DEP
'AllowIsolation': 'true',
'SuppressStartupBanner': 'true',
},
},
'msvs_disabled_warnings': [4351, 4355, 4800, 4595],
'conditions': [
['asan == 1 and OS != "mac"', {
'cflags+': [
'-fno-omit-frame-pointer',
'-fsanitize=address',
'-DLEAK_SANITIZER'
],
'cflags!': [ '-fomit-frame-pointer' ],
'ldflags': [ '-fsanitize=address' ],
}],
['asan == 1 and OS == "mac"', {
'xcode_settings': {
'OTHER_CFLAGS+': [
'-fno-omit-frame-pointer',
'-gline-tables-only',
'-fsanitize=address',
'-DLEAK_SANITIZER'
],
'OTHER_CFLAGS!': [
'-fomit-frame-pointer',