<commit_before>var jpgp             = require('../lib/jpgp');
var async            = require('async');
var vucoin           = require('vucoin');
var _                = require('underscore');
var es               = require('event-stream');
var unix2dos         = require('../lib/unix2dos');
var versionFilter    = require('../lib/streams/versionFilter');
var currencyFilter   = require('../lib/streams/currencyFilter');
var http2raw         = require('../lib/streams/parsers/http2raw');
var jsoner           = require('../lib/streams/jsoner');
var http400          = require('../lib/http/http400');
var parsers          = require('../lib/streams/parsers/doc');
var link2pubkey      = require('../lib/streams/link2pubkey');
var extractSignature = require('../lib/streams/extractSignature');
var verifySignature  = require('../lib/streams/verifySignature');
var logger           = require('../lib/logger')();
var mlogger          = require('../lib/logger')('membership');

module.exports = function (wotServer) {
  return new KeychainBinding(wotServer);
}

function KeychainBinding (wotServer) {

  var that = this;
  var conf = wotServer.conf;

  // Services
  var http              = wotServer.HTTPService;
  var MerkleService     = wotServer.MerkleService;
  var ParametersService = wotServer.ParametersService;
  var PeeringService    = wotServer.PeeringService;
  var SyncService       = wotServer.SyncService;
  var ContractService   = wotServer.ContractService;

  // Models
  var Peer       = wotServer.conn.model('Peer');
  var Forward    = wotServer.conn.model('Forward');
  var Membership = wotServer.conn.model('Membership');
  var PublicKey  = wotServer.conn.model('PublicKey');
  var Merkle     = wotServer.conn.model('Merkle');
  var Key        = wotServer.conn.model('Key');

  this.parseMembership = function (req, res) {
    var onError = http400(res);
    http2raw.membership(req, onError)
      .pipe(unix2dos())
      .pipe(parsers.parseMembership(onError))
      .pipe(versionFilter(onError))
      .pipe(currencyFilter(conf.currency, onError))
      .pipe(extractSignature(onError))
      .pipe(link2pubkey(wotServer.PublicKeyService, onError))
      .pipe(verifySignature(onError))
      .pipe(wotServer.singleWriteStream(onError))
      .pipe(jsoner())
      .pipe(es.stringify())
      .pipe(res);
  };

  this.parseKeyblock = function (req, res) {
    var onError = http400(res);
    http2raw.keyblock(req, onError)
      .pipe(unix2dos())
      .pipe(parsers.parseKeyblock(onError))
      .pipe(versionFilter(onError))
      .pipe(currencyFilter(conf.currency, onError))
      .pipe(extractSignature(onError))
      .pipe(link2pubkey(wotServer.PublicKeyService, onError))
      .pipe(verifySignature(onError))
      .pipe(wotServer.singleWriteStream(onError))
      .pipe(jsoner())
      .pipe(es.stringify())
      .pipe(res);
  }

  this.current = function (req, res) {
    res.end(503);
  }
}<commit_msg>HTTP API: send 501 HTTP code for non-implemented URIs<commit_after>var jpgp             = require('../lib/jpgp');
var async            = require('async');
var vucoin           = require('vucoin');
var _                = require('underscore');
var es               = require('event-stream');
var unix2dos         = require('../lib/unix2dos');
var versionFilter    = require('../lib/streams/versionFilter');
var currencyFilter   = require('../lib/streams/currencyFilter');
var http2raw         = require('../lib/streams/parsers/http2raw');
var jsoner           = require('../lib/streams/jsoner');
var http400          = require('../lib/http/http400');
var parsers          = require('../lib/streams/parsers/doc');
var link2pubkey      = require('../lib/streams/link2pubkey');
var extractSignature = require('../lib/streams/extractSignature');
var verifySignature  = require('../lib/streams/verifySignature');
var logger           = require('../lib/logger')();
var mlogger          = require('../lib/logger')('membership');

module.exports = function (wotServer) {
  return new KeychainBinding(wotServer);
}

function KeychainBinding (wotServer) {

  var that = this;
  var conf = wotServer.conf;

  // Services
  var http              = wotServer.HTTPService;
  var MerkleService     = wotServer.MerkleService;
  var ParametersService = wotServer.ParametersService;
  var PeeringService    = wotServer.PeeringService;
  var SyncService       = wotServer.SyncService;
  var ContractService   = wotServer.ContractService;

  // Models
  var Peer       = wotServer.conn.model('Peer');
  var Forward    = wotServer.conn.model('Forward');
  var Membership = wotServer.conn.model('Membership');
  var PublicKey  = wotServer.conn.model('PublicKey');
  var Merkle     = wotServer.conn.model('Merkle');
  var Key        = wotServer.conn.model('Key');

  this.parseMembership = function (req, res) {
    var onError = http400(res);
    http2raw.membership(req, onError)
      .pipe(unix2dos())
      .pipe(parsers.parseMembership(onError))
      .pipe(versionFilter(onError))
      .pipe(currencyFilter(conf.currency, onError))
      .pipe(extractSignature(onError))
      .pipe(link2pubkey(wotServer.PublicKeyService, onError))
      .pipe(verifySignature(onError))
      .pipe(wotServer.singleWriteStream(onError))
      .pipe(jsoner())
      .pipe(es.stringify())
      .pipe(res);
  };

  this.parseKeyblock = function (req, res) {
    var onError = http400(res);
    http2raw.keyblock(req, onError)
      .pipe(unix2dos())
      .pipe(parsers.parseKeyblock(onError))
      .pipe(versionFilter(onError))
      .pipe(currencyFilter(conf.currency, onError))
      .pipe(extractSignature(onError))
      .pipe(link2pubkey(wotServer.PublicKeyService, onError))
      .pipe(verifySignature(onError))
      .pipe(wotServer.singleWriteStream(onError))
      .pipe(jsoner())
      .pipe(es.stringify())
      .pipe(res);
  }

  this.current = function (req, res) {
    res.send(501, "Not implemented.");
    res.end();
  }
}
{'fraction_non_alphanumeric': 0.14545454545454545, 'fraction_numerical': 0.009595959595959595, 'mean_word_length': 3.0831615120274916, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6583081', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1848, 'n_words': 315}