proxy-network/src/proxy.cpp

40 lines
1.3 KiB
C++
Raw Normal View History

2023-09-30 14:28:48 -05:00
//----- Include files ---------------------------------------------------------
2023-10-01 18:24:47 -05:00
#include <algorithm>
2023-10-03 22:45:14 -05:00
#include <cstring>
2023-09-30 14:28:48 -05:00
#include <future>
2023-10-01 16:10:03 -05:00
#include <iostream>
2023-10-01 18:24:47 -05:00
#include <vector>
#include "network.hpp"
2023-09-30 14:28:48 -05:00
int main(void)
{
2023-10-03 22:45:14 -05:00
strcpy(hazardous_contents_CS_01, "password.txt");
strcpy(hazardous_contents_CS_02, "admin.config");
2023-10-01 18:24:47 -05:00
std::vector<std::future<void>> pending_futures;
Server proxy(kProxyPort);
Client browser;
Client webserver;
2023-09-30 14:28:48 -05:00
// Main loop to listen, accept, and then spin-off a thread to handle the GET
while (1)
{
2023-10-01 18:24:47 -05:00
if (browser.ConnectFrom(proxy.socketFD) != 0)
{
2023-10-01 16:10:03 -05:00
std::cerr << "ERROR - Unable to create socket to client" << std::endl;
2023-09-30 14:28:48 -05:00
continue;
2023-10-01 18:24:47 -05:00
}
if (webserver.ConnectTo(kWebserverPort) != 0)
{
std::cerr << "ERROR - Unable to connect to webserver" << std::endl;
continue;
}
auto newThreadRequest1 = std::async(std::launch::async, PipeSockets, browser.socketFD, webserver.socketFD);
auto newThreadRequest2 = std::async(std::launch::async, ProxySockets, webserver.socketFD, browser.socketFD);
pending_futures.push_back(std::move(newThreadRequest1));
pending_futures.push_back(std::move(newThreadRequest2));
2023-09-30 14:28:48 -05:00
}
2023-10-01 18:24:47 -05:00
proxy.Close();
return 0;
2023-09-30 14:28:48 -05:00
}