Browse Source

use shared pointer of RI for transports

pull/113/head
orignal 10 years ago
parent
commit
1c3f70056a
  1. 6
      NTCPSession.cpp
  2. 4
      NTCPSession.h
  3. 6
      SSU.cpp
  4. 6
      SSU.h
  5. 2
      SSUSession.cpp
  6. 2
      SSUSession.h
  7. 7
      TransportSession.h
  8. 6
      Transports.cpp

6
NTCPSession.cpp

@ -19,7 +19,7 @@ namespace i2p @@ -19,7 +19,7 @@ namespace i2p
{
namespace transport
{
NTCPSession::NTCPSession (boost::asio::io_service& service, const i2p::data::RouterInfo * in_RemoteRouter):
NTCPSession::NTCPSession (boost::asio::io_service& service, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter):
TransportSession (in_RemoteRouter), m_Socket (service),
m_TerminationTimer (service), m_IsEstablished (false), m_ReceiveBufferOffset (0),
m_NextMessage (nullptr), m_NumSentBytes (0), m_NumReceivedBytes (0)
@ -597,8 +597,8 @@ namespace transport @@ -597,8 +597,8 @@ namespace transport
NTCPClient::NTCPClient (boost::asio::io_service& service, const boost::asio::ip::address& address,
int port, const i2p::data::RouterInfo& in_RouterInfo):
NTCPSession (service, &in_RouterInfo), m_Endpoint (address, port)
int port, std::shared_ptr<const i2p::data::RouterInfo> in_RouterInfo):
NTCPSession (service, in_RouterInfo), m_Endpoint (address, port)
{
Connect ();
}

4
NTCPSession.h

@ -62,7 +62,7 @@ namespace transport @@ -62,7 +62,7 @@ namespace transport
{
public:
NTCPSession (boost::asio::io_service& service, const i2p::data::RouterInfo * in_RemoteRouter = nullptr);
NTCPSession (boost::asio::io_service& service, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter = nullptr);
~NTCPSession ();
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
@ -146,7 +146,7 @@ namespace transport @@ -146,7 +146,7 @@ namespace transport
{
public:
NTCPClient (boost::asio::io_service& service, const boost::asio::ip::address& address, int port, const i2p::data::RouterInfo& in_RouterInfo);
NTCPClient (boost::asio::io_service& service, const boost::asio::ip::address& address, int port, std::shared_ptr<const i2p::data::RouterInfo> in_RouterInfo);
private:

6
SSU.cpp

@ -141,7 +141,7 @@ namespace transport @@ -141,7 +141,7 @@ namespace transport
session->ProcessNextMessage (buf, bytes_transferred, from);
}
SSUSession * SSUServer::FindSession (const i2p::data::RouterInfo * router)
SSUSession * SSUServer::FindSession (const i2p::data::RouterInfo * router) const
{
if (!router) return nullptr;
auto address = router->GetSSUAddress (true); // v4 only
@ -155,7 +155,7 @@ namespace transport @@ -155,7 +155,7 @@ namespace transport
return FindSession (boost::asio::ip::udp::endpoint (address->host, address->port));
}
SSUSession * SSUServer::FindSession (const boost::asio::ip::udp::endpoint& e)
SSUSession * SSUServer::FindSession (const boost::asio::ip::udp::endpoint& e) const
{
auto it = m_Sessions.find (e);
if (it != m_Sessions.end ())
@ -164,7 +164,7 @@ namespace transport @@ -164,7 +164,7 @@ namespace transport
return nullptr;
}
SSUSession * SSUServer::GetSession (const i2p::data::RouterInfo * router, bool peerTest)
SSUSession * SSUServer::GetSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest)
{
SSUSession * session = nullptr;
if (router)

6
SSU.h

@ -31,9 +31,9 @@ namespace transport @@ -31,9 +31,9 @@ namespace transport
~SSUServer ();
void Start ();
void Stop ();
SSUSession * GetSession (const i2p::data::RouterInfo * router, bool peerTest = false);
SSUSession * FindSession (const i2p::data::RouterInfo * router);
SSUSession * FindSession (const boost::asio::ip::udp::endpoint& e);
SSUSession * GetSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false);
SSUSession * FindSession (const i2p::data::RouterInfo * router) const;
SSUSession * FindSession (const boost::asio::ip::udp::endpoint& e) const;
SSUSession * GetRandomEstablishedSession (const SSUSession * excluded);
void DeleteSession (SSUSession * session);
void DeleteAllSessions ();

2
SSUSession.cpp

@ -14,7 +14,7 @@ namespace i2p @@ -14,7 +14,7 @@ namespace i2p
namespace transport
{
SSUSession::SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint,
const i2p::data::RouterInfo * router, bool peerTest ): TransportSession (router),
std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest ): TransportSession (router),
m_Server (server), m_RemoteEndpoint (remoteEndpoint),
m_Timer (m_Server.GetService ()), m_PeerTest (peerTest),
m_State (eSessionStateUnknown), m_IsSessionKey (false), m_RelayTag (0),

2
SSUSession.h

@ -55,7 +55,7 @@ namespace transport @@ -55,7 +55,7 @@ namespace transport
public:
SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint,
const i2p::data::RouterInfo * router = nullptr, bool peerTest = false);
std::shared_ptr<const i2p::data::RouterInfo> router = nullptr, bool peerTest = false);
void ProcessNextMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint);
~SSUSession ();

7
TransportSession.h

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
#include <inttypes.h>
#include <iostream>
#include <memory>
#include "Identity.h"
#include "RouterInfo.h"
@ -51,7 +52,7 @@ namespace transport @@ -51,7 +52,7 @@ namespace transport
{
public:
TransportSession (const i2p::data::RouterInfo * in_RemoteRouter):
TransportSession (std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter):
m_RemoteRouter (in_RemoteRouter), m_DHKeysPair (nullptr)
{
if (m_RemoteRouter)
@ -60,12 +61,12 @@ namespace transport @@ -60,12 +61,12 @@ namespace transport
virtual ~TransportSession () { delete m_DHKeysPair; };
const i2p::data::RouterInfo * GetRemoteRouter () { return m_RemoteRouter; };
std::shared_ptr<const i2p::data::RouterInfo> GetRemoteRouter () { return m_RemoteRouter; };
const i2p::data::IdentityEx& GetRemoteIdentity () { return m_RemoteIdentity; };
protected:
const i2p::data::RouterInfo * m_RemoteRouter;
std::shared_ptr<const i2p::data::RouterInfo> m_RemoteRouter;
i2p::data::IdentityEx m_RemoteIdentity;
DHKeysPair * m_DHKeysPair; // X - for client and Y - for server
};

6
Transports.cpp

@ -290,14 +290,14 @@ namespace transport @@ -290,14 +290,14 @@ namespace transport
auto address = r->GetNTCPAddress (!context.SupportsV6 ());
if (address && !r->UsesIntroducer () && !r->IsUnreachable () && msg->GetLength () < NTCP_MAX_MESSAGE_SIZE)
{
auto s = new NTCPClient (m_Service, address->host, address->port, *r);
auto s = new NTCPClient (m_Service, address->host, address->port, r);
AddNTCPSession (s);
s->SendI2NPMessage (msg);
}
else
{
// then SSU
auto s = m_SSUServer ? m_SSUServer->GetSession (r.get ()) : nullptr;
auto s = m_SSUServer ? m_SSUServer->GetSession (r) : nullptr;
if (s)
s->SendI2NPMessage (msg);
else
@ -360,7 +360,7 @@ namespace transport @@ -360,7 +360,7 @@ namespace transport
{
auto router = i2p::data::netdb.GetRandomRouter ();
if (router && router->IsSSU () && m_SSUServer)
m_SSUServer->GetSession (router.get (), true); // peer test
m_SSUServer->GetSession (router, true); // peer test
}
}

Loading…
Cancel
Save