Skip to content
Snippets Groups Projects
Select Git revision
  • 024fd7fbdfcc3e0695a225c93f9846b056611819
  • dev default protected
  • release/1.9.1 protected
  • pini-1.8-docker
  • pini-sync-onlypeers
  • duniter-v2s-issue-123-industrialize-releases
  • feature/build-aarch64-nodejs16
  • release/1.8 protected
  • pini-docker
  • ci_tags
  • fix/1448/1.8/txs_not_stored
  • feature/node-20
  • fix/1441/node_summary_with_storage
  • fix/1442/improve_bma_tx_history
  • feature/wotwizard-1.8
  • release/1.9 protected
  • 1.7 protected
  • feature/docker-set-latest protected
  • feature/fast-docker-build-1.8.4
  • fast-docker-build protected
  • feature/dump-distance
  • v1.8.7 protected
  • v1.8.7-rc4 protected
  • v1.8.7-rc3 protected
  • v1.8.7-rc2 protected
  • v1.8.7-rc1 protected
  • v1.8.6 protected
  • v1.7.23 protected
  • v1.8.5 protected
  • v1.8.4 protected
  • v1.8.3 protected
  • v1.8.2 protected
  • v1.8.1 protected
  • v1.8.0 protected
  • v1.8.0-rc1 protected
  • v1.8.0-beta5 protected
  • v1.8.0-beta4 protected
  • v1.8.0-beta3 protected
  • v1.8.0-beta2 protected
  • v1.8.0-beta protected
  • v1.7.21 protected
41 results

server.js

Blame
  • 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);