<commit_before>const util = require('util');
const Promise = require('bluebird');
const redis = require("redis");

const log = require("../../net2/logger")('intel');
const bone = require('../../lib/Bone');
const flowUtil = require('../../net2/FlowUtil.js');

const rclient = redis.createClient();
Promise.promisifyAll(redis.RedisClient.prototype);

class Intel {
  async jwt() {
    try {
      return await rclient.getAsync("sys:bone:jwt");
    } catch (err) {
      // null
    }
  }

  async check(dn) {
    try {
      return await this.checkIntelFromCloud(dn);
    } catch (err) {
      log.error("Error:", err, {});
    }
  }

  async checkIntelFromCloud(dn) {
    log.info("Checking intel for", dn);
    bone.setToken(await this.jwt());
    //log.debug(`JWT: ${bone.getToken()}`);

    let origHost = {};
    let debugMode = false;

    let hds = flowUtil.hashHost(dn, {keepOriginal: true});
    hds.forEach(hd => origHost[hd[2]] = hd[0]);

    let _hlist = hds.map(x => x.slice(1, 3));
    let _alist = flowUtil.hashApp(dn);

    //log.debug('Mapping: ' + util.inspect(origHost));

    let alist = [dn], hlist = [dn], iplist = [dn];
    let _iplist = _hlist;
    let flow = {fd: 'in'};

    let flowlist = debugMode ?
      [{iplist, hlist, alist, _iplist, _hlist, _alist, flow}] :
      [{_iplist, _hlist, _alist, flow}];

    let data = {flowlist, hashed: 1};

    //log.info(util.inspect(data, {depth: null}));
<commit_msg>switching to linux for dev<commit_after>const util = require('util');
const Promise = require('bluebird');
const Redis = require("Redis");

const log = require("../../net2/logger")('intel');
const bone = require('../../lib/Bone');
const flowUtil = require('../../net2/FlowUtil.js');

const redis = Redis.createClient();
Promise.promisifyAll(Redis.RedisClient.prototype);

class Intel {
  
  constructor(types) {
    this.types = types;
  }
  
  async jwt() {
    try {
      return await redis.getAsync("sys:bone:jwt");
    } catch (err) {
      // null
    }
  }

  async check(dn) {
    try {
      return await this.checkIntelFromCloud(dn);
    } catch (err) {
      log.error("Error:", err, {});
    }
  }
  
  async checkIntelLocally(dn) {
    let jobs = types.map(async type => {
      let key = `dns:hashset:${type}`;

      let hds = flowUtil.hashHost(dn);
      
      let jobs = hds.map(async hd => ({type, isMember: await redis.sismemberAsync(key, hd)}));

      return await Promise.all(jobs);
    });
    
    let result = await Promise.all(jobs);
    
  }

  async checkIntelFromCloud(dn) {
    log.info("Checking intel for", dn);
    bone.setToken(await this.jwt());
    //log.debug(`JWT: ${bone.getToken()}`);

    let origHost = {};
    let debugMode = false;

    let hds = flowUtil.hashHost(dn, {keepOriginal: true});
    hds.forEach(hd => origHost[hd[2]] = hd[0]);

    let _hlist = hds.map(x => x.slice(1, 3));
    let _alist = flowUtil.hashApp(dn);

    //log.debug('Mapping: ' + util.inspect(origHost));

    let alist = [dn], hlist = [dn], iplist = [dn];
    let _iplist = _hlist;
    let flow = {fd: 'in'};

    let flowlist = debugMode ?
      [{iplist, hlist, alist, _iplist, _hlist, _alist, flow}] :
      [{_iplist, _hlist, _alist, flow}];

    let data = {flowlist, hashed: 1};

    //log.info(util.inspect(data, {depth: null}));

{'fraction_non_alphanumeric': 0.18336369156041288, 'fraction_numerical': 0.004250151791135397, 'mean_word_length': 2.9272943980929678, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6684588', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1184, 'n_words': 259}