Browse Source

introduced Peer

pull/150/head
orignal 10 years ago
parent
commit
d971dff593
  1. 3
      NTCPSession.cpp
  2. 2
      SSUSession.cpp
  3. 30
      Transports.cpp
  4. 20
      Transports.h

3
NTCPSession.cpp

@ -77,6 +77,7 @@ namespace transport @@ -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 @@ -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)

2
SSUSession.cpp

@ -756,6 +756,7 @@ namespace transport @@ -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 @@ -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)

30
Transports.cpp

@ -139,6 +139,7 @@ namespace transport @@ -139,6 +139,7 @@ namespace transport
void Transports::Stop ()
{
m_Peers.clear ();
if (m_SSUServer)
{
m_SSUServer->Stop ();
@ -291,6 +292,35 @@ namespace transport @@ -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
});
}
}
}

20
Transports.h

@ -6,6 +6,7 @@ @@ -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 @@ -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:
@ -66,6 +80,9 @@ namespace transport @@ -66,6 +80,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:
@ -86,7 +103,8 @@ namespace transport @@ -86,7 +103,8 @@ namespace transport
NTCPServer * m_NTCPServer;
SSUServer * m_SSUServer;
std::map<i2p::data::IdentHash, Peer> m_Peers;
DHKeysPairSupplier m_DHKeysPairSupplier;
public:

Loading…
Cancel
Save