<commit_before>var mongoose = require('mongoose');
var async    = require('async');
var sha1     = require('sha1');
var jpgp     = require('../lib/jpgp');
var _        = require('underscore');
var Schema   = mongoose.Schema;

var PeerSchema = new Schema({
  version: String,
  currency: String,
  fingerprint: String,
  dns: String,
  ipv4: String,
  ipv6: String,
  port: { type: Number, default: 8081 },
  signature: String,
  hash: String,
  status: String,
  created: { type: Date, default: Date.now },
  updated: { type: Date, default: Date.now }
});

PeerSchema.methods = {
  
  copyValues: function(to) {
    var obj = this;
    ["version", "currency", "fingerprint", "dns", "ipv4", "ipv6", "port", "hash", "status"].forEach(function (key) {
      to[key] = obj[key];
    });
  },
  
  json: function() {
    var obj = this;
    var json = {};
    ["version", "currency", "fingerprint", "dns", "ipv4", "ipv6", "port", "status", "signature"].forEach(function (key) {
      json[key] = obj[key];
    });
    return json;
  },
  
  parse: function(rawPeeringReq, callback) {
    var rawPR = rawPeeringReq;
    var sigIndex = rawPeeringReq.lastIndexOf("-----BEGIN");
    if(~sigIndex){
      this.signature = rawPeeringReq.substring(sigIndex);
      rawPR = rawPeeringReq.substring(0, sigIndex);
    }
    if(!rawPR){
      callback("No peering request given");
      return false;
    }
    else{
      var obj = this;
      var captures = [
        {prop: "version",           regexp: /Version: (.*)/},
        {prop: "currency",          regexp: /Currency: (.*)/},
        {prop: "fingerprint",       regexp: /Fingerprint: (.*)/},
        {prop: "dns",               regexp: /Dns: (.*)/},<commit_msg>Fix: replace signature when updating peer<commit_after>var mongoose = require('mongoose');
var async    = require('async');
var sha1     = require('sha1');
var jpgp     = require('../lib/jpgp');
var _        = require('underscore');
var Schema   = mongoose.Schema;

var PeerSchema = new Schema({
  version: String,
  currency: String,
  fingerprint: String,
  dns: String,
  ipv4: String,
  ipv6: String,
  port: { type: Number, default: 8081 },
  signature: String,
  hash: String,
  status: String,
  created: { type: Date, default: Date.now },
  updated: { type: Date, default: Date.now }
});

PeerSchema.methods = {
  
  copyValues: function(to) {
    var obj = this;
    ["version", "currency", "fingerprint", "dns", "ipv4", "ipv6", "port", "hash", "status", "signature"].forEach(function (key) {
      to[key] = obj[key];
    });
  },
  
  json: function() {
    var obj = this;
    var json = {};
    ["version", "currency", "fingerprint", "dns", "ipv4", "ipv6", "port", "status", "signature"].forEach(function (key) {
      json[key] = obj[key];
    });
    return json;
  },
  
  parse: function(rawPeeringReq, callback) {
    var rawPR = rawPeeringReq;
    var sigIndex = rawPeeringReq.lastIndexOf("-----BEGIN");
    if(~sigIndex){
      this.signature = rawPeeringReq.substring(sigIndex);
      rawPR = rawPeeringReq.substring(0, sigIndex);
    }
    if(!rawPR){
      callback("No peering request given");
      return false;
    }
    else{
      var obj = this;
      var captures = [
        {prop: "version",           regexp: /Version: (.*)/},
        {prop: "currency",          regexp: /Currency: (.*)/},
        {prop: "fingerprint",       regexp: /Fingerprint: (.*)/},
        {prop: "dns",               regexp: /Dns: (.*)/},
{'fraction_non_alphanumeric': 0.17839559803069793, 'fraction_numerical': 0.007529684332464524, 'mean_word_length': 2.7584330794341674, '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': '5478926', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1159, 'n_words': 280}