<commit_before>/**
 * \file   dublin_traceroute.h
 * \author <NAME> <<EMAIL>>
 * \copyright 2-clause BSD
 * \date   October 2015
 * \brief  Main class for the NAT-aware multipath traceroute
 *
 * This module contains the implementation of the NAT-aware multipath
 * traceroute known as dublin-traceroute.
 *
 * \sa dublin_traceroute.cc
 */

#ifndef _Dublin_TRACEROUTE_H
#define _Dublin_TRACEROUTE_H

#include <iostream>
#include <arpa/inet.h>
#include <thread>
#include <mutex>

#include "common.h"
#include "exceptions.h"
#include "traceroute_results.h"

using namespace Tins;

// TODO add copyright and author

/* TODO put everything into a namespace, e.g.
 *      namespace DublinTraceroute {  // or DublinTraceroute
 *          class Traceroute {
 *              TracerouteResults run();
 *              ...
 *          }
 *      }
 */

enum probe_type {
	// valid probe types must be within `min` and `max`, which are used for
	// argument checking.
	min,
	// UDP over IPv4
	UDPv4,
	max,
};

inline
const std::string
probe_type_name(probe_type type) {
	switch (type) {
	case probe_type::UDPv4:
		return "IPv4/UDP";
	default:
		return "<unknown probe type>";
	}
}

class  DublinTraceroute {

private:
	const uint16_t		 srcport_,
				 dstport_;
	const std::string	 dst_;
	const probe_type	 type_;
	IPv4Address		 target_;
	const uint8_t		 npaths_,
				 min_ttl_,
				 max_ttl_;
	const uint16_t		 delay_;
	const bool		 broken_nat_,
				 use_srcport_for_path_generation_,
				 no_dns_;
	std::mutex		 mutex_tracerouting,
				 mutex_sniffed_packets;
	IPv4Address		 my_address;
	std::vector<std::shared_ptr<Packet>>	 sniffed_packets;
	const void		 validate_arguments();

public:
	static const probe_type  default_type = probe_type::UDPv4;
	static const uint16_t	 default_srcport = 12345;
	static const uint16_t	 default_dstport = 33434;
	static const uint8_t	 default_npaths = 20;
	static const uint8_t	 default_min_ttl = 1;
	static const uint8_t	 default_max_ttl = 30;
	static const uint16_t	 default_delay = 10;
	static const bool	 default_broken_nat = false;
	static const bool	 default_use_srcport_for_path_generation = false;
	static const bool	 default_no_dns = false;
	DublinTraceroute(
			const std::string &dst,
			const probe_type type = default_type,
			const uint16_t srcport = default_srcport,
			const uint16_t dstport = default_dstport,
			const uint8_t npaths = default_npaths,
			const uint8_t min_ttl = default_min_ttl,
			const uint8_t max_ttl = default_max_ttl,
			const uint16_t delay = default_delay,
			const bool broken_nat = default_broken_nat,
			const bool use_srcport_for_path_generation = default_use_srcport_for_path_generation,
			const bool no_dns = default_no_dns
			):
				dst_(dst),
				type_(type),
				srcport_(srcport),
				dstport_(dstport),
				npaths_(npaths),
				min_ttl_(min_ttl),
				max_ttl_(max_ttl),
				delay_(delay),
				broken_nat_(broken_nat),
				use_srcport_for_path_generation_(use_srcport_for_path_generation),
				no_dns_(no_dns)
	{ validate_arguments(); }
	DublinTraceroute(
			const char *dst,
			const probe_type type = default_type,
			const uint16_t srcport = default_srcport,
			const uint16_t dstport = default_dstport,
			const uint8_t npaths = default_npaths,
			const uint8_t min_ttl = default_min_ttl,
			const uint8_t max_ttl = default_max_ttl,
			const uint16_t delay = default_delay,
			const bool broken_nat = default_broken_nat,
			const bool use_srcport_for_path_generation = default_use_srcport_for_path_generation,
			const bool no_dns = default_no_dns
		       ):
				dst_(std::string(dst)),
				type_(type_),
				srcport_(srcport),
				dstport_(dstport),<commit_msg>Fix constructor<commit_after>/**
 * \file   dublin_traceroute.h
 * \author <NAME> <<EMAIL>>
 * \copyright 2-clause BSD
 * \date   October 2015
 * \brief  Main class for the NAT-aware multipath traceroute
 *
 * This module contains the implementation of the NAT-aware multipath
 * traceroute known as dublin-traceroute.
 *
 * \sa dublin_traceroute.cc
 */

#ifndef _Dublin_TRACEROUTE_H
#define _Dublin_TRACEROUTE_H

#include <iostream>
#include <arpa/inet.h>
#include <thread>
#include <mutex>

#include "common.h"
#include "exceptions.h"
#include "traceroute_results.h"

using namespace Tins;

// TODO add copyright and author

/* TODO put everything into a namespace, e.g.
 *      namespace DublinTraceroute {  // or DublinTraceroute
 *          class Traceroute {
 *              TracerouteResults run();
 *              ...
 *          }
 *      }
 */

enum probe_type {
	// valid probe types must be within `min` and `max`, which are used for
	// argument checking.
	min,
	// UDP over IPv4
	UDPv4,
	max,
};

inline
const std::string
probe_type_name(probe_type type) {
	switch (type) {
	case probe_type::UDPv4:
		return "IPv4/UDP";
	default:
		return "<unknown probe type>";
	}
}

class  DublinTraceroute {

private:
	const uint16_t		 srcport_,
				 dstport_;
	const std::string	 dst_;
	const probe_type	 type_;
	IPv4Address		 target_;
	const uint8_t		 npaths_,
				 min_ttl_,
				 max_ttl_;
	const uint16_t		 delay_;
	const bool		 broken_nat_,
				 use_srcport_for_path_generation_,
				 no_dns_;
	std::mutex		 mutex_tracerouting,
				 mutex_sniffed_packets;
	IPv4Address		 my_address;
	std::vector<std::shared_ptr<Packet>>	 sniffed_packets;
	const void		 validate_arguments();

public:
	static const probe_type  default_type = probe_type::UDPv4;
	static const uint16_t	 default_srcport = 12345;
	static const uint16_t	 default_dstport = 33434;
	static const uint8_t	 default_npaths = 20;
	static const uint8_t	 default_min_ttl = 1;
	static const uint8_t	 default_max_ttl = 30;
	static const uint16_t	 default_delay = 10;
	static const bool	 default_broken_nat = false;
	static const bool	 default_use_srcport_for_path_generation = false;
	static const bool	 default_no_dns = false;
	DublinTraceroute(
			const std::string &dst,
			const probe_type type = default_type,
			const uint16_t srcport = default_srcport,
			const uint16_t dstport = default_dstport,
			const uint8_t npaths = default_npaths,
			const uint8_t min_ttl = default_min_ttl,
			const uint8_t max_ttl = default_max_ttl,
			const uint16_t delay = default_delay,
			const bool broken_nat = default_broken_nat,
			const bool use_srcport_for_path_generation = default_use_srcport_for_path_generation,
			const bool no_dns = default_no_dns
			):
				dst_(dst),
				type_(type),
				srcport_(srcport),
				dstport_(dstport),
				npaths_(npaths),
				min_ttl_(min_ttl),
				max_ttl_(max_ttl),
				delay_(delay),
				broken_nat_(broken_nat),
				use_srcport_for_path_generation_(use_srcport_for_path_generation),
				no_dns_(no_dns)
	{ validate_arguments(); }
	DublinTraceroute(
			const char *dst,
			const probe_type type = default_type,
			const uint16_t srcport = default_srcport,
			const uint16_t dstport = default_dstport,
			const uint8_t npaths = default_npaths,
			const uint8_t min_ttl = default_min_ttl,
			const uint8_t max_ttl = default_max_ttl,
			const uint16_t delay = default_delay,
			const bool broken_nat = default_broken_nat,
			const bool use_srcport_for_path_generation = default_use_srcport_for_path_generation,
			const bool no_dns = default_no_dns
		       ):
				dst_(std::string(dst)),
				type_(type),
				srcport_(srcport),
				dstport_(dstport),
{'fraction_non_alphanumeric': 0.08046134834546204, 'fraction_numerical': 0.01675133873403817, 'mean_word_length': 3.908355795148248, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '6429464', 'n_tokens_mistral': 2915, 'n_tokens_neox': 2558, 'n_words': 616}