<commit_before>#include "Socket.h"

#include "Common.h"

#include <cstring>
#include <errno.h>
#include <unistd.h>
#include <iostream>
#include <fstream>
#include <relay/RelayServer.h>
#include <iomanip>
#include "proxy/ProxyServer.h"
#include "ConnectionData.h"
#include "Util.h"
#include "MasterController.h"

using namespace std;

struct Config
{
	Config() {
		proxyPort = -1;
		relayPort = -1;
		masterAddress;
		masterPort = -1;
	}

	int proxyPort;
	int relayPort;
	std::string masterAddress;
	int masterPort;
};

void initMasterController(Config& config) {

	if (config.masterAddress.empty()) {
		return;
	}

	auto master = MasterController::getInstance();
	char ipo[INET_ADDRSTRLEN];
	inet_pton(AF_INET, config.masterAddress.c_str(), (void*)ipo);

	AddressDetails masterInfo;
	masterInfo.addressType = IPV4_ADDRESS;
	masterInfo.address = std::string();
	masterInfo.address.append(ipo, 4);
	masterInfo.port = (uint16_t)config.masterPort;

	string ip;
	string data;

	Socket::getLocalIPAddress(ip, data);
	if (ip.empty()) {
		cerr << "Could not get Local IP Address: " << ip << endl;
		exit(1);
	}

	AddressDetails relayInfo;
	relayInfo.addressType = IPV4_ADDRESS;
	relayInfo.address = data;
	relayInfo.port = (uint16_t)config.relayPort;

	master->connect(relayInfo, masterInfo);
}

// Print an error message, usage, and then exit.
void Usage(string errorMessage)
{
	cerr << errorMessage << "\n"
"Usage: [-config <config.cfg (default)>] [-proxy port <port, default 1080>] [-relay port <port, default 1090>] [-master <ip>:<port]\n"
"Command line options supersedes  options in the config file.\n";
	exit(1);
}

Config ReadConfigFromFile(string filename)
{
	Config cfg;
	ifstream input(filename.c_str());

	string key;
	string temp;
	while (true) {

		input >> key;
		if (input.eof() || key.empty())
			break;

		if (key == "-proxy") {<commit_msg>Fixed up by using pton<commit_after>#include "Socket.h"

#include "Common.h"

#include <cstring>
#include <errno.h>
#include <unistd.h>
#include <iostream>
#include <fstream>
#include <relay/RelayServer.h>
#include <iomanip>
#include "proxy/ProxyServer.h"
#include "ConnectionData.h"
#include "Util.h"
#include "MasterController.h"

using namespace std;

struct Config
{
	Config() {
		proxyPort = -1;
		relayPort = -1;
		masterAddress;
		masterPort = -1;
	}

	int proxyPort;
	int relayPort;
	std::string masterAddress;
	int masterPort;
};

void initMasterController(Config& config) {

	if (config.masterAddress.empty()) {
		return;
	}

	auto master = MasterController::getInstance();

	AddressDetails masterInfo;
	masterInfo.addressType = IPV4_ADDRESS;
	masterInfo.address = Util::PresentationToNetwork(config.masterAddress);
	masterInfo.port = (uint16_t)config.masterPort;

	string ip;
	string data;

	Socket::getLocalIPAddress(ip, data);
	if (ip.empty()) {
		cerr << "Could not get Local IP Address: " << ip << endl;
		exit(1);
	}

	AddressDetails relayInfo;
	relayInfo.addressType = IPV4_ADDRESS;
	relayInfo.address = Util::PresentationToNetwork(ip);
	relayInfo.port = (uint16_t)config.relayPort;

	master->connect(relayInfo, masterInfo);
}

// Print an error message, usage, and then exit.
void Usage(string errorMessage)
{
	cerr << errorMessage << "\n"
"Usage: [-config <config.cfg (default)>] [-proxy port <port, default 1080>] [-relay port <port, default 1090>] [-master <ip>:<port]\n"
"Command line options supersedes  options in the config file.\n";
	exit(1);
}

Config ReadConfigFromFile(string filename)
{
	Config cfg;
	ifstream input(filename.c_str());

	string key;
	string temp;
	while (true) {

		input >> key;
		if (input.eof() || key.empty())
			break;

		if (key == "-proxy") {
{'fraction_non_alphanumeric': 0.14595336076817558, 'fraction_numerical': 0.010699588477366255, 'mean_word_length': 4.842948717948718, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 31, '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': '5723638', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1278, 'n_words': 319}