mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
introduced Peer
This commit is contained in:
parent
1eef996701
commit
d971dff593
@ -77,6 +77,7 @@ namespace transport
|
||||
{
|
||||
m_IsEstablished = false;
|
||||
m_Socket.close ();
|
||||
transports.PeerDisconnected (shared_from_this ());
|
||||
int numDelayed = 0;
|
||||
for (auto it :m_DelayedMessages)
|
||||
{
|
||||
@ -106,6 +107,8 @@ namespace transport
|
||||
SendTimeSyncMessage ();
|
||||
SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are
|
||||
|
||||
transports.PeerConnected (shared_from_this ());
|
||||
|
||||
if (!m_DelayedMessages.empty ())
|
||||
{
|
||||
for (auto it :m_DelayedMessages)
|
||||
|
@ -756,6 +756,7 @@ namespace transport
|
||||
void SSUSession::Close ()
|
||||
{
|
||||
SendSesionDestroyed ();
|
||||
transports.PeerDisconnected (shared_from_this ());
|
||||
if (!m_DelayedMessages.empty ())
|
||||
{
|
||||
for (auto it :m_DelayedMessages)
|
||||
@ -773,6 +774,7 @@ namespace transport
|
||||
m_DHKeysPair = nullptr;
|
||||
}
|
||||
SendI2NPMessage (CreateDatabaseStoreMsg ());
|
||||
transports.PeerConnected (shared_from_this ());
|
||||
if (!m_DelayedMessages.empty ())
|
||||
{
|
||||
for (auto it :m_DelayedMessages)
|
||||
|
@ -139,6 +139,7 @@ namespace transport
|
||||
|
||||
void Transports::Stop ()
|
||||
{
|
||||
m_Peers.clear ();
|
||||
if (m_SSUServer)
|
||||
{
|
||||
m_SSUServer->Stop ();
|
||||
@ -291,6 +292,35 @@ namespace transport
|
||||
{
|
||||
m_DHKeysPairSupplier.Return (pair);
|
||||
}
|
||||
|
||||
void Transports::PeerConnected (std::shared_ptr<TransportSession> session)
|
||||
{
|
||||
m_Service.post([session, this]()
|
||||
{
|
||||
auto ident = session->GetRemoteIdentity ().GetIdentHash ();
|
||||
auto it = m_Peers.find (ident);
|
||||
if (it != m_Peers.end ())
|
||||
{
|
||||
it->second.session = session;
|
||||
for (auto it1: it->second.delayedMessages)
|
||||
session->SendI2NPMessage (it1);
|
||||
}
|
||||
/* else // incoming connection
|
||||
m_Peers[ident] = { nullptr, session };*/
|
||||
});
|
||||
}
|
||||
|
||||
void Transports::PeerDisconnected (std::shared_ptr<TransportSession> session)
|
||||
{
|
||||
m_Service.post([session, this]()
|
||||
{
|
||||
auto ident = session->GetRemoteIdentity ().GetIdentHash ();
|
||||
auto it = m_Peers.find (ident);
|
||||
if (it != m_Peers.end ())
|
||||
m_Peers.erase (it);
|
||||
// TODO:: check for delayed messages
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
18
Transports.h
18
Transports.h
@ -6,6 +6,7 @@
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
@ -50,6 +51,19 @@ namespace transport
|
||||
CryptoPP::AutoSeededRandomPool m_Rnd;
|
||||
};
|
||||
|
||||
struct Peer
|
||||
{
|
||||
std::shared_ptr<const i2p::data::RouterInfo> router;
|
||||
std::shared_ptr<TransportSession> session;
|
||||
std::list<i2p::I2NPMessage *> delayedMessages;
|
||||
|
||||
~Peer ()
|
||||
{
|
||||
for (auto it :delayedMessages)
|
||||
i2p::DeleteI2NPMessage (it);
|
||||
}
|
||||
};
|
||||
|
||||
class Transports
|
||||
{
|
||||
public:
|
||||
@ -67,6 +81,9 @@ namespace transport
|
||||
void SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
|
||||
void CloseSession (std::shared_ptr<const i2p::data::RouterInfo> router);
|
||||
|
||||
void PeerConnected (std::shared_ptr<TransportSession> session);
|
||||
void PeerDisconnected (std::shared_ptr<TransportSession> session);
|
||||
|
||||
private:
|
||||
|
||||
void Run ();
|
||||
@ -86,6 +103,7 @@ namespace transport
|
||||
|
||||
NTCPServer * m_NTCPServer;
|
||||
SSUServer * m_SSUServer;
|
||||
std::map<i2p::data::IdentHash, Peer> m_Peers;
|
||||
|
||||
DHKeysPairSupplier m_DHKeysPairSupplier;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user