server.ts 26.66 KiB
// Source file from duniter: Crypto-currency software to manage libre currency such as Ğ1
// Copyright (C) 2018 Cedric Moreau <cem.moreau@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
import {IdentityService} from "./app/service/IdentityService"
import {MembershipService} from "./app/service/MembershipService"
import {PeeringService} from "./app/service/PeeringService"
import {BlockchainService} from "./app/service/BlockchainService"
import {TransactionService} from "./app/service/TransactionsService"
import {ConfDTO} from "./app/lib/dto/ConfDTO"
import {FileDAL, FileDALParams} from "./app/lib/dal/fileDAL"
import * as stream from "stream"
import {Key, randomKey} from "./app/lib/common-libs/crypto/keyring"
import {parsers} from "./app/lib/common-libs/parsers/index"
import {Cloneable} from "./app/lib/dto/Cloneable"
import {CommonConstants, DuniterDocument, duniterDocument2str} from "./app/lib/common-libs/constants"
import {GlobalFifoPromise} from "./app/service/GlobalFifoPromise"
import {BlockchainContext} from "./app/lib/computation/BlockchainContext"
import {BlockDTO} from "./app/lib/dto/BlockDTO"
import {DBIdentity} from "./app/lib/dal/sqliteDAL/IdentityDAL"
import {CertificationDTO} from "./app/lib/dto/CertificationDTO"
import {MembershipDTO} from "./app/lib/dto/MembershipDTO"
import {RevocationDTO} from "./app/lib/dto/RevocationDTO"
import {TransactionDTO} from "./app/lib/dto/TransactionDTO"
import {PeerDTO} from "./app/lib/dto/PeerDTO"
import {OtherConstants} from "./app/lib/other_constants"
import {WS2PCluster} from "./app/modules/ws2p/lib/WS2PCluster"
import {DBBlock} from "./app/lib/db/DBBlock"
import {ProxiesConf} from './app/lib/proxy';
import {Directory, FileSystem} from "./app/lib/system/directory"
import {DataErrors} from "./app/lib/common-libs/errors"
import {DBPeer} from "./app/lib/db/DBPeer"
import {Underscore} from "./app/lib/common-libs/underscore"
import {SQLiteDriver} from "./app/lib/dal/drivers/SQLiteDriver"
import {LevelUp} from "levelup";
import {BMAConstants} from "./app/modules/bma/lib/constants"
import {HttpMilestonePage} from "./app/modules/bma/lib/dtos"
import * as toJson from "./app/modules/bma/lib/tojson"
export interface HookableServer {
generatorGetJoinData: (...args:any[]) => Promise<any>
generatorComputeNewCerts: (...args:any[]) => Promise<any>
generatorNewCertsToLinks: (...args:any[]) => Promise<any>
onPluggedFSHook: (...args:any[]) => Promise<any>
resetDataHook: (...args:any[]) => Promise<any>
resetConfigHook: (...args:any[]) => Promise<any>
}
const path = require('path');
const archiver = require('archiver');
const fs = require('fs');
const es = require('event-stream');
const extract = require('extract-zip')
const daemonize = require("daemonize2")
const constants = require('./app/lib/constants');
const jsonpckg = require('./package.json');
const logger = require('./app/lib/logger').NewLogger('server');
export class Server extends stream.Duplex implements HookableServer {
private paramsP:Promise<FileDALParams>