1
0

ProtoProxy: Fixed connection and logging.

This commit is contained in:
Mattes D 2015-03-22 15:00:51 +01:00
parent c3c29577a5
commit 8df9f1685a
5 changed files with 23 additions and 15 deletions

View File

@ -8,6 +8,7 @@
#include "Server.h"
#include <iostream>
#include "PolarSSL++/CryptoKey.h"
#include "../../src/Logger.h"
#ifdef _WIN32
#include <direct.h> // For _mkdir()

View File

@ -247,7 +247,3 @@ public:
#define LOGERROR printf
#define LOGINFO printf
#define LOGWARNING printf

View File

@ -5,6 +5,8 @@
#include "Globals.h"
#include "Server.h"
#include "../../src/Logger.h"
#include "../../src/LoggerListeners.h"
@ -12,8 +14,16 @@
int main(int argc, char ** argv)
{
// Initialize logging subsystem:
cLogger::InitiateMultithreading();
auto consoleLogListener = MakeConsoleListener();
auto fileLogListener = new cFileListener();
cLogger::GetInstance().AttachListener(consoleLogListener);
cLogger::GetInstance().AttachListener(fileLogListener);
int ListenPort = (argc > 1) ? atoi(argv[1]) : 25564;
int ConnectPort = (argc > 2) ? atoi(argv[2]) : 25565;
printf("Initializing ProtoProxy. Listen port %d, connect port %d.\n", ListenPort, ConnectPort);
cServer Server;
int res = Server.Init(ListenPort, ConnectPort);
if (res != 0)

View File

@ -6,6 +6,7 @@
#include "Globals.h"
#include "Server.h"
#include "Connection.h"
#include "../../src/Logger.h"
@ -28,15 +29,11 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort)
int res = WSAStartup(0x0202, &wsa);
if (res != 0)
{
printf("Cannot initialize WinSock: %d\n", res);
LOGERROR("Cannot initialize WinSock: %d", res);
return res;
}
#endif // _WIN32
LOGINFO("Generating protocol encryption keypair...");
m_PrivateKey.Generate();
m_PublicKeyDER = m_PrivateKey.GetPubKeyDER();
m_ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (m_ListenSocket < 0)
{
@ -45,22 +42,22 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort)
#else
int err = errno;
#endif
printf("Failed to create listener socket: %d\n", err);
LOGERROR("Failed to create listener socket: %d", err);
return err;
}
sockaddr_in local;
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
local.sin_addr.s_addr = 130; // INADDR_ANY; // All interfaces
local.sin_addr.s_addr = INADDR_ANY; // All interfaces
local.sin_port = htons(a_ListenPort);
if (!bind(m_ListenSocket, (sockaddr *)&local, sizeof(local)))
if (bind(m_ListenSocket, (sockaddr *)&local, sizeof(local)) != 0)
{
#ifdef _WIN32
int err = WSAGetLastError();
#else
int err = errno;
#endif
printf("Failed to bind listener socket: %d\n", err);
LOGERROR("Failed to bind listener socket: %d", err);
return err;
}
if (listen(m_ListenSocket, 1) != 0)
@ -73,8 +70,11 @@ int cServer::Init(short a_ListenPort, short a_ConnectPort)
printf("Failed to listen on socket: %d\n", err);
return err;
}
LOGINFO("Listening on port %d, connecting to localhost:%d", a_ListenPort, a_ConnectPort);
printf("Listening on port %d, connecting to localhost:%d\n", a_ListenPort, a_ConnectPort);
LOGINFO("Generating protocol encryption keypair...");
m_PrivateKey.Generate();
m_PublicKeyDER = m_PrivateKey.GetPubKeyDER();
return 0;
}

View File

@ -1,5 +1,6 @@
#include "Logger.h"
#include "OSSupport/File.h"