Browse Source

moved transports to 'transport' namespace

pull/105/head
orignal 10 years ago
parent
commit
7b768ccb26
  1. 4
      Daemon.cpp
  2. 4
      HTTPServer.cpp
  3. 11
      I2NPProtocol.cpp
  4. 18
      NTCPSession.cpp
  5. 4
      NTCPSession.h
  6. 10
      NetDb.cpp
  7. 6
      SSU.cpp
  8. 4
      SSU.h
  9. 2
      SSUData.cpp
  10. 2
      SSUData.h
  11. 2
      TransitTunnel.cpp
  12. 34
      Transports.cpp
  13. 27
      Transports.h
  14. 2
      Tunnel.cpp
  15. 4
      TunnelEndpoint.cpp
  16. 2
      TunnelGateway.cpp

4
Daemon.cpp

@ -103,7 +103,7 @@ namespace i2p @@ -103,7 +103,7 @@ namespace i2p
LogPrint("HTTP Server started");
i2p::data::netdb.Start();
LogPrint("NetDB started");
i2p::transports.Start();
i2p::transport::transports.Start();
LogPrint("Transports started");
i2p::tunnel::tunnels.Start();
LogPrint("Tunnels started");
@ -120,7 +120,7 @@ namespace i2p @@ -120,7 +120,7 @@ namespace i2p
LogPrint("Client stoped");
i2p::tunnel::tunnels.Stop();
LogPrint("Tunnels stoped");
i2p::transports.Stop();
i2p::transport::transports.Stop();
LogPrint("Transports stoped");
i2p::data::netdb.Stop();
LogPrint("NetDB stoped");

4
HTTPServer.cpp

@ -699,7 +699,7 @@ namespace util @@ -699,7 +699,7 @@ namespace util
void HTTPConnection::ShowTransports (std::stringstream& s)
{
s << "NTCP<br>";
for (auto it: i2p::transports.GetNTCPSessions ())
for (auto it: i2p::transport::transports.GetNTCPSessions ())
{
// RouterInfo of incoming connection doesn't have address
bool outgoing = it.second->GetRemoteRouterInfo ().GetNTCPAddress ();
@ -714,7 +714,7 @@ namespace util @@ -714,7 +714,7 @@ namespace util
}
s << std::endl;
}
auto ssuServer = i2p::transports.GetSSUServer ();
auto ssuServer = i2p::transport::transports.GetSSUServer ();
if (ssuServer)
{
s << "<br>SSU<br>";

11
I2NPProtocol.cpp

@ -13,9 +13,10 @@ @@ -13,9 +13,10 @@
#include "Garlic.h"
#include "I2NPProtocol.h"
using namespace i2p::transport;
namespace i2p
{
I2NPMessage * NewI2NPMessage ()
{
return new I2NPMessageBuffer<I2NP_MAX_MESSAGE_SIZE>();
@ -353,13 +354,13 @@ namespace i2p @@ -353,13 +354,13 @@ namespace i2p
if (clearText.flag & 0x40) // we are endpoint of outboud tunnel
{
// so we send it to reply tunnel
i2p::transports.SendMessage (clearText.nextIdent,
transports.SendMessage (clearText.nextIdent,
CreateTunnelGatewayMsg (be32toh (clearText.nextTunnel),
eI2NPVariableTunnelBuildReply, buf, len,
be32toh (clearText.nextMessageID)));
}
else
i2p::transports.SendMessage (clearText.nextIdent,
transports.SendMessage (clearText.nextIdent,
CreateI2NPMessage (eI2NPVariableTunnelBuild, buf, len, be32toh (clearText.nextMessageID)));
}
}
@ -373,13 +374,13 @@ namespace i2p @@ -373,13 +374,13 @@ namespace i2p
if (clearText.flag & 0x40) // we are endpoint of outbound tunnel
{
// so we send it to reply tunnel
i2p::transports.SendMessage (clearText.nextIdent,
transports.SendMessage (clearText.nextIdent,
CreateTunnelGatewayMsg (be32toh (clearText.nextTunnel),
eI2NPTunnelBuildReply, buf, len,
be32toh (clearText.nextMessageID)));
}
else
i2p::transports.SendMessage (clearText.nextIdent,
transports.SendMessage (clearText.nextIdent,
CreateI2NPMessage (eI2NPTunnelBuild, buf, len, be32toh (clearText.nextMessageID)));
}
}

18
NTCPSession.cpp

@ -17,14 +17,14 @@ using namespace i2p::crypto; @@ -17,14 +17,14 @@ using namespace i2p::crypto;
namespace i2p
{
namespace ntcp
namespace transport
{
NTCPSession::NTCPSession (boost::asio::io_service& service, i2p::data::RouterInfo& in_RemoteRouterInfo):
m_Socket (service), m_TerminationTimer (service), m_IsEstablished (false),
m_RemoteRouterInfo (in_RemoteRouterInfo), m_ReceiveBufferOffset (0),
m_NextMessage (nullptr), m_NumSentBytes (0), m_NumReceivedBytes (0)
{
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
m_DHKeysPair = transports.GetNextDHKeysPair ();
m_Establisher = new Establisher;
}
@ -77,12 +77,12 @@ namespace ntcp @@ -77,12 +77,12 @@ namespace ntcp
{
m_IsEstablished = false;
m_Socket.close ();
i2p::transports.RemoveNTCPSession (this);
transports.RemoveNTCPSession (this);
int numDelayed = 0;
for (auto it :m_DelayedMessages)
{
// try to send them again
i2p::transports.SendMessage (m_RemoteRouterInfo.GetIdentHash (), it);
transports.SendMessage (m_RemoteRouterInfo.GetIdentHash (), it);
numDelayed++;
}
m_DelayedMessages.clear ();
@ -119,7 +119,7 @@ namespace ntcp @@ -119,7 +119,7 @@ namespace ntcp
void NTCPSession::ClientLogin ()
{
if (!m_DHKeysPair)
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
m_DHKeysPair = transports.GetNextDHKeysPair ();
// send Phase1
const uint8_t * x = m_DHKeysPair->publicKey;
memcpy (m_Establisher->phase1.pubKey, x, 256);
@ -189,7 +189,7 @@ namespace ntcp @@ -189,7 +189,7 @@ namespace ntcp
void NTCPSession::SendPhase2 ()
{
if (!m_DHKeysPair)
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
m_DHKeysPair = transports.GetNextDHKeysPair ();
const uint8_t * y = m_DHKeysPair->publicKey;
memcpy (m_Establisher->phase2.pubKey, y, 256);
uint8_t xy[512];
@ -238,7 +238,7 @@ namespace ntcp @@ -238,7 +238,7 @@ namespace ntcp
if (ecode != boost::asio::error::operation_aborted)
{
GetRemoteRouterInfo ().SetUnreachable (true); // this RouterInfo is not valid
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
transports.ReuseDHKeysPair (m_DHKeysPair);
m_DHKeysPair = nullptr;
Terminate ();
}
@ -263,7 +263,7 @@ namespace ntcp @@ -263,7 +263,7 @@ namespace ntcp
if (memcmp (hxy, m_Establisher->phase2.encrypted.hxy, 32))
{
LogPrint ("Incorrect hash");
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
transports.ReuseDHKeysPair (m_DHKeysPair);
m_DHKeysPair = nullptr;
Terminate ();
return ;
@ -635,7 +635,7 @@ namespace ntcp @@ -635,7 +635,7 @@ namespace ntcp
{
LogPrint ("NTCP server session connected");
SetIsEstablished (true);
i2p::transports.AddNTCPSession (this);
transports.AddNTCPSession (this);
SendTimeSyncMessage ();
SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are

4
NTCPSession.h

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
namespace i2p
{
namespace ntcp
namespace transport
{
#pragma pack(1)
@ -67,7 +67,7 @@ namespace ntcp @@ -67,7 +67,7 @@ namespace ntcp
const size_t NTCP_BUFFER_SIZE = 1040; // fits one tunnel message (1028)
const int NTCP_TERMINATION_TIMEOUT = 120; // 2 minutes
class NTCPSession: public i2p::transport::TransportSession
class NTCPSession: public TransportSession
{
public:

10
NetDb.cpp

@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
#include "Reseed.h"
#include "util.h"
using namespace i2p::transport;
namespace i2p
{
namespace data
@ -403,7 +405,7 @@ namespace data @@ -403,7 +405,7 @@ namespace data
RequestedDestination * dest = CreateRequestedDestination (destination, false, false, pool);
auto floodfill = GetClosestFloodfill (destination, dest->GetExcludedPeers ());
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 @@ -655,10 +657,10 @@ namespace data
if (outbound)
outbound->SendTunnelDataMsg (buf+32, replyTunnelID, replyMsg);
else
i2p::transports.SendMessage (buf+32, i2p::CreateTunnelGatewayMsg (replyTunnelID, replyMsg));
transports.SendMessage (buf+32, i2p::CreateTunnelGatewayMsg (replyTunnelID, replyMsg));
}
else
i2p::transports.SendMessage (buf+32, replyMsg);
transports.SendMessage (buf+32, replyMsg);
}
i2p::DeleteI2NPMessage (msg);
}
@ -712,7 +714,7 @@ namespace data @@ -712,7 +714,7 @@ namespace data
});
}
else
i2p::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
i2p::transport::transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
}
else
DeleteRequestedDestination (dest);

6
SSU.cpp

@ -12,7 +12,7 @@ @@ -12,7 +12,7 @@
namespace i2p
{
namespace ssu
namespace transport
{
SSUSession::SSUSession (SSUServer& server, boost::asio::ip::udp::endpoint& remoteEndpoint,
@ -173,7 +173,7 @@ namespace ssu @@ -173,7 +173,7 @@ namespace ssu
LogPrint ("Session request received");
m_RemoteEndpoint = senderEndpoint;
if (!m_DHKeysPair)
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
m_DHKeysPair = transports.GetNextDHKeysPair ();
CreateAESandMacKey (buf + sizeof (SSUHeader));
SendSessionCreated (buf + sizeof (SSUHeader));
}
@ -608,7 +608,7 @@ namespace ssu @@ -608,7 +608,7 @@ namespace ssu
{
// set connect timer
ScheduleConnectTimer ();
m_DHKeysPair = i2p::transports.GetNextDHKeysPair ();
m_DHKeysPair = transports.GetNextDHKeysPair ();
SendSessionRequest ();
}
}

4
SSU.h

@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
namespace i2p
{
namespace ssu
namespace transport
{
#pragma pack(1)
struct SSUHeader
@ -58,7 +58,7 @@ namespace ssu @@ -58,7 +58,7 @@ namespace ssu
};
class SSUServer;
class SSUSession: public i2p::transport::TransportSession
class SSUSession: public TransportSession
{
public:

2
SSUData.cpp

@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
namespace i2p
{
namespace ssu
namespace transport
{
SSUData::SSUData (SSUSession& session):
m_Session (session), m_ResendTimer (session.m_Server.GetService ())

2
SSUData.h

@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
namespace i2p
{
namespace ssu
namespace transport
{
const size_t SSU_MTU = 1484;

2
TransitTunnel.cpp

@ -34,7 +34,7 @@ namespace tunnel @@ -34,7 +34,7 @@ namespace tunnel
*(uint32_t *)(tunnelMsg->GetPayload ()) = htobe32 (m_NextTunnelID);
FillI2NPMessageHeader (tunnelMsg, eI2NPTunnelData);
i2p::transports.SendMessage (m_NextIdent, tunnelMsg);
i2p::transport::transports.SendMessage (m_NextIdent, tunnelMsg);
}
void TransitTunnel::SendTunnelDataMsg (i2p::I2NPMessage * msg)

34
Transports.cpp

@ -10,6 +10,8 @@ @@ -10,6 +10,8 @@
using namespace i2p::data;
namespace i2p
{
namespace transport
{
DHKeysPairSupplier::DHKeysPairSupplier (int size):
m_QueueSize (size), m_IsRunning (false), m_Thread (nullptr)
@ -66,7 +68,7 @@ namespace i2p @@ -66,7 +68,7 @@ namespace i2p
}
}
i2p::transport::DHKeysPair * DHKeysPairSupplier::Acquire ()
DHKeysPair * DHKeysPairSupplier::Acquire ()
{
if (!m_Queue.empty ())
{
@ -78,14 +80,14 @@ namespace i2p @@ -78,14 +80,14 @@ namespace i2p
}
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);
dh.GenerateKeyPair(m_Rnd, pair->privateKey, pair->publicKey);
return pair;
}
}
void DHKeysPairSupplier::Return (i2p::transport::DHKeysPair * pair)
void DHKeysPairSupplier::Return (DHKeysPair * pair)
{
std::unique_lock<std::mutex> l(m_AcquiredMutex);
m_Queue.push (pair);
@ -119,7 +121,7 @@ namespace i2p @@ -119,7 +121,7 @@ namespace i2p
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 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,
conn, boost::asio::placeholders::error));
}
@ -127,7 +129,7 @@ namespace i2p @@ -127,7 +129,7 @@ namespace i2p
{
if (!m_SSUServer)
{
m_SSUServer = new i2p::ssu::SSUServer (address.port);
m_SSUServer = new SSUServer (address.port);
LogPrint ("Start listening UDP port ", address.port);
m_SSUServer->Start ();
DetectExternalIP ();
@ -179,19 +181,19 @@ namespace i2p @@ -179,19 +181,19 @@ namespace i2p
}
}
void Transports::AddNTCPSession (i2p::ntcp::NTCPSession * session)
void Transports::AddNTCPSession (NTCPSession * session)
{
if (session)
m_NTCPSessions[session->GetRemoteRouterInfo ().GetIdentHash ()] = session;
}
void Transports::RemoveNTCPSession (i2p::ntcp::NTCPSession * session)
void Transports::RemoveNTCPSession (NTCPSession * session)
{
if (session)
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)
{
@ -203,13 +205,13 @@ namespace i2p @@ -203,13 +205,13 @@ namespace i2p
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,
conn, boost::asio::placeholders::error));
}
}
i2p::ntcp::NTCPSession * Transports::GetNextNTCPSession ()
NTCPSession * Transports::GetNextNTCPSession ()
{
for (auto session: m_NTCPSessions)
if (session.second->IsEstablished ())
@ -217,7 +219,7 @@ namespace i2p @@ -217,7 +219,7 @@ namespace i2p
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);
if (it != m_NTCPSessions.end ())
@ -252,9 +254,9 @@ namespace i2p @@ -252,9 +254,9 @@ namespace i2p
// existing session not found. create new
// try NTCP first if message size < 16K
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);
s->SendI2NPMessage (msg);
}
@ -328,13 +330,15 @@ namespace i2p @@ -328,13 +330,15 @@ namespace i2p
}
}
i2p::transport::DHKeysPair * Transports::GetNextDHKeysPair ()
DHKeysPair * Transports::GetNextDHKeysPair ()
{
return m_DHKeysPairSupplier.Acquire ();
}
void Transports::ReuseDHKeysPair (i2p::transport::DHKeysPair * pair)
void Transports::ReuseDHKeysPair (DHKeysPair * pair)
{
m_DHKeysPairSupplier.Return (pair);
}
}
}

27
Transports.h

@ -18,6 +18,8 @@ @@ -18,6 +18,8 @@
#include "Identity.h"
namespace i2p
{
namespace transport
{
class DHKeysPairSupplier
{
@ -27,8 +29,8 @@ namespace i2p @@ -27,8 +29,8 @@ namespace i2p
~DHKeysPairSupplier ();
void Start ();
void Stop ();
i2p::transport::DHKeysPair * Acquire ();
void Return (i2p::transport::DHKeysPair * pair);
DHKeysPair * Acquire ();
void Return (DHKeysPair * pair);
private:
@ -38,7 +40,7 @@ namespace i2p @@ -38,7 +40,7 @@ namespace i2p
private:
const int m_QueueSize;
std::queue<i2p::transport::DHKeysPair *> m_Queue;
std::queue<DHKeysPair *> m_Queue;
bool m_IsRunning;
std::thread * m_Thread;
@ -59,13 +61,13 @@ namespace i2p @@ -59,13 +61,13 @@ namespace i2p
boost::asio::io_service& GetService () { return m_Service; };
i2p::transport::DHKeysPair * GetNextDHKeysPair ();
void ReuseDHKeysPair (i2p::transport::DHKeysPair * pair);
void ReuseDHKeysPair (DHKeysPair * pair);
void AddNTCPSession (i2p::ntcp::NTCPSession * session);
void RemoveNTCPSession (i2p::ntcp::NTCPSession * session);
void AddNTCPSession (NTCPSession * session);
void RemoveNTCPSession (NTCPSession * session);
i2p::ntcp::NTCPSession * GetNextNTCPSession ();
i2p::ntcp::NTCPSession * FindNTCPSession (const i2p::data::IdentHash& ident);
NTCPSession * GetNextNTCPSession ();
NTCPSession * FindNTCPSession (const i2p::data::IdentHash& ident);
void SendMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
void CloseSession (const i2p::data::RouterInfo * router);
@ -73,7 +75,7 @@ namespace i2p @@ -73,7 +75,7 @@ namespace i2p
private:
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,
const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
void PostMessage (const i2p::data::IdentHash& ident, i2p::I2NPMessage * msg);
@ -89,8 +91,8 @@ namespace i2p @@ -89,8 +91,8 @@ namespace i2p
boost::asio::io_service::work m_Work;
boost::asio::ip::tcp::acceptor * m_NTCPAcceptor;
std::map<i2p::data::IdentHash, i2p::ntcp::NTCPSession *> m_NTCPSessions;
i2p::ssu::SSUServer * m_SSUServer;
std::map<i2p::data::IdentHash, NTCPSession *> m_NTCPSessions;
SSUServer * m_SSUServer;
DHKeysPairSupplier m_DHKeysPairSupplier;
@ -98,10 +100,11 @@ namespace i2p @@ -98,10 +100,11 @@ namespace i2p
// for HTTP only
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;
}
}
#endif

2
Tunnel.cpp

@ -92,7 +92,7 @@ namespace tunnel @@ -92,7 +92,7 @@ namespace tunnel
if (outboundTunnel)
outboundTunnel->SendTunnelDataMsg (GetNextIdentHash (), 0, msg);
else
i2p::transports.SendMessage (GetNextIdentHash (), msg);
i2p::transport::transports.SendMessage (GetNextIdentHash (), msg);
}
bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t len)

4
TunnelEndpoint.cpp

@ -235,7 +235,7 @@ namespace tunnel @@ -235,7 +235,7 @@ namespace tunnel
i2p::HandleI2NPMessage (msg.data);
break;
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;
case eDeliveryTypeRouter:
if (msg.hash == i2p::context.GetRouterInfo ().GetIdentHash ()) // check if message is sent to us
@ -253,7 +253,7 @@ namespace tunnel @@ -253,7 +253,7 @@ namespace tunnel
*ds = *(msg.data);
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
{

2
TunnelGateway.cpp

@ -186,7 +186,7 @@ namespace tunnel @@ -186,7 +186,7 @@ namespace tunnel
{
m_Tunnel->EncryptTunnelMsg (tunnelMsg);
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_Buffer.ClearTunnelDataMsgs ();

Loading…
Cancel
Save