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
{ {
m_IsEstablished = false; m_IsEstablished = false;
m_Socket.close (); m_Socket.close ();
transports.PeerDisconnected (shared_from_this ());
int numDelayed = 0; int numDelayed = 0;
for (auto it :m_DelayedMessages) for (auto it :m_DelayedMessages)
{ {
@ -106,6 +107,8 @@ namespace transport
SendTimeSyncMessage (); SendTimeSyncMessage ();
SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are
transports.PeerConnected (shared_from_this ());
if (!m_DelayedMessages.empty ()) if (!m_DelayedMessages.empty ())
{ {
for (auto it :m_DelayedMessages) for (auto it :m_DelayedMessages)

2
SSUSession.cpp

@ -756,6 +756,7 @@ namespace transport
void SSUSession::Close () void SSUSession::Close ()
{ {
SendSesionDestroyed (); SendSesionDestroyed ();
transports.PeerDisconnected (shared_from_this ());
if (!m_DelayedMessages.empty ()) if (!m_DelayedMessages.empty ())
{ {
for (auto it :m_DelayedMessages) for (auto it :m_DelayedMessages)
@ -773,6 +774,7 @@ namespace transport
m_DHKeysPair = nullptr; m_DHKeysPair = nullptr;
} }
SendI2NPMessage (CreateDatabaseStoreMsg ()); SendI2NPMessage (CreateDatabaseStoreMsg ());
transports.PeerConnected (shared_from_this ());
if (!m_DelayedMessages.empty ()) if (!m_DelayedMessages.empty ())
{ {
for (auto it :m_DelayedMessages) for (auto it :m_DelayedMessages)

30
Transports.cpp

@ -139,6 +139,7 @@ namespace transport
void Transports::Stop () void Transports::Stop ()
{ {
m_Peers.clear ();
if (m_SSUServer) if (m_SSUServer)
{ {
m_SSUServer->Stop (); m_SSUServer->Stop ();
@ -291,6 +292,35 @@ namespace transport
{ {
m_DHKeysPairSupplier.Return (pair); 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 @@
#include <condition_variable> #include <condition_variable>
#include <functional> #include <functional>
#include <map> #include <map>
#include <list>
#include <queue> #include <queue>
#include <string> #include <string>
#include <memory> #include <memory>
@ -50,6 +51,19 @@ namespace transport
CryptoPP::AutoSeededRandomPool m_Rnd; 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 class Transports
{ {
public: public:
@ -66,6 +80,9 @@ namespace transport
void SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg); void SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
void CloseSession (std::shared_ptr<const i2p::data::RouterInfo> router); 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: private:
@ -86,7 +103,8 @@ namespace transport
NTCPServer * m_NTCPServer; NTCPServer * m_NTCPServer;
SSUServer * m_SSUServer; SSUServer * m_SSUServer;
std::map<i2p::data::IdentHash, Peer> m_Peers;
DHKeysPairSupplier m_DHKeysPairSupplier; DHKeysPairSupplier m_DHKeysPairSupplier;
public: public:

Loading…
Cancel
Save