Added class ProxyDebug.

This commit is contained in:
XMRig
2017-09-04 08:15:01 +03:00
parent 4df1183abd
commit cad2ba8081
7 changed files with 170 additions and 5 deletions

View File

@@ -49,6 +49,7 @@ set(HEADERS
src/proxy/Miner.h
src/proxy/Miners.h
src/proxy/Proxy.h
src/proxy/ProxyDebug.h
src/proxy/Server.h
src/proxy/splitters/NonceMapper.h
src/proxy/splitters/NonceSplitter.h
@@ -87,6 +88,7 @@ set(SOURCES
src/proxy/Miner.cpp
src/proxy/Miners.cpp
src/proxy/Proxy.cpp
src/proxy/ProxyDebug.cpp
src/proxy/Server.cpp
src/proxy/splitters/NonceMapper.cpp
src/proxy/splitters/NonceSplitter.cpp

View File

@@ -42,6 +42,7 @@
#include "proxy/Miner.h"
#include "proxy/Miners.h"
#include "proxy/Proxy.h"
#include "proxy/ProxyDebug.h"
#include "proxy/Server.h"
#include "proxy/splitters/NonceSplitter.h"
@@ -50,7 +51,7 @@ Proxy::Proxy(const Options *options)
{
srand(time(0) ^ (uintptr_t) this);
m_miners = new Miners();
m_miners = new Miners();
m_splitter = new NonceSplitter(options, Platform::userAgent());
m_timer.data = this;
@@ -65,6 +66,8 @@ Proxy::Proxy(const Options *options)
Events::subscribe(IEvent::LoginType, m_splitter);
Events::subscribe(IEvent::SubmitType, m_splitter);
m_debug = new ProxyDebug();
}

View File

@@ -36,6 +36,7 @@
class Miners;
class NonceSplitter;
class Options;
class ProxyDebug;
class Server;
class Url;
@@ -71,6 +72,7 @@ private:
Miners *m_miners;
NonceSplitter *m_splitter;
ProxyDebug *m_debug;
std::vector<Server*> m_servers;
uv_timer_t m_timer;
};

107
src/proxy/ProxyDebug.cpp Normal file
View File

@@ -0,0 +1,107 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <inttypes.h>
#include "proxy/Events.h"
#include "proxy/events/CloseEvent.h"
#include "proxy/events/ConnectionEvent.h"
#include "proxy/events/LoginEvent.h"
#include "proxy/events/SubmitEvent.h"
#include "proxy/ProxyDebug.h"
#include "log/Log.h"
#include "proxy/Miner.h"
#include "proxy/LoginRequest.h"
ProxyDebug::ProxyDebug()
{
Events::subscribe(IEvent::ConnectionType, this);
Events::subscribe(IEvent::CloseType, this);
Events::subscribe(IEvent::LoginType, this);
Events::subscribe(IEvent::SubmitType, this);
}
ProxyDebug::~ProxyDebug()
{
}
void ProxyDebug::onEvent(IEvent *event)
{
switch (event->type())
{
case IEvent::ConnectionType: {
auto e = static_cast<ConnectionEvent*>(event);
LOG_INFO("[debug] connection <Miner id=%" PRId64 ", ip=%s> via port: %d", e->miner()->id(), e->miner()->ip(), e->port());
}
break;
case IEvent::LoginType: {
auto e = static_cast<LoginEvent*>(event);
LOG_INFO("[debug] login <Miner id=%" PRId64 ", ip=%s>, <Request login=%s, agent=%s>", e->miner()->id(), e->miner()->ip(), e->request.login(), e->request.agent());
}
break;
case IEvent::CloseType: {
auto e = static_cast<CloseEvent*>(event);
LOG_INFO("[debug] close <Miner id=%" PRId64 ", ip=%s>", e->miner()->id(), e->miner()->ip());
}
break;
default:
break;
}
}
void ProxyDebug::onRejectedEvent(IEvent *event)
{
switch (event->type())
{
case IEvent::ConnectionType: {
ConnectionEvent *e = static_cast<ConnectionEvent*>(event);
LOG_ERR("[error] connection <Miner id=%" PRId64 ", ip=%s> via port: %d", e->miner()->id(), e->miner()->ip(), e->port());
}
break;
case IEvent::LoginType: {
auto e = static_cast<LoginEvent*>(event);
LOG_ERR("[error] login <Miner id=%" PRId64 ", ip=%s>, <Request login=%s, agent=%s>", e->miner()->id(), e->miner()->ip(), e->request.login(), e->request.agent());
}
break;
case IEvent::CloseType: {
auto e = static_cast<CloseEvent*>(event);
LOG_INFO("[debug] close <Miner id=%" PRId64 ", ip=%s>", e->miner()->id(), e->miner()->ip());
}
break;
default:
break;
}
}

43
src/proxy/ProxyDebug.h Normal file
View File

@@ -0,0 +1,43 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __PROXYDEBUG_H__
#define __PROXYDEBUG_H__
#include "interfaces/IEventListener.h"
class ProxyDebug : public IEventListener
{
public:
ProxyDebug();
~ProxyDebug();
protected:
void onEvent(IEvent *event) override;
void onRejectedEvent(IEvent *event) override;
};
#endif /* __PROXYDEBUG_H__ */

View File

@@ -74,5 +74,5 @@ void Server::onConnection(uv_stream_t *server, int status)
return;
}
ConnectionEvent::start(miner);
ConnectionEvent::start(miner, instance->m_port);
}

View File

@@ -31,14 +31,22 @@
class ConnectionEvent : public MinerEvent
{
public:
static inline bool start(Miner *miner)
static inline bool start(Miner *miner, int port)
{
return exec(new (m_buf) ConnectionEvent(miner));
return exec(new (m_buf) ConnectionEvent(miner, port));
}
inline int port() const { return m_port; }
protected:
inline ConnectionEvent(Miner *miner) : MinerEvent(ConnectionType, miner) {}
inline ConnectionEvent(Miner *miner, int port)
: MinerEvent(ConnectionType, miner),
m_port(port)
{}
private:
int m_port;
};