Select Git revision
-
cgeek test account authoredcgeek test account authored
server.js 18.46 KiB
"use strict";
const stream = require('stream');
const async = require('async');
const util = require('util');
const path = require('path');
const co = require('co');
const _ = require('underscore');
const Q = require('q');
const archiver = require('archiver');
const unzip = require('unzip2');
const fs = require('fs');
const parsers = require('./app/lib/streams/parsers');
const constants = require('./app/lib/constants');
const fileDAL = require('./app/lib/dal/fileDAL');
const jsonpckg = require('./package.json');
const router = require('./app/lib/streams/router');
const base58 = require('./app/lib/crypto/base58');
const keyring = require('./app/lib/crypto/keyring');
const directory = require('./app/lib/system/directory');
const dos2unix = require('./app/lib/system/dos2unix');
const Synchroniser = require('./app/lib/sync');
const multicaster = require('./app/lib/streams/multicaster');
const upnp = require('./app/lib/system/upnp');
const bma = require('./app/lib/streams/bma');
const rawer = require('./app/lib/ucp/rawer');
function Server (dbConf, overrideConf) {
stream.Duplex.call(this, { objectMode: true });
const home = directory.getHome(dbConf.name, dbConf.home);
const paramsP = directory.getHomeParams(dbConf && dbConf.memory, home);
const logger = require('./app/lib/logger')('server');
const that = this;
that.home = home;
that.conf = null;
that.dal = null;
that.version = jsonpckg.version;
that.MerkleService = require("./app/lib/helpers/merkle");
that.ParametersService = require("./app/lib/helpers/parameters")();
that.IdentityService = require('./app/service/IdentityService')();
that.MembershipService = require('./app/service/MembershipService')();
that.PeeringService = require('./app/service/PeeringService')(that);
that.BlockchainService = require('./app/service/BlockchainService')(that);
that.TransactionsService = require('./app/service/TransactionsService')();
// Create document mapping
const documentsMapping = {
'identity': { action: that.IdentityService.submitIdentity, parser: parsers.parseIdentity },
'certification': { action: that.IdentityService.submitCertification, parser: parsers.parseCertification},
'revocation': { action: that.IdentityService.submitRevocation, parser: parsers.parseRevocation },
'membership': { action: that.MembershipService.submitMembership, parser: parsers.parseMembership },
'peer': { action: that.PeeringService.submitP, parser: parsers.parsePeer },
'transaction': { action: that.TransactionsService.processTx, parser: parsers.parseTransaction },
'block': { action: _.partial(that.BlockchainService.submitBlock, _, true, constants.NO_FORK_ALLOWED), parser: parsers.parseBlock }
};
// Unused, but made mandatory by Duplex interface
this._read = () => null;
this._write = (obj, enc, writeDone) => that.submit(obj, false, () => writeDone);
/**
* Facade method to control what is pushed to the stream (we don't want it to be closed)
* @param obj An object to be pushed to the stream.
*/
this.streamPush = (obj) => {
if (obj) {
that.push(obj);