<commit_before>var _ = require('lodash');

var TOKEN = '__smocks_id';

var STATES = {};

var initialized = false;

function StateManager(options) {
  options = options || {};
  this.timeout = options.timeout || 8 * 60 * 60 * 1000;
  this.maxSessions = options.maxSessions || 30;
}
_.extend(StateManager.prototype, {
  isInitialized: function(request) {
    var sessionId = request.state[TOKEN];

    var initialized = sessionId && !!STATES[sessionId];
    if (_.isArray(initialized)) {
      initialized = undefined;
    }
    if (!initialized) {
      var newStateId = _.uniqueId('_smocks_state_');
      request._smocksInitialized = newStateId;
    }
    return initialized;
  },

  onResponse: function(request, reply) {
    var newStateId = request._smocksInitialized;
    if (newStateId) {
      reply.state(TOKEN, newStateId, { encoding: 'none', clearInvalid: true, path: '/' });
    }<commit_msg>add server id for session state vefication purposes<commit_after>var _ = require('lodash');

var TOKEN = '__smocks_id';
var MACHINE_ID = Math.floor(Math.random() * 1000000) + '';

var STATES = {};

var initialized = false;

function StateManager(options) {
  options = options || {};
  this.timeout = options.timeout || 8 * 60 * 60 * 1000;
  this.maxSessions = options.maxSessions || 30;
}
_.extend(StateManager.prototype, {
  isInitialized: function(request) {
    var sessionId = request.state[TOKEN];

    var initialized = sessionId && !!STATES[sessionId];
    if (_.isArray(initialized)) {
      initialized = undefined;
    }
    if (!initialized) {
      var newStateId = _.uniqueId('_smocks_state_');
      request._smocksInitialized = newStateId;
    }
    return initialized;
  },

  onResponse: function(request, reply) {
    var newStateId = request._smocksInitialized;
    if (newStateId) {
      reply.state(TOKEN, newStateId, { encoding: 'none', clearInvalid: true, path: '/' });
      reply.state('__smocks_container_id', MACHINE_ID, { encoding: 'none', clearInvalid: true, path: '/' });
    }
{'fraction_non_alphanumeric': 0.13817097415506957, 'fraction_numerical': 0.01441351888667992, 'mean_word_length': 3.7701421800947865, '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': '6405664', 'n_tokens_mistral': 652, 'n_tokens_neox': 629, 'n_words': 140}