mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-11 17:37:53 +00:00
use shared pointer of RI for transports
This commit is contained in:
parent
d8b9968aed
commit
1c3f70056a
@ -19,7 +19,7 @@ namespace i2p
|
|||||||
{
|
{
|
||||||
namespace transport
|
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),
|
TransportSession (in_RemoteRouter), m_Socket (service),
|
||||||
m_TerminationTimer (service), m_IsEstablished (false), m_ReceiveBufferOffset (0),
|
m_TerminationTimer (service), m_IsEstablished (false), m_ReceiveBufferOffset (0),
|
||||||
m_NextMessage (nullptr), m_NumSentBytes (0), m_NumReceivedBytes (0)
|
m_NextMessage (nullptr), m_NumSentBytes (0), m_NumReceivedBytes (0)
|
||||||
@ -597,8 +597,8 @@ namespace transport
|
|||||||
|
|
||||||
|
|
||||||
NTCPClient::NTCPClient (boost::asio::io_service& service, const boost::asio::ip::address& address,
|
NTCPClient::NTCPClient (boost::asio::io_service& service, const boost::asio::ip::address& address,
|
||||||
int port, const i2p::data::RouterInfo& in_RouterInfo):
|
int port, std::shared_ptr<const i2p::data::RouterInfo> in_RouterInfo):
|
||||||
NTCPSession (service, &in_RouterInfo), m_Endpoint (address, port)
|
NTCPSession (service, in_RouterInfo), m_Endpoint (address, port)
|
||||||
{
|
{
|
||||||
Connect ();
|
Connect ();
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
public:
|
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 ();
|
~NTCPSession ();
|
||||||
|
|
||||||
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
|
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
|
||||||
@ -146,7 +146,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
public:
|
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:
|
private:
|
||||||
|
|
||||||
|
6
SSU.cpp
6
SSU.cpp
@ -141,7 +141,7 @@ namespace transport
|
|||||||
session->ProcessNextMessage (buf, bytes_transferred, from);
|
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;
|
if (!router) return nullptr;
|
||||||
auto address = router->GetSSUAddress (true); // v4 only
|
auto address = router->GetSSUAddress (true); // v4 only
|
||||||
@ -155,7 +155,7 @@ namespace transport
|
|||||||
return FindSession (boost::asio::ip::udp::endpoint (address->host, address->port));
|
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);
|
auto it = m_Sessions.find (e);
|
||||||
if (it != m_Sessions.end ())
|
if (it != m_Sessions.end ())
|
||||||
@ -164,7 +164,7 @@ namespace transport
|
|||||||
return nullptr;
|
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;
|
SSUSession * session = nullptr;
|
||||||
if (router)
|
if (router)
|
||||||
|
6
SSU.h
6
SSU.h
@ -31,9 +31,9 @@ namespace transport
|
|||||||
~SSUServer ();
|
~SSUServer ();
|
||||||
void Start ();
|
void Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
SSUSession * GetSession (const i2p::data::RouterInfo * router, bool peerTest = false);
|
SSUSession * GetSession (std::shared_ptr<const i2p::data::RouterInfo> router, bool peerTest = false);
|
||||||
SSUSession * FindSession (const i2p::data::RouterInfo * router);
|
SSUSession * FindSession (const i2p::data::RouterInfo * router) const;
|
||||||
SSUSession * FindSession (const boost::asio::ip::udp::endpoint& e);
|
SSUSession * FindSession (const boost::asio::ip::udp::endpoint& e) const;
|
||||||
SSUSession * GetRandomEstablishedSession (const SSUSession * excluded);
|
SSUSession * GetRandomEstablishedSession (const SSUSession * excluded);
|
||||||
void DeleteSession (SSUSession * session);
|
void DeleteSession (SSUSession * session);
|
||||||
void DeleteAllSessions ();
|
void DeleteAllSessions ();
|
||||||
|
@ -14,7 +14,7 @@ namespace i2p
|
|||||||
namespace transport
|
namespace transport
|
||||||
{
|
{
|
||||||
SSUSession::SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint,
|
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_Server (server), m_RemoteEndpoint (remoteEndpoint),
|
||||||
m_Timer (m_Server.GetService ()), m_PeerTest (peerTest),
|
m_Timer (m_Server.GetService ()), m_PeerTest (peerTest),
|
||||||
m_State (eSessionStateUnknown), m_IsSessionKey (false), m_RelayTag (0),
|
m_State (eSessionStateUnknown), m_IsSessionKey (false), m_RelayTag (0),
|
||||||
|
@ -55,7 +55,7 @@ namespace transport
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint,
|
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);
|
void ProcessNextMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint);
|
||||||
~SSUSession ();
|
~SSUSession ();
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
#include "RouterInfo.h"
|
#include "RouterInfo.h"
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
public:
|
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)
|
m_RemoteRouter (in_RemoteRouter), m_DHKeysPair (nullptr)
|
||||||
{
|
{
|
||||||
if (m_RemoteRouter)
|
if (m_RemoteRouter)
|
||||||
@ -60,12 +61,12 @@ namespace transport
|
|||||||
|
|
||||||
virtual ~TransportSession () { delete m_DHKeysPair; };
|
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; };
|
const i2p::data::IdentityEx& GetRemoteIdentity () { return m_RemoteIdentity; };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
const i2p::data::RouterInfo * m_RemoteRouter;
|
std::shared_ptr<const i2p::data::RouterInfo> m_RemoteRouter;
|
||||||
i2p::data::IdentityEx m_RemoteIdentity;
|
i2p::data::IdentityEx m_RemoteIdentity;
|
||||||
DHKeysPair * m_DHKeysPair; // X - for client and Y - for server
|
DHKeysPair * m_DHKeysPair; // X - for client and Y - for server
|
||||||
};
|
};
|
||||||
|
@ -290,14 +290,14 @@ namespace transport
|
|||||||
auto address = r->GetNTCPAddress (!context.SupportsV6 ());
|
auto address = r->GetNTCPAddress (!context.SupportsV6 ());
|
||||||
if (address && !r->UsesIntroducer () && !r->IsUnreachable () && msg->GetLength () < NTCP_MAX_MESSAGE_SIZE)
|
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);
|
AddNTCPSession (s);
|
||||||
s->SendI2NPMessage (msg);
|
s->SendI2NPMessage (msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// then SSU
|
// then SSU
|
||||||
auto s = m_SSUServer ? m_SSUServer->GetSession (r.get ()) : nullptr;
|
auto s = m_SSUServer ? m_SSUServer->GetSession (r) : nullptr;
|
||||||
if (s)
|
if (s)
|
||||||
s->SendI2NPMessage (msg);
|
s->SendI2NPMessage (msg);
|
||||||
else
|
else
|
||||||
@ -360,7 +360,7 @@ namespace transport
|
|||||||
{
|
{
|
||||||
auto router = i2p::data::netdb.GetRandomRouter ();
|
auto router = i2p::data::netdb.GetRandomRouter ();
|
||||||
if (router && router->IsSSU () && m_SSUServer)
|
if (router && router->IsSSU () && m_SSUServer)
|
||||||
m_SSUServer->GetSession (router.get (), true); // peer test
|
m_SSUServer->GetSession (router, true); // peer test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user