mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
moved transports to 'transport' namespace
This commit is contained in:
parent
165af090b6
commit
7b768ccb26
|
@ -103,7 +103,7 @@ namespace i2p
|
||||||
LogPrint("HTTP Server started");
|
LogPrint("HTTP Server started");
|
||||||
i2p::data::netdb.Start();
|
i2p::data::netdb.Start();
|
||||||
LogPrint("NetDB started");
|
LogPrint("NetDB started");
|
||||||
i2p::transports.Start();
|
i2p::transport::transports.Start();
|
||||||
LogPrint("Transports started");
|
LogPrint("Transports started");
|
||||||
i2p::tunnel::tunnels.Start();
|
i2p::tunnel::tunnels.Start();
|
||||||
LogPrint("Tunnels started");
|
LogPrint("Tunnels started");
|
||||||
|
@ -120,7 +120,7 @@ namespace i2p
|
||||||
LogPrint("Client stoped");
|
LogPrint("Client stoped");
|
||||||
i2p::tunnel::tunnels.Stop();
|
i2p::tunnel::tunnels.Stop();
|
||||||
LogPrint("Tunnels stoped");
|
LogPrint("Tunnels stoped");
|
||||||
i2p::transports.Stop();
|
i2p::transport::transports.Stop();
|
||||||
LogPrint("Transports stoped");
|
LogPrint("Transports stoped");
|
||||||
i2p::data::netdb.Stop();
|
i2p::data::netdb.Stop();
|
||||||
LogPrint("NetDB stoped");
|
LogPrint("NetDB stoped");
|
||||||
|
|
|
@ -699,7 +699,7 @@ namespace util
|
||||||
void HTTPConnection::ShowTransports (std::stringstream& s)
|
void HTTPConnection::ShowTransports (std::stringstream& s)
|
||||||
{
|
{
|
||||||
s << "NTCP<br>";
|
s << "NTCP<br>";
|
||||||
for (auto it: i2p::transports.GetNTCPSessions ())
|
for (auto it: i2p::transport::transports.GetNTCPSessions ())
|
||||||
{
|
{
|
||||||
// RouterInfo of incoming connection doesn't have address
|
// RouterInfo of incoming connection doesn't have address
|
||||||
bool outgoing = it.second->GetRemoteRouterInfo ().GetNTCPAddress ();
|
bool outgoing = it.second->GetRemoteRouterInfo ().GetNTCPAddress ();
|
||||||
|
@ -714,7 +714,7 @@ namespace util
|
||||||
}
|
}
|
||||||
s << std::endl;
|
s << std::endl;
|
||||||
}
|
}
|
||||||
auto ssuServer = i2p::transports.GetSSUServer ();
|
auto ssuServer = i2p::transport::transports.GetSSUServer ();
|
||||||
if (ssuServer)
|
if (ssuServer)
|
||||||
{
|
{
|
||||||
s << "<br>SSU<br>";
|
s << "<br>SSU<br>";
|
||||||
|
|
|
@ -13,9 +13,10 @@
|
||||||
#include "Garlic.h"
|
#include "Garlic.h"
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
|
|
||||||
|
using namespace i2p::transport;
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
|
|
||||||
I2NPMessage * NewI2NPMessage ()
|
I2NPMessage * NewI2NPMessage ()
|
||||||
{
|
{
|
||||||
return new I2NPMessageBuffer<I2NP_MAX_MESSAGE_SIZE>();
|
return new I2NPMessageBuffer<I2NP_MAX_MESSAGE_SIZE>();
|
||||||
|
@ -353,13 +354,13 @@ namespace i2p
|
||||||
if (clearText.flag & 0x40) // we are endpoint of outboud tunnel
|
if (clearText.flag & 0x40) // we are endpoint of outboud tunnel
|
||||||
{
|
{
|
||||||
// so we send it to reply tunnel
|
// so we send it to reply tunnel
|
||||||
i2p::transports.SendMessage (clearText.nextIdent,
|
transports.SendMessage (clearText.nextIdent,
|
||||||
CreateTunnelGatewayMsg (be32toh (clearText.nextTunnel),
|
CreateTunnelGatewayMsg (be32toh (clearText.nextTunnel),
|
||||||
eI2NPVariableTunnelBuildReply, buf, len,
|
eI2NPVariableTunnelBuildReply, buf, len,
|
||||||
be32toh (clearText.nextMessageID)));
|
be32toh (clearText.nextMessageID)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
i2p::transports.SendMessage (clearText.nextIdent,
|
transports.SendMessage (clearText.nextIdent,
|
||||||
CreateI2NPMessage (eI2NPVariableTunnelBuild, buf, len, be32toh (clearText.nextMessageID)));
|
CreateI2NPMessage (eI2NPVariableTunnelBuild, buf, len, be32toh (clearText.nextMessageID)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,13 +374,13 @@ namespace i2p
|
||||||
if (clearText.flag & 0x40) // we are endpoint of outbound tunnel
|
if (clearText.flag & 0x40) // we are endpoint of outbound tunnel
|
||||||
{
|
{
|
||||||
// so we send it to reply tunnel
|
// so we send it to reply tunnel
|
||||||
i2p::transports.SendMessage (clearText.nextIdent,
|
transports.SendMessage (clearText.nextIdent,
|
||||||
CreateTunnelGatewayMsg (be32toh (clearText.nextTunnel),
|
CreateTunnelGatewayMsg (be32toh (clearText.nextTunnel),
|
||||||
eI2NPTunnelBuildReply, buf, len,
|
eI2NPTunnelBuildReply, buf, len,
|
||||||
be32toh (clearText.nextMessageID)));
|
be32toh (clearText.nextMessageID)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
i2p::transports.SendMessage (clearText.nextIdent,
|
transports.SendMessage (clearText.nextIdent,
|
||||||
CreateI2NPMessage (eI2NPTunnelBuild, buf, len, be32toh (clearText.nextMessageID)));
|
CreateI2NPMessage (eI2NPTunnelBuild, buf, len, be32toh (clearText.nextMessageID)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,14 @@ using namespace i2p::crypto;
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace ntcp
|
namespace transport
|
||||||
{
|
{
|
||||||
NTCPSession::NTCPSession (boost::asio::io_service& service, i2p::data::RouterInfo& in_RemoteRouterInfo):
|
NTCPSession::NTCPSession (boost::asio::io_service& service, i2p::data::RouterInfo& in_RemoteRouterInfo):
|
||||||
m_Socket (service), m_TerminationTimer (service), m_IsEstablished (false),
|
m_Socket (service), m_TerminationTimer (service), m_IsEstablished (false),
|
||||||
m_RemoteRouterInfo (in_RemoteRouterInfo), m_ReceiveBufferOffset (0),
|
m_RemoteRouterInfo (in_RemoteRouterInfo), m_ReceiveBufferOffset (0),
|
||||||
m_NextMessage (nullptr), m_NumSentBytes (0), m_NumReceivedBytes (0)
|
m_NextMessage (nullptr), m_NumSentBytes (0), m_NumReceivedBytes (0)
|
||||||
{
|
{
|
||||||
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
|
m_DHKeysPair = transports.GetNextDHKeysPair ();
|
||||||
m_Establisher = new Establisher;
|
m_Establisher = new Establisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,12 +77,12 @@ namespace ntcp
|
||||||
{
|
{
|
||||||
m_IsEstablished = false;
|
m_IsEstablished = false;
|
||||||
m_Socket.close ();
|
m_Socket.close ();
|
||||||
i2p::transports.RemoveNTCPSession (this);
|
transports.RemoveNTCPSession (this);
|
||||||
int numDelayed = 0;
|
int numDelayed = 0;
|
||||||
for (auto it :m_DelayedMessages)
|
for (auto it :m_DelayedMessages)
|
||||||
{
|
{
|
||||||
// try to send them again
|
// try to send them again
|
||||||
i2p::transports.SendMessage (m_RemoteRouterInfo.GetIdentHash (), it);
|
transports.SendMessage (m_RemoteRouterInfo.GetIdentHash (), it);
|
||||||
numDelayed++;
|
numDelayed++;
|
||||||
}
|
}
|
||||||
m_DelayedMessages.clear ();
|
m_DelayedMessages.clear ();
|
||||||
|
@ -119,7 +119,7 @@ namespace ntcp
|
||||||
void NTCPSession::ClientLogin ()
|
void NTCPSession::ClientLogin ()
|
||||||
{
|
{
|
||||||
if (!m_DHKeysPair)
|
if (!m_DHKeysPair)
|
||||||
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
|
m_DHKeysPair = transports.GetNextDHKeysPair ();
|
||||||
// send Phase1
|
// send Phase1
|
||||||
const uint8_t * x = m_DHKeysPair->publicKey;
|
const uint8_t * x = m_DHKeysPair->publicKey;
|
||||||
memcpy (m_Establisher->phase1.pubKey, x, 256);
|
memcpy (m_Establisher->phase1.pubKey, x, 256);
|
||||||
|
@ -189,7 +189,7 @@ namespace ntcp
|
||||||
void NTCPSession::SendPhase2 ()
|
void NTCPSession::SendPhase2 ()
|
||||||
{
|
{
|
||||||
if (!m_DHKeysPair)
|
if (!m_DHKeysPair)
|
||||||
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
|
m_DHKeysPair = transports.GetNextDHKeysPair ();
|
||||||
const uint8_t * y = m_DHKeysPair->publicKey;
|
const uint8_t * y = m_DHKeysPair->publicKey;
|
||||||
memcpy (m_Establisher->phase2.pubKey, y, 256);
|
memcpy (m_Establisher->phase2.pubKey, y, 256);
|
||||||
uint8_t xy[512];
|
uint8_t xy[512];
|
||||||
|
@ -238,7 +238,7 @@ namespace ntcp
|
||||||
if (ecode != boost::asio::error::operation_aborted)
|
if (ecode != boost::asio::error::operation_aborted)
|
||||||
{
|
{
|
||||||
GetRemoteRouterInfo ().SetUnreachable (true); // this RouterInfo is not valid
|
GetRemoteRouterInfo ().SetUnreachable (true); // this RouterInfo is not valid
|
||||||
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
|
transports.ReuseDHKeysPair (m_DHKeysPair);
|
||||||
m_DHKeysPair = nullptr;
|
m_DHKeysPair = nullptr;
|
||||||
Terminate ();
|
Terminate ();
|
||||||
}
|
}
|
||||||
|
@ -263,7 +263,7 @@ namespace ntcp
|
||||||
if (memcmp (hxy, m_Establisher->phase2.encrypted.hxy, 32))
|
if (memcmp (hxy, m_Establisher->phase2.encrypted.hxy, 32))
|
||||||
{
|
{
|
||||||
LogPrint ("Incorrect hash");
|
LogPrint ("Incorrect hash");
|
||||||
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
|
transports.ReuseDHKeysPair (m_DHKeysPair);
|
||||||
m_DHKeysPair = nullptr;
|
m_DHKeysPair = nullptr;
|
||||||
Terminate ();
|
Terminate ();
|
||||||
return ;
|
return ;
|
||||||
|
@ -635,7 +635,7 @@ namespace ntcp
|
||||||
{
|
{
|
||||||
LogPrint ("NTCP server session connected");
|
LogPrint ("NTCP server session connected");
|
||||||
SetIsEstablished (true);
|
SetIsEstablished (true);
|
||||||
i2p::transports.AddNTCPSession (this);
|
transports.AddNTCPSession (this);
|
||||||
|
|
||||||
SendTimeSyncMessage ();
|
SendTimeSyncMessage ();
|
||||||
SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are
|
SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace ntcp
|
namespace transport
|
||||||
{
|
{
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
@ -67,7 +67,7 @@ namespace ntcp
|
||||||
const size_t NTCP_BUFFER_SIZE = 1040; // fits one tunnel message (1028)
|
const size_t NTCP_BUFFER_SIZE = 1040; // fits one tunnel message (1028)
|
||||||
const int NTCP_TERMINATION_TIMEOUT = 120; // 2 minutes
|
const int NTCP_TERMINATION_TIMEOUT = 120; // 2 minutes
|
||||||
|
|
||||||
class NTCPSession: public i2p::transport::TransportSession
|
class NTCPSession: public TransportSession
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
10
NetDb.cpp
10
NetDb.cpp
|
@ -15,6 +15,8 @@
|
||||||
#include "Reseed.h"
|
#include "Reseed.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
using namespace i2p::transport;
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace data
|
namespace data
|
||||||
|
@ -403,7 +405,7 @@ namespace data
|
||||||
RequestedDestination * dest = CreateRequestedDestination (destination, false, false, pool);
|
RequestedDestination * dest = CreateRequestedDestination (destination, false, false, pool);
|
||||||
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
|
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
|
||||||
if (floodfill)
|
if (floodfill)
|
||||||
i2p::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
|
transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -655,10 +657,10 @@ namespace data
|
||||||
if (outbound)
|
if (outbound)
|
||||||
outbound->SendTunnelDataMsg (buf+32, replyTunnelID, replyMsg);
|
outbound->SendTunnelDataMsg (buf+32, replyTunnelID, replyMsg);
|
||||||
else
|
else
|
||||||
i2p::transports.SendMessage (buf+32, i2p::CreateTunnelGatewayMsg (replyTunnelID, replyMsg));
|
transports.SendMessage (buf+32, i2p::CreateTunnelGatewayMsg (replyTunnelID, replyMsg));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
i2p::transports.SendMessage (buf+32, replyMsg);
|
transports.SendMessage (buf+32, replyMsg);
|
||||||
}
|
}
|
||||||
i2p::DeleteI2NPMessage (msg);
|
i2p::DeleteI2NPMessage (msg);
|
||||||
}
|
}
|
||||||
|
@ -712,7 +714,7 @@ namespace data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
i2p::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
|
i2p::transport::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
DeleteRequestedDestination (dest);
|
DeleteRequestedDestination (dest);
|
||||||
|
|
6
SSU.cpp
6
SSU.cpp
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace ssu
|
namespace transport
|
||||||
{
|
{
|
||||||
|
|
||||||
SSUSession::SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint,
|
SSUSession::SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint,
|
||||||
|
@ -173,7 +173,7 @@ namespace ssu
|
||||||
LogPrint ("Session request received");
|
LogPrint ("Session request received");
|
||||||
m_RemoteEndpoint = senderEndpoint;
|
m_RemoteEndpoint = senderEndpoint;
|
||||||
if (!m_DHKeysPair)
|
if (!m_DHKeysPair)
|
||||||
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
|
m_DHKeysPair = transports.GetNextDHKeysPair ();
|
||||||
CreateAESandMacKey (buf + sizeof (SSUHeader));
|
CreateAESandMacKey (buf + sizeof (SSUHeader));
|
||||||
SendSessionCreated (buf + sizeof (SSUHeader));
|
SendSessionCreated (buf + sizeof (SSUHeader));
|
||||||
}
|
}
|
||||||
|
@ -608,7 +608,7 @@ namespace ssu
|
||||||
{
|
{
|
||||||
// set connect timer
|
// set connect timer
|
||||||
ScheduleConnectTimer ();
|
ScheduleConnectTimer ();
|
||||||
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
|
m_DHKeysPair = transports.GetNextDHKeysPair ();
|
||||||
SendSessionRequest ();
|
SendSessionRequest ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
SSU.h
4
SSU.h
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace ssu
|
namespace transport
|
||||||
{
|
{
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
struct SSUHeader
|
struct SSUHeader
|
||||||
|
@ -58,7 +58,7 @@ namespace ssu
|
||||||
};
|
};
|
||||||
|
|
||||||
class SSUServer;
|
class SSUServer;
|
||||||
class SSUSession: public i2p::transport::TransportSession
|
class SSUSession: public TransportSession
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace ssu
|
namespace transport
|
||||||
{
|
{
|
||||||
SSUData::SSUData (SSUSession& session):
|
SSUData::SSUData (SSUSession& session):
|
||||||
m_Session (session), m_ResendTimer (session.m_Server.GetService ())
|
m_Session (session), m_ResendTimer (session.m_Server.GetService ())
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace ssu
|
namespace transport
|
||||||
{
|
{
|
||||||
|
|
||||||
const size_t SSU_MTU = 1484;
|
const size_t SSU_MTU = 1484;
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace tunnel
|
||||||
*(uint32_t *)(tunnelMsg->GetPayload ()) = htobe32 (m_NextTunnelID);
|
*(uint32_t *)(tunnelMsg->GetPayload ()) = htobe32 (m_NextTunnelID);
|
||||||
FillI2NPMessageHeader (tunnelMsg, eI2NPTunnelData);
|
FillI2NPMessageHeader (tunnelMsg, eI2NPTunnelData);
|
||||||
|
|
||||||
i2p::transports.SendMessage (m_NextIdent, tunnelMsg);
|
i2p::transport::transports.SendMessage (m_NextIdent, tunnelMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransitTunnel::SendTunnelDataMsg (i2p::I2NPMessage * msg)
|
void TransitTunnel::SendTunnelDataMsg (i2p::I2NPMessage * msg)
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
using namespace i2p::data;
|
using namespace i2p::data;
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
|
{
|
||||||
|
namespace transport
|
||||||
{
|
{
|
||||||
DHKeysPairSupplier::DHKeysPairSupplier (int size):
|
DHKeysPairSupplier::DHKeysPairSupplier (int size):
|
||||||
m_QueueSize (size), m_IsRunning (false), m_Thread (nullptr)
|
m_QueueSize (size), m_IsRunning (false), m_Thread (nullptr)
|
||||||
|
@ -66,7 +68,7 @@ namespace i2p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i2p::transport::DHKeysPair * DHKeysPairSupplier::Acquire ()
|
DHKeysPair * DHKeysPairSupplier::Acquire ()
|
||||||
{
|
{
|
||||||
if (!m_Queue.empty ())
|
if (!m_Queue.empty ())
|
||||||
{
|
{
|
||||||
|
@ -78,14 +80,14 @@ namespace i2p
|
||||||
}
|
}
|
||||||
else // queue is empty, create new
|
else // queue is empty, create new
|
||||||
{
|
{
|
||||||
i2p::transport::DHKeysPair * pair = new i2p::transport::DHKeysPair ();
|
DHKeysPair * pair = new DHKeysPair ();
|
||||||
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
CryptoPP::DH dh (i2p::crypto::elgp, i2p::crypto::elgg);
|
||||||
dh.GenerateKeyPair(m_Rnd, pair->privateKey, pair->publicKey);
|
dh.GenerateKeyPair(m_Rnd, pair->privateKey, pair->publicKey);
|
||||||
return pair;
|
return pair;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHKeysPairSupplier::Return (i2p::transport::DHKeysPair * pair)
|
void DHKeysPairSupplier::Return (DHKeysPair * pair)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> l(m_AcquiredMutex);
|
std::unique_lock<std::mutex> l(m_AcquiredMutex);
|
||||||
m_Queue.push (pair);
|
m_Queue.push (pair);
|
||||||
|
@ -119,7 +121,7 @@ namespace i2p
|
||||||
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address.port));
|
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), address.port));
|
||||||
|
|
||||||
LogPrint ("Start listening TCP port ", address.port);
|
LogPrint ("Start listening TCP port ", address.port);
|
||||||
auto conn = new i2p::ntcp::NTCPServerConnection (m_Service);
|
auto conn = new NTCPServerConnection (m_Service);
|
||||||
m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this,
|
m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this,
|
||||||
conn, boost::asio::placeholders::error));
|
conn, boost::asio::placeholders::error));
|
||||||
}
|
}
|
||||||
|
@ -127,7 +129,7 @@ namespace i2p
|
||||||
{
|
{
|
||||||
if (!m_SSUServer)
|
if (!m_SSUServer)
|
||||||
{
|
{
|
||||||
m_SSUServer = new i2p::ssu::SSUServer (address.port);
|
m_SSUServer = new SSUServer (address.port);
|
||||||
LogPrint ("Start listening UDP port ", address.port);
|
LogPrint ("Start listening UDP port ", address.port);
|
||||||
m_SSUServer->Start ();
|
m_SSUServer->Start ();
|
||||||
DetectExternalIP ();
|
DetectExternalIP ();
|
||||||
|
@ -179,19 +181,19 @@ namespace i2p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transports::AddNTCPSession (i2p::ntcp::NTCPSession * session)
|
void Transports::AddNTCPSession (NTCPSession * session)
|
||||||
{
|
{
|
||||||
if (session)
|
if (session)
|
||||||
m_NTCPSessions[session->GetRemoteRouterInfo ().GetIdentHash ()] = session;
|
m_NTCPSessions[session->GetRemoteRouterInfo ().GetIdentHash ()] = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transports::RemoveNTCPSession (i2p::ntcp::NTCPSession * session)
|
void Transports::RemoveNTCPSession (NTCPSession * session)
|
||||||
{
|
{
|
||||||
if (session)
|
if (session)
|
||||||
m_NTCPSessions.erase (session->GetRemoteRouterInfo ().GetIdentHash ());
|
m_NTCPSessions.erase (session->GetRemoteRouterInfo ().GetIdentHash ());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transports::HandleAccept (i2p::ntcp::NTCPServerConnection * conn, const boost::system::error_code& error)
|
void Transports::HandleAccept (NTCPServerConnection * conn, const boost::system::error_code& error)
|
||||||
{
|
{
|
||||||
if (!error)
|
if (!error)
|
||||||
{
|
{
|
||||||
|
@ -203,13 +205,13 @@ namespace i2p
|
||||||
|
|
||||||
if (error != boost::asio::error::operation_aborted)
|
if (error != boost::asio::error::operation_aborted)
|
||||||
{
|
{
|
||||||
conn = new i2p::ntcp::NTCPServerConnection (m_Service);
|
conn = new NTCPServerConnection (m_Service);
|
||||||
m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this,
|
m_NTCPAcceptor->async_accept(conn->GetSocket (), boost::bind (&Transports::HandleAccept, this,
|
||||||
conn, boost::asio::placeholders::error));
|
conn, boost::asio::placeholders::error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i2p::ntcp::NTCPSession * Transports::GetNextNTCPSession ()
|
NTCPSession * Transports::GetNextNTCPSession ()
|
||||||
{
|
{
|
||||||
for (auto session: m_NTCPSessions)
|
for (auto session: m_NTCPSessions)
|
||||||
if (session.second->IsEstablished ())
|
if (session.second->IsEstablished ())
|
||||||
|
@ -217,7 +219,7 @@ namespace i2p
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2p::ntcp::NTCPSession * Transports::FindNTCPSession (const i2p::data::IdentHash& ident)
|
NTCPSession * Transports::FindNTCPSession (const i2p::data::IdentHash& ident)
|
||||||
{
|
{
|
||||||
auto it = m_NTCPSessions.find (ident);
|
auto it = m_NTCPSessions.find (ident);
|
||||||
if (it != m_NTCPSessions.end ())
|
if (it != m_NTCPSessions.end ())
|
||||||
|
@ -252,9 +254,9 @@ namespace i2p
|
||||||
// existing session not found. create new
|
// existing session not found. create new
|
||||||
// try NTCP first if message size < 16K
|
// try NTCP first if message size < 16K
|
||||||
auto address = r->GetNTCPAddress ();
|
auto address = r->GetNTCPAddress ();
|
||||||
if (address && !r->UsesIntroducer () && !r->IsUnreachable () && msg->GetLength () < i2p::ntcp::NTCP_MAX_MESSAGE_SIZE)
|
if (address && !r->UsesIntroducer () && !r->IsUnreachable () && msg->GetLength () < NTCP_MAX_MESSAGE_SIZE)
|
||||||
{
|
{
|
||||||
auto s = new i2p::ntcp::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);
|
||||||
}
|
}
|
||||||
|
@ -328,13 +330,15 @@ namespace i2p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i2p::transport::DHKeysPair * Transports::GetNextDHKeysPair ()
|
DHKeysPair * Transports::GetNextDHKeysPair ()
|
||||||
{
|
{
|
||||||
return m_DHKeysPairSupplier.Acquire ();
|
return m_DHKeysPairSupplier.Acquire ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transports::ReuseDHKeysPair (i2p::transport::DHKeysPair * pair)
|
void Transports::ReuseDHKeysPair (DHKeysPair * pair)
|
||||||
{
|
{
|
||||||
m_DHKeysPairSupplier.Return (pair);
|
m_DHKeysPairSupplier.Return (pair);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
27
Transports.h
27
Transports.h
|
@ -18,6 +18,8 @@
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
|
{
|
||||||
|
namespace transport
|
||||||
{
|
{
|
||||||
class DHKeysPairSupplier
|
class DHKeysPairSupplier
|
||||||
{
|
{
|
||||||
|
@ -27,8 +29,8 @@ namespace i2p
|
||||||
~DHKeysPairSupplier ();
|
~DHKeysPairSupplier ();
|
||||||
void Start ();
|
void Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
i2p::transport::DHKeysPair * Acquire ();
|
DHKeysPair * Acquire ();
|
||||||
void Return (i2p::transport::DHKeysPair * pair);
|
void Return (DHKeysPair * pair);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -38,7 +40,7 @@ namespace i2p
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const int m_QueueSize;
|
const int m_QueueSize;
|
||||||
std::queue<i2p::transport::DHKeysPair *> m_Queue;
|
std::queue<DHKeysPair *> m_Queue;
|
||||||
|
|
||||||
bool m_IsRunning;
|
bool m_IsRunning;
|
||||||
std::thread * m_Thread;
|
std::thread * m_Thread;
|
||||||
|
@ -59,13 +61,13 @@ namespace i2p
|
||||||
|
|
||||||
boost::asio::io_service& GetService () { return m_Service; };
|
boost::asio::io_service& GetService () { return m_Service; };
|
||||||
i2p::transport::DHKeysPair * GetNextDHKeysPair ();
|
i2p::transport::DHKeysPair * GetNextDHKeysPair ();
|
||||||
void ReuseDHKeysPair (i2p::transport::DHKeysPair * pair);
|
void ReuseDHKeysPair (DHKeysPair * pair);
|
||||||
|
|
||||||
void AddNTCPSession (i2p::ntcp::NTCPSession * session);
|
void AddNTCPSession (NTCPSession * session);
|
||||||
void RemoveNTCPSession (i2p::ntcp::NTCPSession * session);
|
void RemoveNTCPSession (NTCPSession * session);
|
||||||
|
|
||||||
i2p::ntcp::NTCPSession * GetNextNTCPSession ();
|
NTCPSession * GetNextNTCPSession ();
|
||||||
i2p::ntcp::NTCPSession * FindNTCPSession (const i2p::data::IdentHash& ident);
|
NTCPSession * FindNTCPSession (const i2p::data::IdentHash& ident);
|
||||||
|
|
||||||
void SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
|
void SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
|
||||||
void CloseSession (const i2p::data::RouterInfo * router);
|
void CloseSession (const i2p::data::RouterInfo * router);
|
||||||
|
@ -73,7 +75,7 @@ namespace i2p
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Run ();
|
void Run ();
|
||||||
void HandleAccept (i2p::ntcp::NTCPServerConnection * conn, const boost::system::error_code& error);
|
void HandleAccept (NTCPServerConnection * conn, const boost::system::error_code& error);
|
||||||
void HandleResendTimer (const boost::system::error_code& ecode, boost::asio::deadline_timer * timer,
|
void HandleResendTimer (const boost::system::error_code& ecode, boost::asio::deadline_timer * timer,
|
||||||
const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
|
const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
|
||||||
void PostMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
|
void PostMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
|
||||||
|
@ -89,8 +91,8 @@ namespace i2p
|
||||||
boost::asio::io_service::work m_Work;
|
boost::asio::io_service::work m_Work;
|
||||||
boost::asio::ip::tcp::acceptor * m_NTCPAcceptor;
|
boost::asio::ip::tcp::acceptor * m_NTCPAcceptor;
|
||||||
|
|
||||||
std::map<i2p::data::IdentHash, i2p::ntcp::NTCPSession *> m_NTCPSessions;
|
std::map<i2p::data::IdentHash, NTCPSession *> m_NTCPSessions;
|
||||||
i2p::ssu::SSUServer * m_SSUServer;
|
SSUServer * m_SSUServer;
|
||||||
|
|
||||||
DHKeysPairSupplier m_DHKeysPairSupplier;
|
DHKeysPairSupplier m_DHKeysPairSupplier;
|
||||||
|
|
||||||
|
@ -98,10 +100,11 @@ namespace i2p
|
||||||
|
|
||||||
// for HTTP only
|
// for HTTP only
|
||||||
const decltype(m_NTCPSessions)& GetNTCPSessions () const { return m_NTCPSessions; };
|
const decltype(m_NTCPSessions)& GetNTCPSessions () const { return m_NTCPSessions; };
|
||||||
const i2p::ssu::SSUServer * GetSSUServer () const { return m_SSUServer; };
|
const SSUServer * GetSSUServer () const { return m_SSUServer; };
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Transports transports;
|
extern Transports transports;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -92,7 +92,7 @@ namespace tunnel
|
||||||
if (outboundTunnel)
|
if (outboundTunnel)
|
||||||
outboundTunnel->SendTunnelDataMsg (GetNextIdentHash (), 0, msg);
|
outboundTunnel->SendTunnelDataMsg (GetNextIdentHash (), 0, msg);
|
||||||
else
|
else
|
||||||
i2p::transports.SendMessage (GetNextIdentHash (), msg);
|
i2p::transport::transports.SendMessage (GetNextIdentHash (), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t len)
|
bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t len)
|
||||||
|
|
|
@ -235,7 +235,7 @@ namespace tunnel
|
||||||
i2p::HandleI2NPMessage (msg.data);
|
i2p::HandleI2NPMessage (msg.data);
|
||||||
break;
|
break;
|
||||||
case eDeliveryTypeTunnel:
|
case eDeliveryTypeTunnel:
|
||||||
i2p::transports.SendMessage (msg.hash, i2p::CreateTunnelGatewayMsg (msg.tunnelID, msg.data));
|
i2p::transport::transports.SendMessage (msg.hash, i2p::CreateTunnelGatewayMsg (msg.tunnelID, msg.data));
|
||||||
break;
|
break;
|
||||||
case eDeliveryTypeRouter:
|
case eDeliveryTypeRouter:
|
||||||
if (msg.hash == i2p::context.GetRouterInfo ().GetIdentHash ()) // check if message is sent to us
|
if (msg.hash == i2p::context.GetRouterInfo ().GetIdentHash ()) // check if message is sent to us
|
||||||
|
@ -253,7 +253,7 @@ namespace tunnel
|
||||||
*ds = *(msg.data);
|
*ds = *(msg.data);
|
||||||
i2p::data::netdb.PostI2NPMsg (ds);
|
i2p::data::netdb.PostI2NPMsg (ds);
|
||||||
}
|
}
|
||||||
i2p::transports.SendMessage (msg.hash, msg.data);
|
i2p::transport::transports.SendMessage (msg.hash, msg.data);
|
||||||
}
|
}
|
||||||
else // we shouldn't send this message. possible leakage
|
else // we shouldn't send this message. possible leakage
|
||||||
{
|
{
|
||||||
|
|
|
@ -186,7 +186,7 @@ namespace tunnel
|
||||||
{
|
{
|
||||||
m_Tunnel->EncryptTunnelMsg (tunnelMsg);
|
m_Tunnel->EncryptTunnelMsg (tunnelMsg);
|
||||||
FillI2NPMessageHeader (tunnelMsg, eI2NPTunnelData);
|
FillI2NPMessageHeader (tunnelMsg, eI2NPTunnelData);
|
||||||
i2p::transports.SendMessage (m_Tunnel->GetNextIdentHash (), tunnelMsg);
|
i2p::transport::transports.SendMessage (m_Tunnel->GetNextIdentHash (), tunnelMsg);
|
||||||
m_NumSentBytes += TUNNEL_DATA_MSG_SIZE;
|
m_NumSentBytes += TUNNEL_DATA_MSG_SIZE;
|
||||||
}
|
}
|
||||||
m_Buffer.ClearTunnelDataMsgs ();
|
m_Buffer.ClearTunnelDataMsgs ();
|
||||||
|
|
Loading…
Reference in a new issue