<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 redis = Redis.createClient();
Promise.promisifyAll(Redis.RedisClient.prototype);

class Intel {
  constructor(types) {
    (async () => {
      this.types = await Promise.map(await redis.keysAsync('dns:hashset:*'), key => key.split(':')[2]);
    })();
  }
  
  async jwt() {
    try {
      return await redis.getAsync("sys:bone:jwt");
    } catch (err) {
      // null
    }
  }

  async check(dn) {
    try {
      let result = await this.checkIntelLocally(dn);
      log.info('local intel result:', util.inspect(result, {colors: true, depth: null}));

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

  async checkIntelLocally(dn) {
    const hashedDomains = flowUtil.hashHost(dn, {keepOriginal: true});
    log.info("hds:\n", util.inspect(hashedDomains, {colors: true}));

    return Promise.map(this.types, async type => {
      const key = `dns:hashset:${type}`;

      // hashedDomain[0]: domain name, [1]: short hash, [2]: full hash
      let results = await Promise.map(hashedDomains, async hashedDomain => ({
        dn: hashedDomain[0],
        isMember: await redis.sismemberAsync(key, hashedDomain[2])
      }));

      let result = results.reduce((acc, cur) => acc || cur.isMember);
      return {[type]: result};
    });
  };

  async checkIntelFromCloud(dn) {
    log.info("Checking intel for", dn);
    bone.setToken(await this.jwt());
    //log.debug(`JWT: ${bone.getToken()}`);
<commit_msg>format local intel result<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) {
    (async () => {
      this.types = await Promise.map(await redis.keysAsync('dns:hashset:*'), key => key.split(':')[2]);
    })();
  }
  
  async jwt() {
    try {
      return await redis.getAsync("sys:bone:jwt");
    } catch (err) {
      // null
    }
  }

  async check(dn) {
    try {
      let result = await this.checkIntelLocally(dn);
      log.info('local intel result:', util.inspect(result, {colors: true, depth: null}));

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

  async checkIntelLocally(dn) {
    const hashedDomains = flowUtil.hashHost(dn, {keepOriginal: true});
    log.info("hds:\n", util.inspect(hashedDomains, {colors: true}));

    return (await Promise.map(this.types, async type => {
      const key = `dns:hashset:${type}`;

      // hashedDomain[0]: domain name, [1]: short hash, [2]: full hash
      let results = await Promise.map(hashedDomains, async hashedDomain => ({
        dn: hashedDomain[0],
        isMember: await redis.sismemberAsync(key, hashedDomain[2])
      }));

      let result = results.reduce((acc, cur) => acc || cur.isMember, false);

      return {type, member: result.isMember};
    })).reduce((acc, cur) => Object.assign(acc, {[cur.type]: [cur.member]}), {});
  };

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

{'fraction_non_alphanumeric': 0.18538076709282936, 'fraction_numerical': 0.0044469149527515284, 'mean_word_length': 3.289630512514899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '7115635', 'n_tokens_mistral': 1213, 'n_tokens_neox': 1206, 'n_words': 253}