Skip to content

Commit

Permalink
use shared pointer of RI for transports
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Nov 21, 2014
1 parent d8b9968 commit 1c3f700
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions NTCPSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ();
}
Expand Down
4 changes: 2 additions & 2 deletions NTCPSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; };
Expand Down Expand Up @@ -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:

Expand Down
6 changes: 3 additions & 3 deletions SSU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ())
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions SSU.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
2 changes: 1 addition & 1 deletion SSUSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion SSUSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();

Expand Down
7 changes: 4 additions & 3 deletions TransportSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <inttypes.h>
#include <iostream>
#include <memory>
#include "Identity.h"
#include "RouterInfo.h"

Expand Down Expand Up @@ -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)
Expand All @@ -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
};
Expand Down
6 changes: 3 additions & 3 deletions Transports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit 1c3f700

Please sign in to comment.