mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
eliminate some overhead
This commit is contained in:
parent
2d513277f2
commit
4582a4fd95
|
@ -5,7 +5,9 @@ namespace i2p
|
||||||
{
|
{
|
||||||
namespace event
|
namespace event
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
EventCore core;
|
EventCore core;
|
||||||
|
#endif
|
||||||
|
|
||||||
void EventCore::SetListener(EventListener * l)
|
void EventCore::SetListener(EventListener * l)
|
||||||
{
|
{
|
||||||
|
|
3
Event.h
3
Event.h
|
@ -27,8 +27,9 @@ namespace i2p
|
||||||
private:
|
private:
|
||||||
EventListener * m_listener = nullptr;
|
EventListener * m_listener = nullptr;
|
||||||
};
|
};
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
extern EventCore core;
|
extern EventCore core;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void EmitEvent(const EventType & ev);
|
void EmitEvent(const EventType & ev);
|
||||||
|
|
|
@ -11,7 +11,9 @@
|
||||||
#include "Transports.h"
|
#include "Transports.h"
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
#include "NTCPSession.h"
|
#include "NTCPSession.h"
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace i2p::crypto;
|
using namespace i2p::crypto;
|
||||||
|
|
||||||
|
@ -606,7 +608,9 @@ namespace transport
|
||||||
{
|
{
|
||||||
if (!m_NextMessage->IsExpired ())
|
if (!m_NextMessage->IsExpired ())
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
EmitEvent({{"type", "transport.recvmsg"} , {"ident", GetIdentHashBase64()}, {"number", "1"}});
|
EmitEvent({{"type", "transport.recvmsg"} , {"ident", GetIdentHashBase64()}, {"number", "1"}});
|
||||||
|
#endif
|
||||||
m_Handler.PutNextMessage (m_NextMessage);
|
m_Handler.PutNextMessage (m_NextMessage);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
#include "SSU.h"
|
#include "SSU.h"
|
||||||
#include "SSUData.h"
|
#include "SSUData.h"
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
|
@ -235,8 +237,11 @@ namespace transport
|
||||||
{
|
{
|
||||||
m_ReceivedMessages.insert (msgID);
|
m_ReceivedMessages.insert (msgID);
|
||||||
m_LastMessageReceivedTime = i2p::util::GetSecondsSinceEpoch ();
|
m_LastMessageReceivedTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
if (!msg->IsExpired ()) {
|
if (!msg->IsExpired ())
|
||||||
|
{
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
EmitEvent({{"type", "transport.recvmsg"} , {"ident", m_Session.GetIdentHashBase64()}, {"number", "1"}});
|
EmitEvent({{"type", "transport.recvmsg"} , {"ident", m_Session.GetIdentHashBase64()}, {"number", "1"}});
|
||||||
|
#endif
|
||||||
m_Handler.PutNextMessage (msg);
|
m_Handler.PutNextMessage (msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace transport
|
||||||
virtual ~TransportSession () {};
|
virtual ~TransportSession () {};
|
||||||
virtual void Done () = 0;
|
virtual void Done () = 0;
|
||||||
|
|
||||||
std::string GetIdentHashBase64() const { return m_RemoteIdentity->GetIdentHash().ToBase64(); }
|
std::string GetIdentHashBase64() const { return m_RemoteIdentity ? m_RemoteIdentity->GetIdentHash().ToBase64() : ""; }
|
||||||
|
|
||||||
std::shared_ptr<const i2p::data::IdentityEx> GetRemoteIdentity () { return m_RemoteIdentity; };
|
std::shared_ptr<const i2p::data::IdentityEx> GetRemoteIdentity () { return m_RemoteIdentity; };
|
||||||
void SetRemoteIdentity (std::shared_ptr<const i2p::data::IdentityEx> ident) { m_RemoteIdentity = ident; };
|
void SetRemoteIdentity (std::shared_ptr<const i2p::data::IdentityEx> ident) { m_RemoteIdentity = ident; };
|
||||||
|
|
|
@ -5,8 +5,10 @@
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
#include "Transports.h"
|
#include "Transports.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
using namespace i2p::data;
|
using namespace i2p::data;
|
||||||
|
|
||||||
|
@ -232,7 +234,9 @@ namespace transport
|
||||||
|
|
||||||
void Transports::SendMessages (const i2p::data::IdentHash& ident, const std::vector<std::shared_ptr<i2p::I2NPMessage> >& msgs)
|
void Transports::SendMessages (const i2p::data::IdentHash& ident, const std::vector<std::shared_ptr<i2p::I2NPMessage> >& msgs)
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
EmitEvent({{"type" , "transport.sendmsg"}, {"ident", ident.ToBase64()}, {"number", std::to_string(msgs.size())}});
|
EmitEvent({{"type" , "transport.sendmsg"}, {"ident", ident.ToBase64()}, {"number", std::to_string(msgs.size())}});
|
||||||
|
#endif
|
||||||
m_Service.post (std::bind (&Transports::PostMessages, this, ident, msgs));
|
m_Service.post (std::bind (&Transports::PostMessages, this, ident, msgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,7 +575,9 @@ namespace transport
|
||||||
auto it = m_Peers.find (ident);
|
auto it = m_Peers.find (ident);
|
||||||
if (it != m_Peers.end ())
|
if (it != m_Peers.end ())
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
EmitEvent({{"type" , "transport.connected"}, {"ident", ident.ToBase64()}, {"inbound", "false"}});
|
EmitEvent({{"type" , "transport.connected"}, {"ident", ident.ToBase64()}, {"inbound", "false"}});
|
||||||
|
#endif
|
||||||
bool sendDatabaseStore = true;
|
bool sendDatabaseStore = true;
|
||||||
if (it->second.delayedMessages.size () > 0)
|
if (it->second.delayedMessages.size () > 0)
|
||||||
{
|
{
|
||||||
|
@ -597,7 +603,9 @@ namespace transport
|
||||||
session->Done();
|
session->Done();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
EmitEvent({{"type" , "transport.connected"}, {"ident", ident.ToBase64()}, {"inbound", "true"}});
|
EmitEvent({{"type" , "transport.connected"}, {"ident", ident.ToBase64()}, {"inbound", "true"}});
|
||||||
|
#endif
|
||||||
session->SendI2NPMessages ({ CreateDatabaseStoreMsg () }); // send DatabaseStore
|
session->SendI2NPMessages ({ CreateDatabaseStoreMsg () }); // send DatabaseStore
|
||||||
std::unique_lock<std::mutex> l(m_PeersMutex);
|
std::unique_lock<std::mutex> l(m_PeersMutex);
|
||||||
m_Peers.insert (std::make_pair (ident, Peer{ 0, nullptr, { session }, i2p::util::GetSecondsSinceEpoch (), {} }));
|
m_Peers.insert (std::make_pair (ident, Peer{ 0, nullptr, { session }, i2p::util::GetSecondsSinceEpoch (), {} }));
|
||||||
|
@ -612,7 +620,9 @@ namespace transport
|
||||||
auto remoteIdentity = session->GetRemoteIdentity ();
|
auto remoteIdentity = session->GetRemoteIdentity ();
|
||||||
if (!remoteIdentity) return;
|
if (!remoteIdentity) return;
|
||||||
auto ident = remoteIdentity->GetIdentHash ();
|
auto ident = remoteIdentity->GetIdentHash ();
|
||||||
|
#ifdef WITH_EVENTS
|
||||||
EmitEvent({{"type" , "transport.disconnected"}, {"ident", ident.ToBase64()}});
|
EmitEvent({{"type" , "transport.disconnected"}, {"ident", ident.ToBase64()}});
|
||||||
|
#endif
|
||||||
auto it = m_Peers.find (ident);
|
auto it = m_Peers.find (ident);
|
||||||
if (it != m_Peers.end ())
|
if (it != m_Peers.end ())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue