# Path: iolibrary.py
# def kill_signal_handler(signal, frame):
#     '''
#     Signal handler for killing the execution.
#     '''
#     print('\nExiting the program per your command.')
#     system('rm -f out.out request.txt iolibrary.pyc hillclimbing.pyc constants.pyc connect.pyc parse.pyc sniff.pyc')
#     if not path.exists('history'):
#         mkdir('history')
#     if path.exists('basic_breach.log'):
#         system('mv basic_breach.log history/')
#     if path.exists('full_breach.log'):
#         system('mv full_breach.log history/')
#     if path.exists('debug.log'):
#         system('mv debug.log history/')
#     if path.exists('attack.log'):
#         system('mv attack.log history/')
#     if path.exists('win_count.log'):
#         system('mv win_count.log history/')
#     if path.exists('sniff.log'):
#         system('mv sniff.log history/')
#     if path.exists('sniff_full.log'):
#         system('mv sniff_full.log history/')
#     sys.exit(0)
# 
# def get_arguments_dict(args_list):
#     '''
#     Parse command line arguments that were given to the program that calls this method.
#     '''
#     parser = argparse.ArgumentParser(description='Parser of breach.py output')
#     parser.add_argument('caller_name', metavar='caller_name', help='The program that called the argument parser.')
#     parser.add_argument('--execute_breach', action='store_true', help='Initiate breach attack via breach.py')
#     args = parser.parse_args(args_list)
# 
#     args_dict = {}
#     args_dict['execute_breach'] = True if args.execute_breach else False
#     return args_dict
# 
# def setup_logger(logger_name, log_file, args_dict, level=logging.DEBUG):
#     '''
#     Logger factory.
#     '''
#     l = logging.getLogger(logger_name)
#     l.setLevel(level)
#     formatter = logging.Formatter('%(asctime)s : %(message)s')
#     fileHandler = logging.FileHandler(log_file)
#     fileHandler.setFormatter(formatter)
#     l.addHandler(fileHandler)
#     if args_dict['log_to_screen']:
#         streamHandler = logging.StreamHandler()
#         streamHandler.setFormatter(formatter)
#         l.addHandler(streamHandler)


from os import system, path, getpid
from iolibrary import kill_signal_handler, get_arguments_dict, setup_logger
import sys
import signal
import datetime
import logging
import time
import threading
import constants
import connect
        import hillclimbing
    Class that parses the packet lengths that are sniffed through the network.
    '''
    def __init__(self, args_dict):
        '''
        Initialize constants and arguments.
        '''
        self.args_dict = args_dict
        assert args_dict['pivot_length'] or args_dict['minimum_request_length'], 'Invalid combination of minimum request and pivot lengths'
        self.alpha_types = args_dict['alpha_types']
        if 'alphabet' in args_dict:
            self.alphabet = args_dict['alphabet']
        self.pivot_length = args_dict['pivot_length']
        self.prefix = args_dict['prefix']
        self.latest_file = args_dict['latest_file']
        self.minimum_request_length = args_dict['minimum_request_length']
        self.method = args_dict['method']
        self.correct_val = args_dict['correct_val']
        self.sampling_ratio = args_dict['sampling_ratio']
        self.refresh_time = args_dict['refresh_time']
        self.start_time = args_dict['start_time']
        self.verbose = args_dict['verbose']
        self.max_iter = args_dict['iterations']
        self.wdir = args_dict['wdir']
        self.execute_breach = args_dict['execute_breach']
        self.divide_and_conquer = args_dict['divide_and_conquer'] if 'divide_and_conquer' in args_dict else 0
        self.history_folder = args_dict['history_folder']
        self.latest_file = 0
        self.point_system = constants.POINT_SYSTEM_MAPPING[args_dict['method']]
        if 'attack_logger' not in args_dict:
            if self.verbose < 1:

# Path: iolibrary.py
# def kill_signal_handler(signal, frame):
#     '''
#     Signal handler for killing the execution.
#     '''
#     print('\nExiting the program per your command.')
#     system('rm -f out.out request.txt iolibrary.pyc hillclimbing.pyc constants.pyc connect.pyc parse.pyc sniff.pyc')
#     if not path.exists('history'):
#         mkdir('history')
#     if path.exists('basic_breach.log'):
#         system('mv basic_breach.log history/')
#     if path.exists('full_breach.log'):
#         system('mv full_breach.log history/')
#     if path.exists('debug.log'):
#         system('mv debug.log history/')
#     if path.exists('attack.log'):
#         system('mv attack.log history/')
#     if path.exists('win_count.log'):
#         system('mv win_count.log history/')
#     if path.exists('sniff.log'):
#         system('mv sniff.log history/')
#     if path.exists('sniff_full.log'):
#         system('mv sniff_full.log history/')
#     sys.exit(0)
# 
# def get_arguments_dict(args_list):
#     '''
#     Parse command line arguments that were given to the program that calls this method.
#     '''
#     parser = argparse.ArgumentParser(description='Parser of breach.py output')
#     parser.add_argument('caller_name', metavar='caller_name', help='The program that called the argument parser.')
#     parser.add_argument('--execute_breach', action='store_true', help='Initiate breach attack via breach.py')
#     args = parser.parse_args(args_list)
# 
#     args_dict = {}
#     args_dict['execute_breach'] = True if args.execute_breach else False
#     return args_dict
# 
# def setup_logger(logger_name, log_file, args_dict, level=logging.DEBUG):
#     '''
#     Logger factory.
#     '''
#     l = logging.getLogger(logger_name)
#     l.setLevel(level)
#     formatter = logging.Formatter('%(asctime)s : %(message)s')
#     fileHandler = logging.FileHandler(log_file)
#     fileHandler.setFormatter(formatter)
#     l.addHandler(fileHandler)
#     if args_dict['log_to_screen']:
#         streamHandler = logging.StreamHandler()
#         streamHandler.setFormatter(formatter)
#         l.addHandler(streamHandler)


# Path: thesis/src/parse.py
from os import system, path, getpid
from iolibrary import kill_signal_handler, get_arguments_dict, setup_logger
import sys
import signal
import datetime
import logging
import time
import threading
import constants
import connect
        import hillclimbing

    Class that parses the packet lengths that are sniffed through the network.
    '''
    def __init__(self, args_dict):
        '''
        Initialize constants and arguments.
        '''
        self.args_dict = args_dict
        assert args_dict['pivot_length'] or args_dict['minimum_request_length'], 'Invalid combination of minimum request and pivot lengths'
        self.alpha_types = args_dict['alpha_types']
        if 'alphabet' in args_dict:
            self.alphabet = args_dict['alphabet']
        self.pivot_length = args_dict['pivot_length']
        self.prefix = args_dict['prefix']
        self.latest_file = args_dict['latest_file']
        self.minimum_request_length = args_dict['minimum_request_length']
        self.method = args_dict['method']
        self.correct_val = args_dict['correct_val']
        self.sampling_ratio = args_dict['sampling_ratio']
        self.refresh_time = args_dict['refresh_time']
        self.start_time = args_dict['start_time']
        self.verbose = args_dict['verbose']
        self.max_iter = args_dict['iterations']
        self.wdir = args_dict['wdir']
        self.execute_breach = args_dict['execute_breach']
        self.divide_and_conquer = args_dict['divide_and_conquer'] if 'divide_and_conquer' in args_dict else 0
        self.history_folder = args_dict['history_folder']
        self.latest_file = 0
        self.point_system = constants.POINT_SYSTEM_MAPPING[args_dict['method']]
        if 'attack_logger' not in args_dict:
            if self.verbose < 1:

                setup_logger('attack_logger', 'attack.log', args_dict, logging.ERROR)